kylefarris / node-querybuilder

Node QueryBuilder Adapter for Node.js (tags: nodejs, node, mysql, active record, activerecord, querybuilder, query builder)
49 stars 19 forks source link

update_batch not working with where clause #23

Closed arifjaunpur closed 6 years ago

arifjaunpur commented 6 years ago

whenever we pass where condition in .update_batch(table,dataset,index[,where],callback), it throws following 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 'WHERE `id` = 30 AND `tripId` IN (30,30)' at line 1
    at Query.Sequence._packetToError (/home/mohd/app/express-test/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)
    at Query.ErrorPacket (/home/mohd/app/express-test/node_modules/mysql/lib/protocol/sequences/Query.js:77:18)
    at Protocol._parsePacket (/home/mohd/app/express-test/node_modules/mysql/lib/protocol/Protocol.js:279:23)
    at Parser.write (/home/mohd/app/express-test/node_modules/mysql/lib/protocol/Parser.js:76:12)
    at Protocol.write (/home/mohd/app/express-test/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/home/mohd/app/express-test/node_modules/mysql/lib/Connection.js:103:28)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    --------------------
    at Protocol._enqueue (/home/mohd/app/express-test/node_modules/mysql/lib/protocol/Protocol.js:145:48)
    at Connection.query (/home/mohd/app/express-test/node_modules/mysql/lib/Connection.js:208:25)
    at exec (/home/mohd/app/express-test/node_modules/node-querybuilder/drivers/mysql/query_exec.js:11:18)
    at next_batch (/home/mohd/app/express-test/node_modules/node-querybuilder/drivers/mysql/query_exec.js:151:17)
    at Object.update_batch (/home/mohd/app/express-test/node_modules/node-querybuilder/drivers/mysql/query_exec.js:169:15)
    at Object.<anonymous> (/home/mohd/app/express-test/b.js:26:17)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    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 \'WHERE `id` = 30 AND `tripId` IN (30,30)\' at line 1',
    sqlState: '42000',
    index: 0,
    sql: 'UPDATE (`trip_students_booking`) SET `studentId` = CASE WHEN `tripId` = 30 THEN 43 WHEN `tripId` = 30 THEN 42 ELSE `studentId` END WHERE  WHERE `id` = 30 AND `tripId` IN (30,30)' } ]

We can see that 2 times added where clause

arifjaunpur commented 6 years ago

after fixing above issue in library, got another issue

/home/mohd/app/express-test/node_modules/mysql/lib/protocol/Parser.js:80
        throw err; // Rethrow non-MySQL errors
        ^

TypeError: Assignment to constant variable.
    at exec (/home/mohd/app/express-test/node_modules/node-querybuilder/drivers/mysql/query_exec.js:154:37)
    at Query.conn.query [as _callback] (/home/mohd/app/express-test/node_modules/node-querybuilder/drivers/mysql/query_exec.js:31:17)
    at Query.Sequence.end (/home/mohd/app/express-test/node_modules/mysql/lib/protocol/sequences/Sequence.js:88:24)
    at Query._handleFinalResultPacket (/home/mohd/app/express-test/node_modules/mysql/lib/protocol/sequences/Query.js:139:8)
    at Query.OkPacket (/home/mohd/app/express-test/node_modules/mysql/lib/protocol/sequences/Query.js:72:10)
    at Protocol._parsePacket (/home/mohd/app/express-test/node_modules/mysql/lib/protocol/Protocol.js:279:23)
    at Parser.write (/home/mohd/app/express-test/node_modules/mysql/lib/protocol/Parser.js:76:12)
    at Protocol.write (/home/mohd/app/express-test/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/home/mohd/app/express-test/node_modules/mysql/lib/Connection.js:103:28)
    at emitOne (events.js:116:13)
kylefarris commented 6 years ago

This is officially working in the v2 branch.