Skip to content

Commit

Permalink
Merge branch 'release/3.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed May 2, 2023
2 parents c00e0f1 + 238500b commit 193a13d
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 40 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log

## [3.1.2](https://github.com/mariadb-corporation/mariadb-connector-nodejs/tree/3.1.2) (May 2023)
[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-nodejs/compare/3.1.1...3.1.2)

## Notable changes
* CONJS-249 add connection.listeners function to permit TypeORM compatibility

## Issues Fixed
* CONJS-247 Improve error message when having set named parameter option and executing standard question mark command
* CONJS-248 Ensuring not using importing file after pool.end()

## [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)

Expand Down
9 changes: 6 additions & 3 deletions lib/cmd/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,13 @@ class Execute extends Parser {
this.emit('send_end');
let errMsg = `Parameter at position ${i} is undefined`;
if (this.opts.namedPlaceholders && this.prepare._placeHolderIndex) {
errMsg = `Parameter named ${this.prepare._placeHolderIndex[i]} is not set`;
if (this.prepare._placeHolderIndex.length < this.prepare.parameterCount) {
errMsg = `Command expect ${this.prepare.parameterCount} parameters, but found only ${this.prepare._placeHolderIndex.length} named parameters. You probably use question mark in place of named parameters`;
} else {
errMsg = `Parameter named ${this.prepare._placeHolderIndex[i]} is not set`;
}
}

this.throwNewError(errMsg + '\nsql: ' + this.displaySql(), false, info, 'HY000', Errors.ER_PARAMETER_UNDEFINED);
this.throwNewError(errMsg, false, info, 'HY000', Errors.ER_PARAMETER_UNDEFINED);
return false;
}

Expand Down
52 changes: 17 additions & 35 deletions lib/cmd/handshake/handshake.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ const Errors = require('../../misc/errors');
const Capabilities = require('../../const/capabilities');
const Collations = require('../../const/collations');

const authenticationPlugins = {
mysql_native_password: require('./auth/native-password-auth.js'),
mysql_clear_password: require('./auth/clear-password-auth'),
client_ed25519: require('./auth/ed25519-password-auth'),
dialog: require('./auth/pam-password-auth'),
sha256_password: require('./auth/sha256-password-auth'),
caching_sha2_password: require('./auth/caching-sha2-password-auth')
};

/**
* Handle handshake.
* see https://mariadb.com/kb/en/library/1-connecting-connecting/
Expand Down Expand Up @@ -199,41 +208,14 @@ class Handshake extends Command {
authReject,
multiAuthResolver
) {
let pluginAuth;
switch (pluginName) {
case 'mysql_native_password':
pluginAuth = require('./auth/native-password-auth.js');
break;

case 'mysql_clear_password':
pluginAuth = require('./auth/clear-password-auth.js');
break;

case 'client_ed25519':
pluginAuth = require('./auth/ed25519-password-auth.js');
break;

case 'dialog':
pluginAuth = require('./auth/pam-password-auth.js');
break;

case 'sha256_password':
pluginAuth = require('./auth/sha256-password-auth.js');
break;

case 'caching_sha2_password':
pluginAuth = require('./auth/caching-sha2-password-auth.js');
break;

//TODO "auth_gssapi_client"

default:
throw Errors.createFatalError(
`Client does not support authentication protocol '${pluginName}' requested by server.`,
Errors.ER_AUTHENTICATION_PLUGIN_NOT_SUPPORTED,
info,
'08004'
);
let pluginAuth = authenticationPlugins[pluginName];
if (!pluginAuth) {
throw Errors.createFatalError(
`Client does not support authentication protocol '${pluginName}' requested by server.`,
Errors.ER_AUTHENTICATION_PLUGIN_NOT_SUPPORTED,
info,
'08004'
);
}
return new pluginAuth(packSeq, compressPackSeq, pluginData, cmdParam, authResolve, authReject, multiAuthResolver);
}
Expand Down
1 change: 1 addition & 0 deletions lib/connection-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ConnectionCallback {
this.#conn = conn;
this.on = this.#conn.on.bind(this.#conn);
this.once = this.#conn.once.bind(this.#conn);
this.listeners = this.#conn.listeners.bind(this.#conn);
}

get threadId() {
Expand Down
1 change: 1 addition & 0 deletions lib/connection-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ConnectionPromise {
this.#conn = conn;
this.on = this.#conn.on.bind(this.#conn);
this.once = this.#conn.once.bind(this.#conn);
this.listeners = this.#conn.listeners.bind(this.#conn);
}

get threadId() {
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.1",
"version": "3.1.2",
"description": "fast mariadb or mysql connector.",
"main": "promise.js",
"types": "types/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions test/integration/test-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ describe('connection', () => {
base
.createConnection()
.then((conn) => {
assert.equal(0, conn.listeners('error').length);
conn.on('error', (err) => {
done();
});
Expand Down Expand Up @@ -291,6 +292,7 @@ describe('connection', () => {
it('connection.ping() with callback', function (done) {
const conn = base.createCallbackConnection();
conn.connect((err) => {
assert.equal(0, conn.listeners('error').length);
conn.ping();
conn.ping((err) => {
if (err) {
Expand Down
18 changes: 18 additions & 0 deletions test/integration/test-placholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ describe('Placeholder', () => {
conn.end();
});

it('execute without placeholder', async function () {
const conn = await base.createConnection({ namedPlaceholders: true });
try {
const rows = await conn.execute('select ? as val1, ? as val3, ? as val2', ['30', '10', '20']);
} catch (err) {
assert.equal(45017, err.errno);
assert.equal('HY000', err.sqlState);
assert(!err.fatal);
assert(
err.message.includes(
'Command expect 3 parameters, but found only 0 named parameters. You probably use question mark in place of named parameters\n' +
"sql: select ? as val1, ? as val3, ? as val2 - parameters:{'0':'30','1':'10','2':'20'}"
)
);
}
conn.end();
});

it('query placeholder using option', async function () {
const rows = await shareConn.query(
{
Expand Down
2 changes: 2 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ export interface Connection {

on(ev: 'end', callback: () => void): Connection;
on(ev: 'error', callback: (err: SqlError) => void): Connection;
listeners(ev: 'end'): (() => void)[];
listeners(ev: 'error'): ((err: SqlError) => void)[];
}

export interface PoolConnection extends Connection {
Expand Down
4 changes: 3 additions & 1 deletion types/mariadb-tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mariadb = require('..');
import { Connection, FieldInfo, ConnectionConfig, PoolConfig, UpsertResult } from '..';
import { Connection, FieldInfo, ConnectionConfig, PoolConfig, UpsertResult, SqlError } from '..';
import { Stream } from 'stream';

// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down Expand Up @@ -166,6 +166,8 @@ async function testMisc(): Promise<void> {
.on('end', () => {
console.log(currRow + ' ' + metaReceived);
});
connection.listeners('end')[0]();
connection.listeners('error')[0](new SqlError('ddd'));

await connection.ping();

Expand Down

0 comments on commit 193a13d

Please sign in to comment.