diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 0247e3a8..dce009ee 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,7 @@ +v8.1.4 (2022-08-??) +------------------- +[fix] fix regression in requestTimout option not accepting `0` as a value ([#1421](https://github.com/tediousjs/node-mssql/pull/1421)) + v8.1.3 (2022-08-08) ------------------- [fix] requestTimeout correctly resolved ([#1398](https://github.com/tediousjs/node-mssql/pull/1398)) diff --git a/lib/msnodesqlv8/connection-pool.js b/lib/msnodesqlv8/connection-pool.js index 497a2e0e..78de9e18 100644 --- a/lib/msnodesqlv8/connection-pool.js +++ b/lib/msnodesqlv8/connection-pool.js @@ -12,6 +12,14 @@ const CONNECTION_DRIVER = ['darwin', 'linux'].includes(platform()) ? 'ODBC Drive const CONNECTION_STRING_PORT = `Driver=${CONNECTION_DRIVER};Server=#{server},#{port};Database=#{database};Uid=#{user};Pwd=#{password};Trusted_Connection=#{trusted};Encrypt=#{encrypt};` const CONNECTION_STRING_NAMED_INSTANCE = `Driver=${CONNECTION_DRIVER};Server=#{server}\\#{instance};Database=#{database};Uid=#{user};Pwd=#{password};Trusted_Connection=#{trusted};Encrypt=#{encrypt};` +function firstDefined () { + for (let i = 0; i < arguments.length; i++) { + if (typeof arguments[i] !== 'undefined') { + return arguments[i] + } + } +} + class ConnectionPool extends BaseConnectionPool { _poolCreate () { return new shared.Promise((resolve, reject) => { @@ -21,11 +29,11 @@ class ConnectionPool extends BaseConnectionPool { defaultConnectionString = CONNECTION_STRING_NAMED_INSTANCE } - this.config.requestTimeout = this.config.requestTimeout || this.config.timeout || 15000 + this.config.requestTimeout = firstDefined(this.config.requestTimeout, this.config.timeout, 15000) const cfg = { conn_str: this.config.connectionString || defaultConnectionString, - conn_timeout: (this.config.connectionTimeout || this.config.timeout || 15000) / 1000 + conn_timeout: firstDefined(this.config.connectionTimeout, this.config.timeout, 15000) / 1000 } cfg.conn_str = cfg.conn_str.replace(/#{([^}]*)}/g, (p) => { diff --git a/lib/tedious/connection-pool.js b/lib/tedious/connection-pool.js index 17c0d3a9..ab2431e2 100644 --- a/lib/tedious/connection-pool.js +++ b/lib/tedious/connection-pool.js @@ -7,6 +7,14 @@ const { IDS } = require('../utils') const shared = require('../shared') const ConnectionError = require('../error/connection-error') +function firstDefined () { + for (let i = 0; i < arguments.length; i++) { + if (typeof arguments[i] !== 'undefined') { + return arguments[i] + } + } +} + class ConnectionPool extends BaseConnectionPool { _poolCreate () { return new shared.Promise((resolve, reject) => { @@ -36,8 +44,8 @@ class ConnectionPool extends BaseConnectionPool { cfg.options.database = cfg.options.database || this.config.database cfg.options.port = cfg.options.port || this.config.port - cfg.options.connectTimeout = cfg.options.connectTimeout || this.config.connectionTimeout || this.config.timeout || 15000 - cfg.options.requestTimeout = cfg.options.requestTimeout || this.config.requestTimeout || this.config.timeout || 15000 + cfg.options.connectTimeout = firstDefined(cfg.options.connectTimeout, this.config.connectionTimeout, this.config.timeout, 15000) + cfg.options.requestTimeout = firstDefined(cfg.options.requestTimeout, this.config.requestTimeout, this.config.timeout, 15000) cfg.options.tdsVersion = cfg.options.tdsVersion || '7_4' cfg.options.rowCollectionOnDone = cfg.options.rowCollectionOnDone || false cfg.options.rowCollectionOnRequestCompletion = cfg.options.rowCollectionOnRequestCompletion || false