Skip to content

Commit 7549c73

Browse files
Al Scottdougwilson
authored andcommitted
Add sql property to query Error objects
closes #1462 closes #1628 closes #1629
1 parent 36d0a7e commit 7549c73

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

Changes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ This file is a manually maintained list of changes for each release. Feel free
44
to add your changes here when sending pull requests. Also send corrections if
55
you spot any mistakes.
66

7+
## HEAD
8+
9+
* Add `sql` property to query `Error` objects #1462 #1628 #1629
10+
711
## v2.13.0 (2017-01-24)
812

913
* Accept regular expression as pool cluster pattern #1572

Readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,9 @@ object. Additionally they typically come with two extra properties:
11141114
* `err.fatal`: Boolean, indicating if this error is terminal to the connection
11151115
object. If the error is not from a MySQL protocol operation, this properly
11161116
will not be defined.
1117+
* `err.sql`: String, contains the full SQL of the failed query. This can be
1118+
useful when using a higher level interface like an ORM that is generating
1119+
the queries.
11171120

11181121
[Error]: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error
11191122
[MySQL server error]: http://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html

lib/protocol/sequences/Query.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ Query.prototype['ErrorPacket'] = function(packet) {
8585
: undefined;
8686

8787
err.index = this._index;
88+
err.sql = this.sql;
89+
8890
this.end(err, results, fields);
8991
};
9092

test/unit/query/test-error-event.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ server.listen(common.fakeServerPort, function (err) {
1212
query.on('error', function (err) {
1313
assert.ok(err, 'got error');
1414
assert.equal(err.code, 'ER_PARSE_ERROR');
15+
assert.equal(err.sql, 'INVALID SQL');
1516
assert.ok(!err.fatal);
1617
connection.destroy();
1718
server.destroy();

0 commit comments

Comments
 (0)