Skip to content

sql.query() Error: ER_PARSE_ERROR: You have an error in your SQL syntax #2398

@R00tCrop

Description

@R00tCrop

Node, code in async function code:

const queryString = 'UPDATE users SET ? = ?, ? = ?, ? = ?, ? = ?, ? = ? WHERE id = ?'
const queryArgsArray = [ 'phone', '+380550236275', 'fn', 'Stas', 'ln', 'Test', 'bday', '123456', 'sex', 'm',  3 ]
const userId = 3
            const query = new Promise((resolve,reject) => {
                sql.query(
                    queryString,
                    queryArgsArray,
                    (e,res) => {
                        if(e) return reject(e)
                        if(res.length) return resolve(res[0])
                        resolve(null)
                    }
                )
            })
            const result = await query

error:

{ Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''phone' = '+380550236275', 'fn' = 'Stas', 'ln' = 'Test', 'bday' = '123456', 'sex' at line 1
    at Query.Sequence._packetToError (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
    at Query.ErrorPacket (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\protocol\sequences\Query.js:79:18)
    at Protocol._parsePacket (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\protocol\Protocol.js:291:23)
    at Parser._parsePacket (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\protocol\Parser.js:433:10)
    at Parser.write (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\protocol\Parser.js:43:10)
    at Protocol.write (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\protocol\Protocol.js:38:16)
    at Socket.<anonymous> (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\Connection.js:88:28)
    at Socket.<anonymous> (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\Connection.js:526:10)
    at Socket.emit (events.js:189:13)
    at addChunk (_stream_readable.js:284:12)
    at readableAddChunk (_stream_readable.js:265:11)
    at Socket.Readable.push (_stream_readable.js:220:10)
    at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
    --------------------
    at Protocol._enqueue (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\protocol\Protocol.js:144:48)
    at Connection.query (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\Connection.js:198:25)
    at Promise (D:\JSlearn\skinEndRenewal\models\User.js:294:21)
    at new Promise (<anonymous>)
    at User.setData (D:\JSlearn\skinEndRenewal\models\User.js:293:27)
    at router.post (D:\JSlearn\skinEndRenewal\routes\profile.js:92:24)
  code: 'ER_PARSE_ERROR',
  errno: 1064,
  sqlMessage:
   'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'\'phone\' = \'+380550236275\', \'fn\' = \'Stas\', \'ln\' = \'Test\', \'bday\' = \'123456\', \'sex\' at line 1',
  sqlState: '42000',
  index: 0,
  sql:
   'UPDATE users SET \'phone\' = \'+380550236275\', \'fn\' = \'Stas\', \'ln\' = \'Test\', \'bday\' = \'123456\', \'sex\' = \'m\' WHERE id = 3' }
profile.change.error { Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''phone' = '+380550236275', 'fn' = 'Stas', 'ln' = 'Test', 'bday' = '123456', 'sex' at line 1
    at Query.Sequence._packetToError (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
    at Query.ErrorPacket (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\protocol\sequences\Query.js:79:18)
    at Protocol._parsePacket (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\protocol\Protocol.js:291:23)
    at Parser._parsePacket (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\protocol\Parser.js:433:10)
    at Parser.write (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\protocol\Parser.js:43:10)
    at Protocol.write (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\protocol\Protocol.js:38:16)
    at Socket.<anonymous> (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\Connection.js:88:28)
    at Socket.<anonymous> (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\Connection.js:526:10)
    at Socket.emit (events.js:189:13)
    at addChunk (_stream_readable.js:284:12)
    at readableAddChunk (_stream_readable.js:265:11)
    at Socket.Readable.push (_stream_readable.js:220:10)
    at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
    --------------------
    at Protocol._enqueue (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\protocol\Protocol.js:144:48)
    at Connection.query (D:\JSlearn\skinEndRenewal\node_modules\mysql\lib\Connection.js:198:25)
    at Promise (D:\JSlearn\skinEndRenewal\models\User.js:294:21)
    at new Promise (<anonymous>)
    at User.setData (D:\JSlearn\skinEndRenewal\models\User.js:293:27)
    at router.post (D:\JSlearn\skinEndRenewal\routes\profile.js:92:24)
  code: 'ER_PARSE_ERROR',
  errno: 1064,
  sqlMessage:
   'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'\'phone\' = \'+380550236275\', \'fn\' = \'Stas\', \'ln\' = \'Test\', \'bday\' = \'123456\', \'sex\' at line 1',
  sqlState: '42000',
  index: 0,
  sql:
   'UPDATE users SET \'phone\' = \'+380550236275\', \'fn\' = \'Stas\', \'ln\' = \'Test\', \'bday\' = \'123456\', \'sex\' = \'m\' WHERE id = 3' }

With this style I have made other queries that work fine. The error is not related to asynchrony or anything else, the problem is in the sql query itself. Sorry if the error occurred due to my stupidity, but reading the examples and google did not help me (((

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions