Skip to content

Commit 6e87af8

Browse files
committed
Fix LOAD DATA INFILE handling in multiple statements
fixes #1036
1 parent 8dad7a1 commit 6e87af8

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

Changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ you spot any mistakes.
99
* Add `poolCluster.remove` to remove pools from the cluster #1006 #1007
1010
* Add optional callback to `poolCluster.end`
1111
* Add `restoreNodeTimeout` option to `PoolCluster` #880 #906
12+
* Fix LOAD DATA INFILE handling in multiple statements #1036
1213
* Fix `poolCluster.add` to throw if `PoolCluster` has been closed
1314
* Fix `poolCluster.add` to throw if `id` already defined
1415
* Fix un-catchable error from `PoolCluster` when MySQL server offline #1033

lib/protocol/sequences/Query.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Query.prototype['OkPacket'] = function(packet) {
7474
}
7575
} finally {
7676
this._index++;
77+
this._resultSet = null;
7778
this._handleFinalResultPacket(packet);
7879
}
7980
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
var assert = require('assert');
2+
var common = require('../../common');
3+
var fs = require('fs');
4+
5+
var path = common.fixtures + '/data.csv';
6+
var table = 'multi_load_data_test';
7+
8+
common.getTestConnection({multipleStatements: true}, function (err, connection) {
9+
assert.ifError(err);
10+
11+
common.useTestDb(connection);
12+
13+
connection.query([
14+
'CREATE TEMPORARY TABLE ?? (',
15+
'`id` int(11) unsigned NOT NULL AUTO_INCREMENT,',
16+
'`title` varchar(255),',
17+
'PRIMARY KEY (`id`)',
18+
') ENGINE=InnoDB DEFAULT CHARSET=utf8'
19+
].join('\n'), [table], assert.ifError);
20+
21+
var stmt =
22+
'LOAD DATA LOCAL INFILE ? INTO TABLE ?? CHARACTER SET utf8 ' +
23+
'FIELDS TERMINATED BY ? (id, title)';
24+
25+
var sql =
26+
connection.format(stmt, [path, table, ',']) + ';' +
27+
connection.format(stmt, [path, table, ',']) + ';';
28+
29+
connection.query(sql, function (err, results) {
30+
assert.ifError(err);
31+
assert.equal(results.length, 2);
32+
assert.equal(results[0].affectedRows, 4);
33+
assert.equal(results[1].affectedRows, 0);
34+
});
35+
36+
connection.query('SELECT * FROM ??', [table], function (err, rows) {
37+
assert.ifError(err);
38+
assert.equal(rows.length, 4);
39+
assert.equal(rows[0].id, 1);
40+
assert.equal(rows[0].title, 'Hello World');
41+
assert.equal(rows[3].id, 4);
42+
assert.equal(rows[3].title, '中文内容');
43+
});
44+
45+
connection.end(assert.ifError);
46+
});

0 commit comments

Comments
 (0)