Skip to content

Commit 95af20f

Browse files
authored
Merge pull request #1338 from dhensby/pulls/6/fix-config-inheritance
Request should use this.parent not this.connection
2 parents 0de3e65 + 5c4ccc0 commit 95af20f

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

CHANGELOG.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
v6.4.0 (2021-11-18)
2+
-------------------
3+
[new] Transaction/PreparedStatements expose the config from their parent connection
4+
[fix] Fix inherited request configs from the pool. Specifically stream and arrayRowMode now inherit accurately from the connection config ([#1338](https://github.com/tediousjs/node-mssql/pull/1338))
5+
16
v6.3.2 (2021-05-13)
27
-------------------
38
[fix] Bump various dependencies for security fixes

lib/base/prepared-statement.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class PreparedStatement extends EventEmitter {
3535
this.parameters = {}
3636
}
3737

38+
get config () {
39+
return this.parent.config
40+
}
41+
3842
get connected () {
3943
return this.parent.connected
4044
}

lib/base/request.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Request extends EventEmitter {
2525
/**
2626
* Create new Request.
2727
*
28-
* @param {Connection|ConnectionPool|Transaction|PreparedStatement} parent If ommited, global connection is used instead.
28+
* @param {Connection|ConnectionPool|Transaction|PreparedStatement} parent If omitted, global connection is used instead.
2929
*/
3030

3131
constructor (parent) {
@@ -38,6 +38,8 @@ class Request extends EventEmitter {
3838
this._paused = false
3939
this.parent = parent || globalConnection.pool
4040
this.parameters = {}
41+
this.stream = null
42+
this.arrayRowMode = null
4143
}
4244

4345
get paused () {
@@ -223,8 +225,8 @@ class Request extends EventEmitter {
223225
*/
224226

225227
batch (batch, callback) {
226-
if (this.stream == null && this.connection) this.stream = this.connection.config.stream
227-
if (this.arrayRowMode == null && this.connection) this.arrayRowMode = this.connection.config.arrayRowMode
228+
if (this.stream === null && this.parent) this.stream = this.parent.config.stream
229+
if (this.arrayRowMode === null && this.parent) this.arrayRowMode = this.parent.config.arrayRowMode
228230
this.rowsAffected = 0
229231

230232
if (typeof callback === 'function') {
@@ -287,11 +289,11 @@ class Request extends EventEmitter {
287289
*/
288290

289291
_batch (batch, callback) {
290-
if (!this.connection) {
292+
if (!this.parent) {
291293
return setImmediate(callback, new RequestError('No connection is specified for that request.', 'ENOCONN'))
292294
}
293295

294-
if (!this.connection.connected) {
296+
if (!this.parent.connected) {
295297
return setImmediate(callback, new ConnectionError('Connection is closed.', 'ECONNCLOSED'))
296298
}
297299

@@ -316,8 +318,8 @@ class Request extends EventEmitter {
316318
options = {}
317319
}
318320

319-
if (this.stream == null && this.connection) this.stream = this.connection.config.stream
320-
if (this.arrayRowMode == null && this.connection) this.arrayRowMode = this.connection.config.arrayRowMode
321+
if (this.stream === null && this.parent) this.stream = this.parent.config.stream
322+
if (this.arrayRowMode === null && this.parent) this.arrayRowMode = this.parent.config.arrayRowMode
321323

322324
if (this.stream || typeof callback === 'function') {
323325
this._bulk(table, options, (err, rowsAffected) => {
@@ -393,8 +395,8 @@ class Request extends EventEmitter {
393395
*/
394396

395397
query (command, callback) {
396-
if (this.stream == null && this.connection) this.stream = this.connection.config.stream
397-
if (this.arrayRowMode == null && this.connection) this.arrayRowMode = this.connection.config.arrayRowMode
398+
if (this.stream === null && this.parent) this.stream = this.parent.config.stream
399+
if (this.arrayRowMode === null && this.parent) this.arrayRowMode = this.parent.config.arrayRowMode
398400
this.rowsAffected = 0
399401

400402
if (typeof callback === 'function') {
@@ -482,8 +484,8 @@ class Request extends EventEmitter {
482484
*/
483485

484486
execute (command, callback) {
485-
if (this.stream == null && this.connection) this.stream = this.connection.config.stream
486-
if (this.arrayRowMode == null && this.connection) this.arrayRowMode = this.connection.config.arrayRowMode
487+
if (this.stream === null && this.parent) this.stream = this.parent.config.stream
488+
if (this.arrayRowMode === null && this.parent) this.arrayRowMode = this.parent.config.arrayRowMode
487489
this.rowsAffected = 0
488490

489491
if (typeof callback === 'function') {

lib/base/transaction.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class Transaction extends EventEmitter {
3737
this.name = ''
3838
}
3939

40+
get config () {
41+
return this.parent.config
42+
}
43+
4044
get connected () {
4145
return this.parent.connected
4246
}

0 commit comments

Comments
 (0)