Skip to content

Commit

Permalink
[misc] correcting batch timezone option handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Dec 10, 2018
1 parent 8b91915 commit 1a4dad2
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/cmd/resultset.js
Expand Up @@ -98,6 +98,8 @@ class ResultSet extends Command {
rowsAsArray: cmdOpts.rowsAsArray != undefined ? cmdOpts.rowsAsArray : connOpts.rowsAsArray,
nestTables: cmdOpts.nestTables != undefined ? cmdOpts.nestTables : connOpts.nestTables,
dateStrings: cmdOpts.dateStrings != undefined ? cmdOpts.dateStrings : connOpts.dateStrings,
timezone: connOpts.timezone,
timezoneMillisOffset: connOpts.timezoneMillisOffset,
namedPlaceholders:
cmdOpts.namedPlaceholders != undefined
? cmdOpts.namedPlaceholders
Expand Down
4 changes: 3 additions & 1 deletion lib/config/connection-options.js
Expand Up @@ -93,7 +93,9 @@ class ConnectionOptions {
this.user = opts.user || process.env.USERNAME;

if (this.maxAllowedPacket && !Number.isInteger(this.maxAllowedPacket)) {
throw new RangeError("maxAllowedPacket must be an integer. was '" + this.maxAllowedPacket + "'");
throw new RangeError(
"maxAllowedPacket must be an integer. was '" + this.maxAllowedPacket + "'"
);
}
}

Expand Down
66 changes: 66 additions & 0 deletions test/integration/test-batch.js
Expand Up @@ -204,6 +204,66 @@ describe("batch", () => {
.catch(done);
};

const simpleBatchWithOptions = (useCompression, useBulk, done) => {
base
.createConnection({ compress: useCompression, bulk: useBulk })
.then(conn => {
const timeout = setTimeout(() => {
console.log(conn.info.getLastPackets());
}, 25000);

conn.query("DROP TABLE IF EXISTS simpleBatchWithOptions");
conn.query("CREATE TABLE simpleBatchWithOptions(id int, d datetime)");
const f = {};
f.toSqlString = () => {
return "blabla";
};
conn
.batch(
{
sql: "INSERT INTO `simpleBatchWithOptions` values (?, ?)",
maxAllowedPacket: 1048576
},
[[1, new Date("2001-12-31 23:59:58")], [2, new Date("2001-12-31 23:59:58")]]
)
.then(res => {
assert.equal(res.affectedRows, 2);
conn
.query("select * from `simpleBatchWithOptions`")
.then(res => {
assert.deepEqual(res, [
{
id: 1,
d: new Date("2001-12-31 23:59:58")
},
{
id: 2,
d: new Date("2001-12-31 23:59:58")
}
]);
conn
.query("DROP TABLE simpleBatchWithOptions")
.then(res => {
clearTimeout(timeout);
conn.end();
done();
})
.catch(done);
})
.catch(err => {
done(err);
});
});
conn
.query("select 1")
.then(rows => {
assert.deepEqual(rows, [{ "1": 1 }]);
})
.catch(done);
})
.catch(done);
};

const simpleBatchEncodingCP1251 = (useCompression, useBulk, timezone, done) => {
base
.createConnection({ compress: useCompression, bulk: useBulk, charset: "CP1251_GENERAL_CI" })
Expand Down Expand Up @@ -1143,6 +1203,12 @@ describe("batch", () => {
simpleBatch(useCompression, true, "local", done);
});

it("simple batch with option", function(done) {
this.timeout(30000);
if (!shareConn.info.isMariaDB() && !shareConn.info.hasMinVersion(5, 6, 0)) this.skip();
simpleBatchWithOptions(useCompression, true, done);
});

it("batch without parameter", function(done) {
if (!shareConn.info.isMariaDB() && !shareConn.info.hasMinVersion(5, 6, 0)) this.skip();
base.createConnection({ compress: useCompression, bulk: true }).then(conn => {
Expand Down
3 changes: 2 additions & 1 deletion test/integration/test-connection.js
Expand Up @@ -347,7 +347,8 @@ describe("connection", () => {
.then(() => done(new Error("expected error !")))
.catch(err => {
assert.isTrue(err != null);
assert.isTrue(err.message.includes("Connection destroyed, command was killed"));
if (!process.env.MAXSCALE_VERSION)
assert.isTrue(err.message.includes("Connection destroyed, command was killed"));
assert.isTrue(err.fatal);
done();
});
Expand Down
3 changes: 1 addition & 2 deletions test/unit/config/test-connection-options.js
Expand Up @@ -54,10 +54,9 @@ describe("test connection options", () => {
assert.equal(result.user, "root");
});


it("wrong maxAllowedPacket value", () => {
try {
new ConnOptions({maxAllowedPacket: "abc"});
new ConnOptions({ maxAllowedPacket: "abc" });
return new Error("must have thrown exception");
} catch (e) {
assert.isTrue(e.message.includes("maxAllowedPacket must be an integer. was 'abc'"));
Expand Down

0 comments on commit 1a4dad2

Please sign in to comment.