Closed Scimonster closed 7 years ago
I can't test it at the moment, but I'd think it would be something like
connection.query().then(function(query) { console.log(query.sql); });
No, it just calls it with an array of RowDataPacket
s. And that wouldn't help anyways when there's an error.
If there's an error then that'll be caught in a catch statement as shown in the readme.
I'll have a try later tonight if I get time
On Wed, 7 Sep 2016, 15:55 Scimonster, notifications@github.com wrote:
No, it just calls it with an array of RowDataPackets. And that wouldn't help anyways when there's an error.
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/lukeb-uk/node-promise-mysql/issues/23#issuecomment-245307127, or mute the thread https://github.com/notifications/unsubscribe-auth/AEjy1I8-xQenXRRql4eV8mBsR34z4rH8ks5qntBmgaJpZM4J2SUM .
Yes, but the error does not give the bad SQL query, just the error code and description. An error about an unexpected ''
doesn't help much if i don't know where that ''
got put.
Sorry, just had a chance to have a look and I understand the issue now. I'll see if there's a way I can solve this.
I'm not sure if this is helpful but you can set debug: ['ComQueryPacket', 'RowDataPacket']
when you create the connection to debug all queries.
Does it have any progress?
Having just had a look into it, @linusnorton's solution should suffice for this. This lib takes the config object you provide and passes it through node-mysql. Thanks Linus!
This is how I am doing it now :)
self.pool.on('connection', function(connection) {
connection.on('enqueue', function(sequence) {
if ('Query' === sequence.constructor.name) {
console.log('\x1b[36m%s\x1b[0m', sequence.sql );
}
});
});
I'm getting some SQL syntax errors right now using the prepared statements, and it would be helpful for debugging to be able to see the SQL query that gets executed. In the original mysql package i could do that as
q=connection.query();console.log(q.sql)
but hereq
is a Promise. Perhaps even just if it throws an error, include that as a property on the error object.