Skip to content

Commit 193a13d

Browse files
committed
Merge branch 'release/3.1.2'
2 parents c00e0f1 + 238500b commit 193a13d

File tree

10 files changed

+61
-40
lines changed

10 files changed

+61
-40
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Change Log
22

3+
## [3.1.2](https://github.com/mariadb-corporation/mariadb-connector-nodejs/tree/3.1.2) (May 2023)
4+
[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-nodejs/compare/3.1.1...3.1.2)
5+
6+
## Notable changes
7+
* CONJS-249 add connection.listeners function to permit TypeORM compatibility
8+
9+
## Issues Fixed
10+
* CONJS-247 Improve error message when having set named parameter option and executing standard question mark command
11+
* CONJS-248 Ensuring not using importing file after pool.end()
12+
313
## [3.1.1](https://github.com/mariadb-corporation/mariadb-connector-nodejs/tree/3.1.1) (Mar 2023)
414
[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-nodejs/compare/3.1.0...3.1.1)
515

lib/cmd/execute.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,13 @@ class Execute extends Parser {
102102
this.emit('send_end');
103103
let errMsg = `Parameter at position ${i} is undefined`;
104104
if (this.opts.namedPlaceholders && this.prepare._placeHolderIndex) {
105-
errMsg = `Parameter named ${this.prepare._placeHolderIndex[i]} is not set`;
105+
if (this.prepare._placeHolderIndex.length < this.prepare.parameterCount) {
106+
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`;
107+
} else {
108+
errMsg = `Parameter named ${this.prepare._placeHolderIndex[i]} is not set`;
109+
}
106110
}
107-
108-
this.throwNewError(errMsg + '\nsql: ' + this.displaySql(), false, info, 'HY000', Errors.ER_PARAMETER_UNDEFINED);
111+
this.throwNewError(errMsg, false, info, 'HY000', Errors.ER_PARAMETER_UNDEFINED);
109112
return false;
110113
}
111114

lib/cmd/handshake/handshake.js

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ const Errors = require('../../misc/errors');
99
const Capabilities = require('../../const/capabilities');
1010
const Collations = require('../../const/collations');
1111

12+
const authenticationPlugins = {
13+
mysql_native_password: require('./auth/native-password-auth.js'),
14+
mysql_clear_password: require('./auth/clear-password-auth'),
15+
client_ed25519: require('./auth/ed25519-password-auth'),
16+
dialog: require('./auth/pam-password-auth'),
17+
sha256_password: require('./auth/sha256-password-auth'),
18+
caching_sha2_password: require('./auth/caching-sha2-password-auth')
19+
};
20+
1221
/**
1322
* Handle handshake.
1423
* see https://mariadb.com/kb/en/library/1-connecting-connecting/
@@ -199,41 +208,14 @@ class Handshake extends Command {
199208
authReject,
200209
multiAuthResolver
201210
) {
202-
let pluginAuth;
203-
switch (pluginName) {
204-
case 'mysql_native_password':
205-
pluginAuth = require('./auth/native-password-auth.js');
206-
break;
207-
208-
case 'mysql_clear_password':
209-
pluginAuth = require('./auth/clear-password-auth.js');
210-
break;
211-
212-
case 'client_ed25519':
213-
pluginAuth = require('./auth/ed25519-password-auth.js');
214-
break;
215-
216-
case 'dialog':
217-
pluginAuth = require('./auth/pam-password-auth.js');
218-
break;
219-
220-
case 'sha256_password':
221-
pluginAuth = require('./auth/sha256-password-auth.js');
222-
break;
223-
224-
case 'caching_sha2_password':
225-
pluginAuth = require('./auth/caching-sha2-password-auth.js');
226-
break;
227-
228-
//TODO "auth_gssapi_client"
229-
230-
default:
231-
throw Errors.createFatalError(
232-
`Client does not support authentication protocol '${pluginName}' requested by server.`,
233-
Errors.ER_AUTHENTICATION_PLUGIN_NOT_SUPPORTED,
234-
info,
235-
'08004'
236-
);
211+
let pluginAuth = authenticationPlugins[pluginName];
212+
if (!pluginAuth) {
213+
throw Errors.createFatalError(
214+
`Client does not support authentication protocol '${pluginName}' requested by server.`,
215+
Errors.ER_AUTHENTICATION_PLUGIN_NOT_SUPPORTED,
216+
info,
217+
'08004'
218+
);
237219
}
238220
return new pluginAuth(packSeq, compressPackSeq, pluginData, cmdParam, authResolve, authReject, multiAuthResolver);
239221
}

lib/connection-callback.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ConnectionCallback {
1212
this.#conn = conn;
1313
this.on = this.#conn.on.bind(this.#conn);
1414
this.once = this.#conn.once.bind(this.#conn);
15+
this.listeners = this.#conn.listeners.bind(this.#conn);
1516
}
1617

1718
get threadId() {

lib/connection-promise.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class ConnectionPromise {
2121
this.#conn = conn;
2222
this.on = this.#conn.on.bind(this.#conn);
2323
this.once = this.#conn.once.bind(this.#conn);
24+
this.listeners = this.#conn.listeners.bind(this.#conn);
2425
}
2526

2627
get threadId() {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mariadb",
3-
"version": "3.1.1",
3+
"version": "3.1.2",
44
"description": "fast mariadb or mysql connector.",
55
"main": "promise.js",
66
"types": "types/index.d.ts",

test/integration/test-connection.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ describe('connection', () => {
192192
base
193193
.createConnection()
194194
.then((conn) => {
195+
assert.equal(0, conn.listeners('error').length);
195196
conn.on('error', (err) => {
196197
done();
197198
});
@@ -291,6 +292,7 @@ describe('connection', () => {
291292
it('connection.ping() with callback', function (done) {
292293
const conn = base.createCallbackConnection();
293294
conn.connect((err) => {
295+
assert.equal(0, conn.listeners('error').length);
294296
conn.ping();
295297
conn.ping((err) => {
296298
if (err) {

test/integration/test-placholders.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ describe('Placeholder', () => {
1616
conn.end();
1717
});
1818

19+
it('execute without placeholder', async function () {
20+
const conn = await base.createConnection({ namedPlaceholders: true });
21+
try {
22+
const rows = await conn.execute('select ? as val1, ? as val3, ? as val2', ['30', '10', '20']);
23+
} catch (err) {
24+
assert.equal(45017, err.errno);
25+
assert.equal('HY000', err.sqlState);
26+
assert(!err.fatal);
27+
assert(
28+
err.message.includes(
29+
'Command expect 3 parameters, but found only 0 named parameters. You probably use question mark in place of named parameters\n' +
30+
"sql: select ? as val1, ? as val3, ? as val2 - parameters:{'0':'30','1':'10','2':'20'}"
31+
)
32+
);
33+
}
34+
conn.end();
35+
});
36+
1937
it('query placeholder using option', async function () {
2038
const rows = await shareConn.query(
2139
{

types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,8 @@ export interface Connection {
690690

691691
on(ev: 'end', callback: () => void): Connection;
692692
on(ev: 'error', callback: (err: SqlError) => void): Connection;
693+
listeners(ev: 'end'): (() => void)[];
694+
listeners(ev: 'error'): ((err: SqlError) => void)[];
693695
}
694696

695697
export interface PoolConnection extends Connection {

types/mariadb-tests.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import mariadb = require('..');
2-
import { Connection, FieldInfo, ConnectionConfig, PoolConfig, UpsertResult } from '..';
2+
import { Connection, FieldInfo, ConnectionConfig, PoolConfig, UpsertResult, SqlError } from '..';
33
import { Stream } from 'stream';
44

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

170172
await connection.ping();
171173

0 commit comments

Comments
 (0)