A
A
Alexey2018-01-28 20:32:43
MySQL
Alexey, 2018-01-28 20:32:43

How to fix MySQL Error 1064 SQL State 4200 which only appears on Linux?

On a bunch of Node.js + Express + MySQL, when deploying to the server, an error occurs in one of the routes.
If we turn to this route, we get an error

"code":"ER_PARSE_ERROR",
"errno":1064,
"sqlMessage":"You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CREATE OR REPLACE VIEW tmp AS SELECT                    TEACH.name,             ' at line 1",
"sqlState":"42000",
"index":0

but if you take the request code from the error message and paste it into the Workbench, then it will work fine.
Actually the request text itself, in which dates and city IDs dynamically arrive. Formatting a la
Workbench.
CREATE OR REPLACE VIEW tmp AS
    SELECT 
        TEACH.name,
        CAT.description,
        WRK.idTEACHER,
        LEC.idLECTURE,
        LEC.out,
        COUNT(TGFL.idTRAININGFL) AS people,
        WRK.hours
    FROM
        LECTURE LEC
            INNER JOIN
        TRAININGFL TGFL ON TGFL.idLECTURE = LEC.idLECTURE
            AND TGFL.idCITY = 1
            AND TGFL.date_attestation BETWEEN '2018-01-01' AND '2018-01-28'
            INNER JOIN
        WORKLOAD WRK ON WRK.idLECTURE = TGFL.idLECTURE
            INNER JOIN
        TEACHER TEACH ON TEACH.idTEACHER = WRK.idTEACHER
            INNER JOIN
        CAT_TEACHER CAT ON CAT.idCAT_TEACHER = TEACH.idCAT
    GROUP BY LEC.idLECTURE , WRK.idTEACHER;CREATE OR REPLACE VIEW allpeople AS
    SELECT 
        COUNT(TGFL.idTRAININGFL) AS allpeople
    FROM
        TRAININGFL TGFL
    WHERE
        idCITY = 1
            AND TGFL.date_attestation BETWEEN '2018-01-01' AND '2018-01-28';SELECT 
    name,
    IFNULL(allin, 0) AS allin,
    IFNULL(hoursin, 0) AS hoursin,
    IFNULL(allout, 0) AS allout,
    IFNULL(hoursout, 0) AS hoursout,
    IFNULL(t1.people1, 0) AS people1in,
    IFNULL(t2.people1, 0) AS people1out,
    IFNULL(t1.people2, 0) AS people2in,
    IFNULL(t2.people2, 0) AS people2out,
    IFNULL(t1.people3, 0) AS people3in,
    IFNULL(t2.people3, 0) AS people3out,
    IFNULL(t1.people4, 0) AS people4in,
    IFNULL(t2.people4, 0) AS people4out,
    allpeople.allpeople
FROM
    tmp
        LEFT JOIN
    (SELECT 
        idTEACHER,
            SUM(IF(tmp.hours = 1, people, 0)) AS people1,
            SUM(IF(tmp.hours = 2, people, 0)) AS people2,
            SUM(IF(tmp.hours = 3, people, 0)) AS people3,
            SUM(IF(tmp.hours = 4, people, 0)) AS people4,
            COUNT(idLECTURE) AS allin,
            SUM(IF(tmp.hours > 0, hours, 0)) AS hoursin
    FROM
        tmp
    WHERE
        1 = 1 AND tmp.out = 1
    GROUP BY hours , idTEACHER
    ORDER BY name) AS t1 ON tmp.idTEACHER = t1.idTEACHER
        LEFT JOIN
    (SELECT 
        idTEACHER,
            SUM(IF(tmp.hours = 1, people, 0)) AS people1,
            SUM(IF(tmp.hours = 2, people, 0)) AS people2,
            SUM(IF(tmp.hours = 3, people, 0)) AS people3,
            SUM(IF(tmp.hours = 4, people, 0)) AS people4,
            COUNT(idLECTURE) AS allout,
            SUM(IF(tmp.hours > 0, hours, 0)) AS hoursout
    FROM
        tmp
    WHERE
        1 = 1 AND tmp.out = 0
    GROUP BY hours , idTEACHER
    ORDER BY name) AS t2 ON tmp.idTEACHER = t2.idTEACHER
        LEFT JOIN
    allpeople ON 1 = 1
GROUP BY tmp.idTEACHER
ORDER BY description , name

On Windows, where I actually write the code with the same versions of the packages, everything works without hemorrhoids.
Somewhere there is magic, where I can not understand yet :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2018-01-28
@skazi_premiere

1. Possibly due to newlines. Try \n instead of \r\n
2. In order to protect against SQL injection, it is usually not allowed to execute multiple queries at once through ';'. Make separate requests.
3. The names of tables and fields are usually written in lowercase

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question