Skip to content

Commit

Permalink
Merge branch 'release/3.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Mar 16, 2023
2 parents 0b6b64a + ed4bafc commit c00e0f1
Show file tree
Hide file tree
Showing 35 changed files with 739 additions and 340 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ jobs:
fast_finish: true
allow_failures:
- env: srv=build
- env: srv=xpand RUN_LONG_TEST=0
include:
- stage: Minimal
env: srv=mariadb v=10.6 local=1
Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Change Log

## [3.1.0](https://github.com/mariadb-corporation/mariadb-connector-nodejs/tree/3.0.2) (Feb 2023)
## [3.1.1](https://github.com/mariadb-corporation/mariadb-connector-nodejs/tree/3.1.1) (Mar 2023)
[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-nodejs/compare/3.1.0...3.1.1)

## Issues Fixed
* CONJS-246 pool not listening to 'error' event might exit application on error
* CONJS-240 Repeating calling the same procedure gets a release prepare error.
* CONJS-244 correction for node.js 12 compatibility
* CONJS-245 batch failing when using bulk and metaAsArray


## [3.1.0](https://github.com/mariadb-corporation/mariadb-connector-nodejs/tree/3.1.0) (Feb 2023)
[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-nodejs/compare/3.0.2...3.1.0)

## Notable changes
Expand Down
5 changes: 4 additions & 1 deletion callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ module.exports.createConnection = function createConnection(opts) {

exports.createPool = function createPool(opts) {
const options = new PoolOptions(opts);
return new PoolCallback(options);
const pool = new PoolCallback(options);
// adding a default error handler to avoid exiting application on connection error.
pool.on('error', (err) => {});
return pool;
};

exports.createPoolCluster = function createPoolCluster(opts) {
Expand Down
8 changes: 6 additions & 2 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,15 @@ class Cluster extends EventEmitter {
}

_createPool(options) {
return new PoolPromise(options);
const pool = new PoolPromise(options);
pool.on('error', (err) => {});
return pool;
}

_createPoolCallback(options) {
return new PoolCallback(options);
const pool = new PoolCallback(options);
pool.on('error', (err) => {});
return pool;
}

/**
Expand Down
46 changes: 35 additions & 11 deletions lib/cmd/batch-bulk.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,13 @@ class BatchBulk extends Parser {

success(val) {
this.bulkPacketNo--;
if (val instanceof OkPacket) this._rows.push(val);

// fast path doesn't push OkPacket if ony one results
if (this._responseIndex === 0) {
if (this.opts.metaAsArray) {
if (val[0] instanceof OkPacket) this._rows.push(val[0]);
} else if (val instanceof OkPacket) this._rows.push(val);
}

if (!this.sending && this.bulkPacketNo === 0) {
this.packet = null;
Expand All @@ -397,19 +403,37 @@ class BatchBulk extends Parser {
this._rows[0].insertId,
this._rows[this._rows.length - 1].warningStatus
);
this.successEnd(rs);
this.successEnd(this.opts.metaAsArray ? [rs, []] : rs);
} else {
// insert with returning
if (this._rows.length === 1) {
this.successEnd(this._rows[0]);
this.successEnd(this.opts.metaAsArray ? [this._rows[0], this._columns] : this._rows[0]);
}
if (this.opts.metaAsArray) {
if (this._rows.length === 1) {
this.successEnd([this._rows[0], this._columns]);
} else {
const rs = [];
this._rows.forEach((row) => {
rs.push(...row);
});
this.successEnd([rs, this._columns]);
}
} else {
const rs = [];
rs.meta = this._rows[0].meta;
this._rows.forEach((row) => {
Array.prototype.push.apply(rs, row);
});
rs.meta = this._rows[0].meta;
this.successEnd(rs);
// insert with returning
if (this._rows.length === 1) {
this.successEnd(this._rows[0]);
} else {
const rs = [];
this._rows.forEach((row) => {
rs.push(...row);
});
Object.defineProperty(rs, 'meta', {
value: this._columns,
writable: true,
enumerable: this.opts.metaEnumerable
});
this.successEnd(rs);
}
}
}
this._columns = null;
Expand Down
12 changes: 6 additions & 6 deletions lib/cmd/column-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class BaseStringParser {
this.readString = readFct;
}

#readIdentifier(skip) {
_readIdentifier(skip) {
let pos = 0;
while (skip-- > 0) {
const type = this.buf[pos++] & 0xff;
Expand Down Expand Up @@ -152,27 +152,27 @@ class BaseStringParser {
}

name() {
return this.#readIdentifier(3);
return this._readIdentifier(3);
}

db() {
return this.#readIdentifier(0);
return this._readIdentifier(0);
}

schema() {
return this.db();
}

table() {
return this.#readIdentifier(1);
return this._readIdentifier(1);
}

orgTable() {
return this.#readIdentifier(2);
return this._readIdentifier(2);
}

orgName() {
return this.#readIdentifier(4);
return this._readIdentifier(4);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/cmd/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Parser extends Command {
this._responseIndex++;
return (this.onPacketReceive = this.readResponsePacket);
}
return this.success(this.opts.metaAsArray ? [okPacket, [null]] : okPacket);
return this.success(this.opts.metaAsArray ? [okPacket, []] : okPacket);
}

this._rows.push(okPacket);
Expand Down
8 changes: 4 additions & 4 deletions lib/cmd/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Query extends Parser {
// param is stream,
// now all params will be written by event
//********************************************
this.paramWritten = this.#paramWritten.bind(this, out, info);
this.paramWritten = this._paramWritten.bind(this, out, info);
out.writeInt8(QUOTE); //'
value.on('data', out.writeBufferEscape.bind(out));

Expand Down Expand Up @@ -128,7 +128,7 @@ class Query extends Parser {
return true;
} else {
const err = Errors.createError(
`Cannot use timeout for MariaDB server before 10.1.2. timeout value: ${this.opts.timeout}`,
`Cannot use timeout for xpand/MariaDB server before 10.1.2. timeout value: ${this.opts.timeout}`,
Errors.ER_TIMEOUT_NOT_SUPPORTED,
info,
'HY000',
Expand Down Expand Up @@ -194,7 +194,7 @@ class Query extends Parser {
return true;
}

#paramWritten(out, info) {
_paramWritten(out, info) {
while (true) {
if (this.valueIdx === this.paramPositions.length / 2) {
//********************************************
Expand Down Expand Up @@ -225,7 +225,7 @@ class Query extends Parser {
'end',
function () {
out.writeInt8(QUOTE);
this.#paramWritten(out, info);
this._paramWritten(out, info);
}.bind(this)
);
value.on('data', out.writeBufferEscape.bind(out));
Expand Down
43 changes: 32 additions & 11 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class Connection extends EventEmitter {
return new Promise(this.executeBulkPromise.bind(this, cmdParam, prepare, this.opts));
} else {
const executes = [];
const cmdOpt = Object.assign({}, this.opts, cmdParam.opts);
for (let i = 0; i < vals.length; i++) {
executes.push(prepare.execute(vals[i], cmdParam.opts, null, cmdParam.stack));
}
Expand All @@ -215,25 +216,44 @@ class Connection extends EventEmitter {
return Promise.resolve(res);
} else {
// aggregate results
const firstResult = res[0];
let firstResult = res[0];
if (cmdOpt.metaAsArray) firstResult = firstResult[0];
if (firstResult instanceof OkPacket) {
let affectedRows = 0;
const insertId = firstResult.insertId;
const warningStatus = firstResult.warningStatus;
for (let i = 0; i < res.length; i++) {
affectedRows += res[i].affectedRows;
if (cmdOpt.metaAsArray) {
for (let i = 0; i < res.length; i++) {
affectedRows += res[i][0].affectedRows;
}
return Promise.resolve([new OkPacket(affectedRows, insertId, warningStatus), []]);
} else {
for (let i = 0; i < res.length; i++) {
affectedRows += res[i].affectedRows;
}
return Promise.resolve(new OkPacket(affectedRows, insertId, warningStatus));
}
return Promise.resolve(new OkPacket(affectedRows, insertId, warningStatus));
} else {
// results have result-set. example :'INSERT ... RETURNING'
// aggregate results
const rs = [];
rs.meta = res.meta;
res.forEach((row) => {
Array.prototype.push.apply(rs, row);
});
rs.meta = res.meta;
return Promise.resolve(rs);
if (cmdOpt.metaAsArray) {
const rs = [];
res.forEach((row) => {
rs.push(...row[0]);
});
return Promise.resolve([rs, res[0][1]]);
} else {
const rs = [];
res.forEach((row) => {
rs.push(...row);
});
Object.defineProperty(rs, 'meta', {
value: res[0].meta,
writable: true,
enumerable: this.opts.metaEnumerable
});
return Promise.resolve(rs);
}
}
}
}.bind(this)
Expand Down Expand Up @@ -337,6 +357,7 @@ class Connection extends EventEmitter {
const resetCmd = new Reset(
cmdParam,
() => {
conn.prepareCache.reset();
let prom = Promise.resolve();
// re-execute init query / session query timeout
prom
Expand Down
4 changes: 4 additions & 0 deletions lib/lru-prepare-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class LruPrepareCache {
if (keyStr.length > 1) keyStr = keyStr.substring(0, keyStr.length - 1);
return 'info{cache:' + keyStr + '}';
}

reset() {
this.#lruCache.clear();
}
}

module.exports = LruPrepareCache;
6 changes: 1 addition & 5 deletions lib/pool-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,12 @@ class PoolPromise extends EventEmitter {
if (this.#pool.opts.connOptions.trace) Error.captureStackTrace(cmdParam);
const baseConn = await this.#pool.getConnection(cmdParam);
const conn = new ConnectionPromise(baseConn);
conn.release = this.#releaseConnection.bind(this, baseConn);
conn.release = () => new Promise(baseConn.release);
conn.end = conn.release;
conn.close = conn.release;
return conn;
}

#releaseConnection(baseConn) {
return new Promise(baseConn.release);
}

/**
* Execute query using text protocol with callback emit columns/data/end/error
* events to permit streaming big result-set
Expand Down
1 change: 0 additions & 1 deletion lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class Pool extends EventEmitter {

this.on('_idle', this._requestsHandler);
this.on('validateSize', this._sizeHandler);

this._sizeHandler();
}

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": "3.1.0",
"version": "3.1.1",
"description": "fast mariadb or mysql connector.",
"main": "promise.js",
"types": "types/index.d.ts",
Expand Down
5 changes: 4 additions & 1 deletion promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ module.exports.createConnection = function createConnection(opts) {

module.exports.createPool = function createPool(opts) {
const options = new PoolOptions(opts);
return new PoolPromise(options);
const pool = new PoolPromise(options);
// adding a default error handler to avoid exiting application on connection error.
pool.on('error', (err) => {});
return pool;
};

module.exports.createPoolCluster = function createPoolCluster(opts) {
Expand Down
5 changes: 0 additions & 5 deletions test/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ before('share initialization', async () => {
// retry
global.shareConn = await basePromise.createConnection(Conf.baseConfig);
}

// https://jira.mariadb.org/browse/XPT-266
if (isXpandFct()) {
global.shareConn.query('SET NAMES UTF8');
}
}
});

Expand Down
5 changes: 3 additions & 2 deletions test/integration/datatype/test-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ describe('time', () => {
await shareConn.query('INSERT INTO time_data VALUES (?, ?)', ['-1:00:00', '25:00:00']);
let results = await shareConn.query('SELECT * FROM time_data');
assert.equal(results[0].t1, '-838:59:58.000000');
assert.equal(results[0].t2, '-838:59:59.999999');

assert.equal(results[0].t2, isXpand() ? '-838:59:59.000000' : '-838:59:59.999999');
assert.equal(results[1].t1, '-01:00:00.000000');
assert.equal(results[1].t2, '25:00:00.000000');
results = await shareConn.execute('SELECT * FROM time_data');
assert.equal(results[0].t1, '-838:59:58');
assert.equal(results[0].t2, '-838:59:59.999999');
assert.equal(results[0].t2, isXpand() ? '-838:59:59' : '-838:59:59.999999');
assert.equal(results[1].t1, '-01:00:00');
assert.equal(results[1].t2, '25:00:00');
});
Expand Down
Loading

0 comments on commit c00e0f1

Please sign in to comment.