Skip to content

Commit 36373d5

Browse files
committed
Merge branch 'release/2.5.2'
2 parents 14977f5 + a22c211 commit 36373d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3894
-4594
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ install:
1919
# generate SSL certificates
2020
- mkdir tmp
2121
- chmod +x .travis/gen-ssl.sh
22+
- chmod +x .travis/sql/*
2223
- chmod +x .travis/build/build.sh
2324
- chmod +x .travis/build/docker-entrypoint.sh
2425
- chmod 777 .travis/build/
@@ -46,6 +47,8 @@ matrix:
4647
env: DB=build SKIP_LEAK=1
4748
- node_js: "12"
4849
env: SKYSQL=true SKIP_LEAK=1
50+
- node_js: "12"
51+
env: SKYSQL_HA=true MAXSCALE_TEST_DISABLE=true SKIP_LEAK=1
4952
- node_js: "10"
5053
env: DB=mariadb:10.5
5154
- node_js: "12"

.travis/script.sh

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,33 @@ set -e
66
###################################################################################################################
77
# test different type of configuration
88
###################################################################################################################
9-
10-
if [ -n "$SKYSQL" ] ; then
11-
12-
if [ -z "$SKYSQL_HOST" ] ; then
13-
echo "No SkySQL configuration found !"
14-
exit 0
9+
if [ -n "$SKYSQL" ] || [ -n "$SKYSQL_HA" ]; then
10+
if [ -n "$SKYSQL" ] ; then
11+
if [ -z "$SKYSQL_HOST" ] ; then
12+
echo "No SkySQL configuration found !"
13+
exit 0
14+
else
15+
export TEST_USER=$SKYSQL_USER
16+
export TEST_HOST=$SKYSQL_HOST
17+
export TEST_PASSWORD=$SKYSQL_PASSWORD
18+
export TEST_PORT=$SKYSQL_PORT
19+
export TEST_SSL_CA=$SKYSQL_SSL_CA
20+
fi
1521
else
16-
export TEST_USER=$SKYSQL_USER
17-
export TEST_HOST=$SKYSQL_HOST
18-
export TEST_PASSWORD=$SKYSQL_PASSWORD
19-
export TEST_PORT=$SKYSQL_PORT
20-
export TEST_SSL_CA=$SKYSQL_SSL_CA
21-
export TEST_BULK=false
22+
if [ -z "$SKYSQL_HA_HOST" ] ; then
23+
echo "No SkySQL configuration found !"
24+
exit 0
25+
else
26+
export TEST_USER=$SKYSQL_HA_USER
27+
export TEST_HOST=$SKYSQL_HA_HOST
28+
export TEST_PASSWORD=$SKYSQL_HA_PASSWORD
29+
export TEST_PORT=$SKYSQL_HA_PORT
30+
export TEST_SSL_CA=$SKYSQL_HA_SSL_CA
31+
fi
2232
fi
2333

2434
else
25-
export TEST_USER=boby
26-
export TEST_PASSWORD=heyPassw0@rd
35+
export TEST_USER=bob
2736
export TEST_HOST=mariadb.example.com
2837
export COMPOSE_FILE=.travis/docker-compose.yml
2938
export ENTRYPOINT=$PROJ_PATH/.travis/sql
@@ -42,6 +51,8 @@ else
4251
docker-compose -f ${COMPOSE_FILE} build
4352
export TEST_PORT=4006
4453
export TEST_SSL_PORT=4009
54+
export TEST_USER=boby
55+
export TEST_PASSWORD=heyPassw0@rd
4556
fi
4657

4758
docker-compose -f ${COMPOSE_FILE} up -d

.travis/sql/dbinit.sql

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
CREATE USER 'bob'@'localhost';
2-
GRANT ALL ON *.* TO 'bob'@'localhost' with grant option;
3-
41
CREATE USER 'bob'@'%';
52
GRANT ALL ON *.* TO 'bob'@'%' with grant option;
63

7-
CREATE USER 'boby'@'%' identified by 'heyPassw0@rd';
8-
GRANT ALL ON *.* TO 'boby'@'%' with grant option;
9-
10-
CREATE USER 'boby'@'localhost' identified by 'heyPassw0@rd';
11-
GRANT ALL ON *.* TO 'boby'@'localhost' with grant option;
4+
/*M!100501 CREATE USER 'boby'@'%' identified by 'heyPassw0@rd'*/;
5+
/*M!100501 GRANT ALL ON *.* TO 'boby'@'%' with grant option*/;
126

137
FLUSH PRIVILEGES;
148

CHANGELOG.md

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

3+
4+
## [2.5.2](https://github.com/mariadb-corporation/mariadb-connector-nodejs/tree/2.5.2) (04 Dec 2020)
5+
[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-nodejs/compare/2.5.1...2.5.2)
6+
7+
* [CONJS-151] bulk batch error (parameter truncation) #137
8+
* [CONJS-152] correction when enabling the `permitLocalInfile` option and some initial commands
9+
* [CONJS-154] Timezone support correction and clarification
10+
* [CONJS-155] correction to support for node.js 10.13 to 10.19
11+
* [CONJS-156] Ensure setting capability PLUGIN_AUTH only if server has it
12+
13+
documentation improvement
14+
315
## [2.5.1](https://github.com/mariadb-corporation/mariadb-connector-nodejs/tree/2.5.1) (23 Oct 2020)
416
[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-nodejs/compare/2.5.0...2.5.1)
517

documentation/callback-api.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,44 @@ This initializes the constant `mariadb`, which is set to use the Callback API ra
4646

4747
## Timezone consideration
4848

49-
It's not recommended, but in some cases, Node.js and database are configured with different timezone.
49+
Client and database can have a different timezone.
5050

51-
By default, `timezone` option is set to 'local' value, indicating to use client timezone, so no conversion will be done.
51+
The connector has different solutions when this is the case.
52+
the `timezone` option can have the following value:
53+
* 'local' (default) : connector doesn't do any conversion. If the database has a different timezone, there will be an offset issue.
54+
* 'auto' : connector retrieve server timezone. Dates will be converted if server timezone differs from client
55+
* IANA timezone / offset, example 'America/New_York' or '+06:00'.
5256

53-
If client and server timezone differ, `timezone` option has to be set to server timezone.
54-
- 'auto' value means client will request server timezone when creating a connection, and use server timezone afterwhile.
55-
- To avoid this additional command on connection, `timezone` can be set to [IANA time zone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
57+
##### IANA timezone / offset
5658

57-
Connector will then convert date to server timezone, rather than the current Node.js timezone.
59+
When using IANA timezone, the connector will set the connection timezone to the timezone.
60+
this can throw an error on connection if timezone is unknown by the server (see [mariadb timezone documentation](https://mariadb.com/kb/en/time-zones/), timezone tables might be not initialized)
61+
If you are sure the server is using that timezone, this step can be skipped with the option `skipSetTimezone`.
5862

63+
If timezone correspond to javascript default timezone, then no conversion will be done
64+
65+
##### Timezone setting recommendation.
66+
The best is to have the same timezone on client and database, then keep the 'local' default value.
67+
68+
If different, then either client or server has to convert date.
69+
In general, that is best to use client conversion, to avoid putting any unneeded stress on the database.
70+
timezone has to be set to the IANA timezone corresponding to server timezone and disabled `skipSetTimezone` option since you are sure that the server has the corresponding timezone.
71+
72+
example: client use 'America/New_York' by default, and server 'America/Los_Angeles'.
73+
execute 'SELECT @@system_time_zone' on the server. that will give the server default timezone.
74+
the server can return POSIX timezone like 'PDT' (Pacific Daylight Time).
75+
IANA timezone correspondence must be found : (see [IANA timezone List](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)) and configure client-side.
76+
This will ensure DST (automatic date saving time change will be handled)
77+
```js
78+
const mariadb = require('mariadb');
79+
const conn = mariadb.createConnection({
80+
host: process.env.DB_HOST,
81+
user: process.env.DB_USER,
82+
password: process.env.DB_PWD,
83+
timezone: 'America/Los_Angeles',
84+
skipSetTimezone: true
85+
});
86+
```
5987

6088
## Security consideration
6189

documentation/developers-guide.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,22 @@ Before submitting a pull request to the project, run local and continuous integr
1717

1818
The repository contains a series of tests to evaluate the Connector and to make sure it can connect to and operate on MariaDB with the new code. Run local tests using npm.
1919

20-
In order for these tests to pass, you need to have a MariaDB or MySQL server installed, which by default it assumes is running at localhost:3306 with a database named `testn` and a user `root` without a password. Once this is set up, you can run the tests with npm:
20+
In order for these tests to pass, you need to have a MariaDB or MySQL server installed, which by default it assumes is running at localhost:3306 with a database named `testn` and a user `root` without a password.
21+
Alternatively you will need to create a user [with grant privilege](https://mariadb.com/kb/en/grant/#the-grant-option-privilege).
22+
Example, with `root` user create the new user and grant privileges:
23+
```
24+
MariaDB [(none)]> create user anel@localhost identified by ('testpass');
25+
MariaDB [(none)]> grant all privileges on *.* to anel@localhost WITH GRANT OPTION;
26+
```
27+
Once this is set up, you can run the tests with npm:
2128

2229
```
2330
$ npm run test:base
2431
```
25-
32+
Or via environment variables with specific user:
33+
```
34+
$ TEST_DB=testn TEST_USER=anel TEST_PASSWORD=testpass TEST_PORT=3306 TEST_HOST=localhost npm run test:base
35+
```
2636
The tests retrieve the host, password, database and port number from environmental variables, which you can manually set if you want to connect to MariaDB in other ways.
2737

2838
* `TEST_HOST` Hostname. By default, localhost.

documentation/promise-api.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,47 @@ const mariadb = require('mariadb');
5454

5555
### Timezone consideration
5656

57-
It's not recommended, but in some cases, Node.js and database are configured with different timezone.
57+
Client and database can have a different timezone.
5858

59-
By default, `timezone` option is set to 'local' value, indicating to use client timezone, so no conversion will be done.
59+
The connector has different solutions when this is the case.
60+
the `timezone` option can have the following value:
61+
* 'local' (default) : connector doesn't do any conversion. If the database has a different timezone, there will be an offset issue.
62+
* 'auto' : connector retrieve server timezone. Dates will be converted if server timezone differs from client
63+
* IANA timezone / offset, example 'America/New_York' or '+06:00'.
6064

61-
If client and server timezone differ, `timezone` option has to be set to server timezone.
62-
- 'auto' value means client will request server timezone when creating a connection, and use server timezone afterwhile.
63-
- To avoid this additional command on connection, `timezone` can be set to [IANA time zone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
65+
##### IANA timezone / offset
6466

65-
Connector will then convert date to server timezone, rather than the current Node.js timezone.
67+
When using IANA timezone, the connector will set the connection timezone to the timezone.
68+
this can throw an error on connection if timezone is unknown by the server (see [mariadb timezone documentation](https://mariadb.com/kb/en/time-zones/), timezone tables might be not initialized)
69+
If you are sure the server is using that timezone, this step can be skipped with the option `skipSetTimezone`.
6670

71+
If timezone correspond to javascript default timezone, then no conversion will be done
6772

73+
##### Timezone setting recommendation.
74+
The best is to have the same timezone on client and database, then keep the 'local' default value.
75+
76+
If different, then either client or server has to convert date.
77+
In general, that is best to use client conversion, to avoid putting any unneeded stress on the database.
78+
timezone has to be set to the IANA timezone corresponding to server timezone and disabled `skipSetTimezone` option since you are sure that the server has the corresponding timezone.
79+
80+
example: client use 'America/New_York' by default, and server 'America/Los_Angeles'.
81+
execute 'SELECT @@system_time_zone' on the server. that will give the server default timezone.
82+
the server can return POSIX timezone like 'PDT' (Pacific Daylight Time).
83+
IANA timezone correspondence must be found : (see [IANA timezone List](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)) and configure client-side.
84+
This will ensure DST (automatic date saving time change will be handled)
85+
86+
```js
87+
const mariadb = require('mariadb');
88+
const conn = mariadb.createConnection({
89+
host: process.env.DB_HOST,
90+
user: process.env.DB_USER,
91+
password: process.env.DB_PWD,
92+
timezone: 'America/Los_Angeles',
93+
skipSetTimezone: true
94+
});
95+
```
96+
97+
6898
### Security consideration
6999

70100
Connection details such as URL, username, and password are better hidden into environment variables.

lib/cmd/change-user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ChangeUser extends Handshake {
6060
out.writeInt8(0);
6161
}
6262

63-
if (this.opts.connectAttributes && info.serverCapabilities & Capabilities.CONNECT_ATTRS) {
63+
if (info.clientCapabilities & Capabilities.CONNECT_ATTRS) {
6464
out.writeInt8(0xfc);
6565
let initPos = out.pos; //save position, assuming connection attributes length will be less than 2 bytes length
6666
out.writeInt16(0);

lib/cmd/common-text-cmd.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const ResultSet = require('./resultset');
44
const FieldDetail = require('../const/field-detail');
55
const FieldType = require('../const/field-type');
66
const Long = require('long');
7+
const moment = require('moment-timezone');
78
const QUOTE = 0x27;
89

910
class CommonText extends ResultSet {
@@ -12,7 +13,11 @@ class CommonText extends ResultSet {
1213
this.configAssign(connOpts, cmdOpts);
1314
this.sql = sql;
1415
this.initialValues = values;
15-
this.getDateQuote = this.opts.tz ? CommonText.getTimezoneDate : CommonText.getLocalDate;
16+
this.getDateQuote = this.opts.tz
17+
? this.opts.tz === 'Etc/UTC'
18+
? CommonText.getUtcDate
19+
: CommonText.getTimezoneDate
20+
: CommonText.getLocalDate;
1621
}
1722

1823
/**
@@ -398,13 +403,25 @@ function getLocalDate(date, opts) {
398403
return getDatePartQuote(year, mon, day, hour, min, sec, ms);
399404
}
400405

406+
function getUtcDate(date, opts) {
407+
const year = date.getUTCFullYear();
408+
const mon = date.getUTCMonth() + 1;
409+
const day = date.getUTCDate();
410+
const hour = date.getUTCHours();
411+
const min = date.getUTCMinutes();
412+
const sec = date.getUTCSeconds();
413+
const ms = date.getUTCMilliseconds();
414+
return getDatePartQuote(year, mon, day, hour, min, sec, ms);
415+
}
416+
401417
function getTimezoneDate(date, opts) {
402418
if (date.getMilliseconds() != 0) {
403-
return opts.tz(date).format("'YYYY-MM-DD HH:mm:ss.SSS'");
419+
return moment.tz(date, opts.tz).format("'YYYY-MM-DD HH:mm:ss.SSS'");
404420
}
405-
return opts.tz(date).format("'YYYY-MM-DD HH:mm:ss'");
421+
return moment.tz(date, opts.tz).format("'YYYY-MM-DD HH:mm:ss'");
406422
}
407423

408424
module.exports = CommonText;
409425
module.exports.getTimezoneDate = getTimezoneDate;
426+
module.exports.getUtcDate = getUtcDate;
410427
module.exports.getLocalDate = getLocalDate;

lib/cmd/handshake/client-capabilities.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ module.exports.init = function (opts, info) {
1717
Capabilities.MULTI_RESULTS |
1818
Capabilities.PS_MULTI_RESULTS |
1919
Capabilities.SESSION_TRACK |
20-
Capabilities.PLUGIN_AUTH |
2120
Capabilities.PLUGIN_AUTH_LENENC_CLIENT_DATA;
2221

2322
if ((info.serverCapabilities & Capabilities.MYSQL) === 0n) {
2423
capabilities |= Capabilities.MARIADB_CLIENT_EXTENDED_TYPE_INFO;
2524
}
2625

27-
if (opts.connectAttributes) {
26+
if (info.serverCapabilities & Capabilities.PLUGIN_AUTH) {
27+
capabilities |= Capabilities.PLUGIN_AUTH;
28+
}
29+
30+
if (opts.connectAttributes && info.serverCapabilities & Capabilities.CONNECT_ATTRS) {
2831
capabilities |= Capabilities.CONNECT_ATTRS;
2932
}
3033

@@ -45,7 +48,7 @@ module.exports.init = function (opts, info) {
4548
capabilities |= Capabilities.DEPRECATE_EOF;
4649
}
4750

48-
if (opts.database) {
51+
if (opts.database && info.serverCapabilities & Capabilities.CONNECT_WITH_DB) {
4952
capabilities |= Capabilities.CONNECT_WITH_DB;
5053
}
5154

0 commit comments

Comments
 (0)