Skip to content

Commit b03ba5b

Browse files
committed
[CONJS-343] batch hangs when having an empty parameters values
1 parent e054849 commit b03ba5b

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

lib/connection.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ class Connection extends EventEmitter {
193193
return this.handleMissingValuesError(cmdParam, reject);
194194
}
195195

196+
// no parameters
197+
if ((Array.isArray(cmdParam.values) && cmdParam.values.length === 0)) {
198+
resolve();
199+
}
200+
196201
// Execute the batch operation
197202
this.prepare(
198203
cmdParam,

test/integration/batch.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,17 @@ describe.sequential(
15711571
}
15721572
});
15731573

1574+
test('batch with empty array values #343', async ({ skip }) => {
1575+
if (!shareConn.info.isMariaDB() && !shareConn.info.hasMinVersion(5, 6, 0)) return skip();
1576+
1577+
const conn = await createConnection({ bulk: true });
1578+
await conn.query('CREATE TEMPORARY TABLE empty_array_value(id int not null primary key auto_increment, id2 int)');
1579+
await conn.batch('INSERT INTO `empty_array_value`(id2) values (?)', []);
1580+
const res = await conn.query('select * from `empty_array_value`');
1581+
assert.deepEqual(res, []);
1582+
await conn.end();
1583+
});
1584+
15741585
test('batch with erroneous parameter', async ({ skip }) => {
15751586
if (!shareConn.info.isMariaDB() && !shareConn.info.hasMinVersion(5, 6, 0)) return skip();
15761587

@@ -1750,6 +1761,19 @@ describe.sequential(
17501761
}
17511762
});
17521763

1764+
test('batch with empty array values #343', async ({ skip }) => {
1765+
if (!shareConn.info.isMariaDB() && !shareConn.info.hasMinVersion(5, 6, 0)) return skip();
1766+
1767+
const conn = await createConnection({ bulk: false });
1768+
await conn.query(
1769+
'CREATE TEMPORARY TABLE empty_array_value(id int not null primary key auto_increment, id2 int)'
1770+
);
1771+
await conn.batch('INSERT INTO `empty_array_value`(id2) values (?)', []);
1772+
const res = await conn.query('select * from `empty_array_value`');
1773+
assert.deepEqual(res, []);
1774+
await conn.end();
1775+
});
1776+
17531777
test('rewrite split for maxAllowedPacket', async ({ skip }) => {
17541778
const t = makeid(100);
17551779
const conn = await createConnection({ bulk: false, maxAllowedPacket: 150 });

test/integration/file.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('sql file import', () => {
1818
maxAllowedSize = Number(row[0].t);
1919
});
2020
afterAll(async () => {
21-
await shareConn.end();
21+
if (shareConn) await shareConn.end();
2222
shareConn = null;
2323
});
2424

0 commit comments

Comments
 (0)