Skip to content

Commit 447b2c3

Browse files
committed
Fix "changedRows" to work on non-English servers
fixes #1819
1 parent 2465811 commit 447b2c3

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

Changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ you spot any mistakes.
77
## HEAD
88

99
* Add new Amazon RDS ca-central-1 certificate CA to Amazon RDS SSL profile #1809
10+
* Fix "changedRows" to work on non-English servers #1819
1011
* Fix typo in insecure auth error message
1112
* Support `mysql_native_password` auth switch request for Azure #1396 #1729 #1730
1213
* Update `bignumber.js` to 4.0.4

Readme.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -855,10 +855,6 @@ You can get the number of changed rows from an update statement.
855855
"changedRows" differs from "affectedRows" in that it does not count updated rows
856856
whose values were not changed.
857857

858-
**Note** this value is parsed from the server message and only works with an English
859-
response. If your mysql server's install is in a different language, use
860-
[affectedRows](#getting-the-number-of-affected-rows).
861-
862858
```js
863859
connection.query('UPDATE posts SET ...', function (error, results, fields) {
864860
if (error) throw error;

lib/protocol/packets/OkPacket.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2+
// Language-neutral expression to match ER_UPDATE_INFO
3+
var ER_UPDATE_INFO_REGEXP = /^[^:0-9]+: [0-9]+[^:0-9]+: ([0-9]+)[^:0-9]+: [0-9]+[^:0-9]*$/;
4+
15
module.exports = OkPacket;
26
function OkPacket(options) {
37
options = options || {};
@@ -22,8 +26,7 @@ OkPacket.prototype.parse = function(parser) {
2226
this.message = parser.parsePacketTerminatedString();
2327
this.changedRows = 0;
2428

25-
var m = this.message.match(/\schanged:\s*(\d+)/i);
26-
29+
var m = ER_UPDATE_INFO_REGEXP.exec(this.message);
2730
if (m !== null) {
2831
this.changedRows = parseInt(m[1], 10);
2932
}

0 commit comments

Comments
 (0)