Skip to content

Commit

Permalink
Merge branch 'release/2.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Mar 20, 2020
2 parents 90170fd + d05f059 commit fe920bb
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Change Log
## [2.3.1](https://github.com/mariadb-corporation/mariadb-connector-nodejs/tree/2.3.1) (19 Mar. 2020)
[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-nodejs/compare/2.3.0...2.3.1)

Corrective release of 2.3.0, changing new connection option `timeout` to `queryTimeout` to avoid any confusion.

## [2.3.0](https://github.com/mariadb-corporation/mariadb-connector-nodejs/tree/2.3.0) (19 Mar. 2020)
[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-nodejs/compare/2.2.0...2.3.0)
* CONJS-127 - Resultset with same identifier skip data. Now an error will be thrown.
Expand Down
1 change: 1 addition & 0 deletions documentation/callback-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ Essential options list:
| **`compress`** | Compresses the exchange with the database through gzip. This permits better performance when the database is not in the same location. |*boolean*| false|
| **`connectTimeout`** | Sets the connection timeout in milliseconds. |*integer* | 10 000|
| **`socketTimeout`** | Sets the socket timeout in milliseconds after connection succeeds. A value of `0` disables the timeout. |*integer* | 0|
| **`queryTimeout`** | Set maximum query time in ms (an error will be thrown if limit is reached). 0 or undefined meaning no timeout. This can be superseded for a query using `timeout` option|*int* |0|
| **`rowsAsArray`** | Returns result-sets as arrays, rather than JSON. This is a faster way to get results. For more information, see Query. |*boolean* | false|

For more information, see the [Connection Options](/documentation/connection-options.md) documentation.
Expand Down
1 change: 0 additions & 1 deletion documentation/connection-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ mariadb.createConnection({
| **collation** | (used in replacement of charset) Permit to defined collation used for connection. This will defined the charset encoding used for exchanges with database and defines the order used when comparing strings. It's mainly used for micro-optimizations|*string* |UTF8MB4_UNICODE_CI|
| **dateStrings** | Whether to retrieve dates as strings or as `Date` objects. |*boolean* |false|
| **debug** | Logs all exchanges with the server. Displays in hexa.|*boolean* |false|
| **timeout** | Set maximum query time in ms. 0 / undefined meaning no timeout|*int* |0|
| **foundRows** | When enabled, the update number corresponds to update rows. When disabled, it indicates the real rows changed. | *boolean* |true|
| **multipleStatements** | Allows you to issue several SQL statements in a single `quer()` call. (That is, `INSERT INTO a VALUES('b'); INSERT INTO c VALUES('d');`). <br/><br/>This may be a **security risk** as it allows for SQL Injection attacks. |*boolean* |false|
| **namedPlaceholders** | Allows the use of named placeholders. |*boolean* |false|
Expand Down
1 change: 1 addition & 0 deletions documentation/promise-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ Essential options list:
| **`compress`** | Compresses the exchange with the database through gzip. This permits better performance when the database is not in the same location. |*boolean*| false|
| **`connectTimeout`** | Sets the connection timeout in milliseconds. |*integer* | 10 000|
| **`socketTimeout`** | Sets the socket timeout in milliseconds after connection succeeds. A value of `0` disables the timeout. |*integer* | 0|
| **`queryTimeout`** | Set maximum query time in ms (an error will be thrown if limit is reached). 0 or undefined meaning no timeout. This can be superseded for a query using [`timeout`](https://github.com/mariadb-corporation/mariadb-connector-nodejs/blob/master/documentation/promise-api.md#timeout) option|*int* |0|
| **`rowsAsArray`** | Returns result-sets as arrays, rather than JSON. This is a faster way to get results. For more information, see Query. |*boolean* | false|

For more information, see the [Connection Options](/documentation/connection-options.md) documentation.
Expand Down
2 changes: 0 additions & 2 deletions lib/cmd/resultset.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ class ResultSet extends Command {
configAssign(connOpts, cmdOpts) {
if (!cmdOpts) {
this.opts = connOpts;
// we only need add timeout if needed
this.opts.timeout = 0;
return;
}
this.opts = {
Expand Down
4 changes: 2 additions & 2 deletions lib/config/connection-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ConnectionOptions {
this.logPackets = opts.logPackets || false;
this.connectAttributes = opts.connectAttributes || false;
this.connectTimeout = opts.connectTimeout === undefined ? 10000 : opts.connectTimeout;
this.timeout = opts.timeout === undefined ? 0 : opts.timeout;
this.queryTimeout = opts.queryTimeout === undefined ? 0 : opts.queryTimeout;
this.socketTimeout = opts.socketTimeout === undefined ? 0 : opts.socketTimeout;
this.database = opts.database;
this.checkDuplicate = opts.checkDuplicate === undefined ? true : opts.checkDuplicate;
Expand Down Expand Up @@ -175,7 +175,7 @@ class ConnectionOptions {
if (opts.checkDuplicate) opts.checkDuplicate = opts.checkDuplicate == 'true';
if (opts.debugCompress) opts.debugCompress = opts.debugCompress == 'true';
if (opts.debugLen) opts.debugLen = parseInt(opts.debugLen);
if (opts.timeout) opts.timeout = parseInt(opts.timeout);
if (opts.queryTimeout) opts.queryTimeout = parseInt(opts.queryTimeout);
if (opts.foundRows) opts.foundRows = opts.foundRows == 'true';
if (opts.maxAllowedPacket && !isNaN(Number.parseInt(opts.maxAllowedPacket)))
opts.maxAllowedPacket = parseInt(opts.maxAllowedPacket);
Expand Down
9 changes: 5 additions & 4 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -811,13 +811,13 @@ function Connection(options) {
};

const _executeSessionTimeout = () => {
if (opts.timeout) {
if (opts.queryTimeout) {
if (info.isMariaDB() && info.hasMinVersion(10, 1, 2)) {
return new Promise(function(resolve, reject) {
const errorHandling = initialErr => {
reject(
Errors.createError(
'Error setting session timeout: ' + initialErr.message,
'Error setting session queryTimeout: ' + initialErr.message,
true,
info,
'08S01',
Expand All @@ -831,7 +831,7 @@ function Connection(options) {
errorHandling,
null,
opts,
'SET max_statement_time=' + opts.timeout / 1000,
'SET max_statement_time=' + opts.queryTimeout / 1000,
null
);
if (opts.trace) Error.captureStackTrace(cmd);
Expand All @@ -840,7 +840,8 @@ function Connection(options) {
} else {
return Promise.reject(
Errors.createError(
'Can only use timeout for MariaDB server after 10.1.1. timeout value: ' + opts.timeout,
'Can only use queryTimeout for MariaDB server after 10.1.1. queryTimeout value: ' +
opts.queryTimeout,
false,
info,
'HY000',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mariadb",
"version": "2.3.0",
"version": "2.3.1",
"description": "fast mariadb/mysql connector.",
"main": "promise.js",
"types": "types/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions test/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const basePromise = require('../promise');
const baseCallback = require('../callback');
const Conf = require('./conf');
const Collations = require('../lib/const/collations.js');
const { assert } = require('chai');

//*****************************************************************
// initialize share connection
Expand Down
30 changes: 29 additions & 1 deletion test/integration/test-connection-opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ describe('connection option', () => {
this.timeout(10000);
if (shareConn.info.isMariaDB() && shareConn.info.hasMinVersion(10, 1, 2)) {
base
.createConnection({ multipleStatements: true, timeout: 1000 })
.createConnection({ multipleStatements: true, queryTimeout: 1000 })
.then(conn => {
conn
.query(
Expand Down Expand Up @@ -448,4 +448,32 @@ describe('connection option', () => {
});
}
});

it('connection timeout superseded', function(done) {
this.timeout(10000);
if (shareConn.info.isMariaDB() && shareConn.info.hasMinVersion(10, 1, 2)) {
base
.createConnection({ multipleStatements: true, queryTimeout: 10000000 })
.then(conn => {
conn
.query({
timeout: 1000,
sql:
'SELECT 1;select c1.* from information_schema.columns as c1, information_schema.tables, information_schema.tables as t2'
})
.then(() => {
conn.end();
done(new Error('must have thrown error'));
})
.catch(err => {
assert.equal(err.errno, 1969);
assert.equal(err.sqlState, '70100');
assert.equal(err.code, 'ER_STATEMENT_TIMEOUT');
conn.end();
done();
});
})
.catch(done);
}
});
});

0 comments on commit fe920bb

Please sign in to comment.