Skip to content

Commit dc04c61

Browse files
committed
Adds ability to change client connection flags
Example: ```js mysql.createConnection("mysql://.../db?flags=-found_rows,plugin_auth"); ``` (blacklists FOUND_ROWS, adds PLUGIN_AUTH)
1 parent f0ad1b9 commit dc04c61

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

lib/ConnectionConfig.js

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function ConnectionConfig(options) {
1717
this.insecureAuth = options.insecureAuth || false;
1818
this.debug = options.debug;
1919
this.timezone = options.timezone || 'local';
20+
this.flags = options.flags || '';
2021
this.typeCast = (options.typeCast === undefined)
2122
? true
2223
: options.typeCast;
@@ -32,23 +33,37 @@ function ConnectionConfig(options) {
3233
? ConnectionConfig.getCharsetNumber(options.charset)
3334
: Charsets.UTF8_GENERAL_CI;
3435

35-
this.clientFlags =
36-
ClientConstants.CLIENT_LONG_PASSWORD |
37-
ClientConstants.CLIENT_FOUND_ROWS |
38-
ClientConstants.CLIENT_LONG_FLAG |
39-
ClientConstants.CLIENT_CONNECT_WITH_DB |
40-
ClientConstants.CLIENT_ODBC |
41-
ClientConstants.CLIENT_LOCAL_FILES |
42-
ClientConstants.CLIENT_IGNORE_SPACE |
43-
ClientConstants.CLIENT_PROTOCOL_41 |
44-
ClientConstants.CLIENT_IGNORE_SIGPIPE |
45-
ClientConstants.CLIENT_TRANSACTIONS |
46-
ClientConstants.CLIENT_RESERVED |
47-
ClientConstants.CLIENT_SECURE_CONNECTION |
48-
ClientConstants.CLIENT_MULTI_RESULTS;
49-
36+
this.defaultFlags = [ "LONG_PASSWORD", "FOUND_ROWS", "LONG_FLAG",
37+
"CONNECT_WITH_DB", "ODBC", "LOCAL_FILES",
38+
"IGNORE_SPACE", "PROTOCOL_41", "IGNORE_SIGPIPE",
39+
"TRANSACTIONS", "RESERVED", "SECURE_CONNECTION",
40+
"MULTI_RESULTS" ];
5041
if (options.multipleStatements) {
51-
this.clientFlags |= ClientConstants.CLIENT_MULTI_STATEMENTS;
42+
this.defaultFlags.push("MULTI_STATEMENTS");
43+
}
44+
45+
var i;
46+
47+
if (this.flags.length > 0) {
48+
this.flags = this.flags.toUpperCase().split(',');
49+
} else {
50+
this.flags = [];
51+
}
52+
53+
this.clientFlags = 0x0;
54+
55+
// add default flags unless "blacklisted"
56+
for (i in this.defaultFlags) {
57+
if (this.flags.indexOf("-" + this.defaultFlags[i]) >= 0) continue;
58+
59+
this.clientFlags |= ClientConstants["CLIENT_" + this.defaultFlags[i]] || 0x0;
60+
}
61+
// add user flags unless already already added
62+
for (i in this.flags) {
63+
if (this.flags[i][0] == "-") continue;
64+
if (this.defaultFlags.indexOf(this.flags[i]) >= 0) continue;
65+
66+
this.clientFlags |= ClientConstants["CLIENT_" + this.flags[i]] || 0x0;
5267
}
5368
}
5469

0 commit comments

Comments
 (0)