Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[BUG] insert_id is incorrect for values greater than 250. (patch from…

… Ben Trask)
  • Loading branch information...
commit c68a8b24c0284d79c6556f359f4d656e33fdaa01 1 parent 38ee501
@masuidrive authored
Showing with 54 additions and 18 deletions.
  1. +1 −1  AUTHORS
  2. +5 −5 lib/mysql/packet.js
  3. +48 −12 test/test.real_mysql.js
View
2  AUTHORS
@@ -6,4 +6,4 @@ Delyan Angelov <delian66@gmail.com>
Oleg Efimov <efimovov@gmail.com>
Peter Rekdal Sunde <peter.sunde@gmail.com>
mape <http://github.com/mape>
-
+Ben Trask <bentrask@comcast.net>
View
10 lib/mysql/packet.js
@@ -33,20 +33,20 @@ var lcb2int = function(lcbs) {
break;
case "\xfc":
- lcb = lcb.slice(2);
v = pack.unpack("v", lcb.substring(0,2))[0];
+ lcb = lcb.slice(2);
break;
case "\xfd":
- lcb = lcb.slice(3);
v = pack.unpack("Cv", lcb.substring(0,3));
- v = (v[1]<<8+v[0]);
+ lcb = lcb.slice(3);
+ v = (v[1]<<8)+v[0];
break;
case "\xfe":
- lcb = lcb.slice(8);
v = pack.unpack("VV", lcb.substring(0,8));
- v = (v[1]<<32+v[0]);
+ lcb = lcb.slice(8);
+ v = (v[1]<<32)+v[0];
break;
default:
View
60 test/test.real_mysql.js
@@ -36,7 +36,7 @@ var test_result1 = function() {
helper.exceptClass(mysql.Connection, conn);
conn.connect();
conn.query("CREATE TEMPORARY TABLE t (id INTEGER, str VARCHAR(254), PRIMARY KEY (id)) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci'");
- conn.query("INSERT INTO t VALUES (1,'abc'),(2,'0'),(3,''),(4,null)");
+ conn.query("INSERT INTO t VALUES (1,'abc'),(2,'0'),(3,''),(256,null)");
// execute SELECT query
helper.expect_callback();
@@ -83,8 +83,8 @@ var test_result1 = function() {
assert.equal('0', result.records[1][1]); // string
assert.equal(3, result.records[2][0]);
assert.equal('', result.records[2][1]); // blank string
- assert.equal(4, result.records[3][0]);
- assert.equal(null, result.records[3][1]); // null string
+ assert.equal(256, result.records[3][0]);
+ assert.equal(undefined, result.records[3][1]); // null string
// result hash fieldname
var res = result.toHash(result.records[0]);
@@ -97,7 +97,7 @@ var test_result1 = function() {
assert.equal(res['id'], 3);
assert.equal(res['str'], '');
var res = result.toHash(result.records[3]);
- assert.equal(res['id'], 4);
+ assert.equal(res['id'], 256);
assert.equal(res['str'], undefined);
// result hash with table name
@@ -112,7 +112,7 @@ var test_result1 = function() {
assert.equal(res['t.id'], 3);
assert.equal(res['t.str'], '');
var res = result.toHash(result.records[3]);
- assert.equal(res['t.id'], 4);
+ assert.equal(res['t.id'], 256);
assert.equal(res['t.str'], undefined);
// result hash fieldname
@@ -127,9 +127,8 @@ var test_result1 = function() {
assert.equal(res['id'], 3);
assert.equal(res['str'], '');
var res = result.toHash(result.records[3]);
- assert.equal(res['id'], 4);
+ assert.equal(res['id'], 256);
assert.equal(res['str'], undefined);
-
});
// table & column alias
@@ -152,7 +151,7 @@ var test_result1 = function() {
assert.equal(1, result.records[0][0]);
assert.equal(2, result.records[1][0]);
assert.equal(3, result.records[2][0]);
- assert.equal(4, result.records[3][0]);
+ assert.equal(256, result.records[3][0]);
// result hash
result.fieldname_with_table = true
@@ -163,7 +162,7 @@ var test_result1 = function() {
var res = result.toHash(result.records[2]);
assert.equal(res['ttt.pkey'], 3);
var res = result.toHash(result.records[3]);
- assert.equal(res['ttt.pkey'], 4);
+ assert.equal(res['ttt.pkey'], 256);
// result hash fieldname without table
result.fieldname_with_table = false
@@ -174,19 +173,56 @@ var test_result1 = function() {
var res = result.toHash(result.records[2]);
assert.equal(res['pkey'], 3);
var res = result.toHash(result.records[3]);
- assert.equal(res['pkey'], 4);
+ assert.equal(res['pkey'], 256);
conn.close();
promise.emitSuccess();
},
function(error) {
- assert.ok(true, false);
+ assert.ok(false);
});
- return promise
+ return promise;
};
all_tests.push(["test_result1", test_result1]);
+var test_insert256rows = function() {
+ var promise = new Promise();
+ var conn = new mysql.Connection(config.mysql.hostname,
+ config.mysql.username,
+ config.mysql.password,
+ config.mysql.database);
+ helper.exceptClass(mysql.Connection, conn);
+ conn.connect();
+ conn.query("CREATE TEMPORARY TABLE t (id INTEGER)");
+ var q = [];
+ for(var i=0; i<256; ++i) {
+ q.push("("+i+")");
+ }
+ conn.query("INSERT INTO t(id) VALUES "+q.join(","), function(result) {
+ assert.equal(1,2);
+ assert.equal(256, result.affected_rows);
+ });
+
+ // execute SELECT query
+ helper.expect_callback();
+ conn.query('SELECT * FROM t ORDER BY id', function(result) { // Success
+ helper.was_called_back();
+
+ assert.equal(1, result.fields.length);
+ assert.equal(256, result.records.length);
+
+ conn.close();
+ promise.emitSuccess();
+ },
+ function(error) {
+ assert.ok(false);
+ });
+
+ return promise;
+};
+all_tests.push(["test_insert256rows", test_insert256rows]);
+
var test_query_without_table = function() {
var promise = new Promise();
Please sign in to comment.
Something went wrong with that request. Please try again.