mssql 12.7.7 → 12.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -934,6 +934,7 @@ __Errors__
934
934
  - ENOTOPEN (`ConnectionError`) - Connection not yet open.
935
935
  - ECONNCLOSED (`ConnectionError`) - Connection is closed.
936
936
  - ENOTBEGUN (`TransactionError`) - Transaction has not begun.
937
+ - EREQINPROG (`TransactionError`) - Can't acquire connection for the request. There is another request in progress.
937
938
  - EABORT (`TransactionError`) - Transaction was aborted (by user or because of an error).
938
939
 
939
940
  ---------------------------------------
@@ -1157,6 +1158,7 @@ __Errors__
1157
1158
  - ENOTOPEN (`ConnectionError`) - Connection not yet open.
1158
1159
  - ECONNCLOSED (`ConnectionError`) - Connection is closed.
1159
1160
  - ENOTBEGUN (`TransactionError`) - Transaction has not begun.
1161
+ - EREQINPROG (`TransactionError`) - Can't acquire connection for the request. There is another request in progress.
1160
1162
  - EABORT (`TransactionError`) - Transaction was aborted (by user or because of an error).
1161
1163
  - EINJECT (`RequestError`) - Parameter type is not a valid identifier. See [Identifiers](#identifiers).
1162
1164
 
@@ -1204,6 +1206,7 @@ __Errors__
1204
1206
  - ENOTOPEN (`ConnectionError`) - Connection not yet open.
1205
1207
  - ECONNCLOSED (`ConnectionError`) - Connection is closed.
1206
1208
  - ENOTBEGUN (`TransactionError`) - Transaction has not begun.
1209
+ - EREQINPROG (`TransactionError`) - Can't acquire connection for the request. There is another request in progress.
1207
1210
  - EABORT (`TransactionError`) - Transaction was aborted (by user or because of an error).
1208
1211
  - EINJECT (`RequestError`) - Parameter type is not a valid identifier. See [Identifiers](#identifiers).
1209
1212
 
@@ -1251,6 +1254,7 @@ __Errors__
1251
1254
  - ENOTOPEN (`ConnectionError`) - Connection not yet open.
1252
1255
  - ECONNCLOSED (`ConnectionError`) - Connection is closed.
1253
1256
  - ENOTBEGUN (`TransactionError`) - Transaction has not begun.
1257
+ - EREQINPROG (`TransactionError`) - Can't acquire connection for the request. There is another request in progress.
1254
1258
  - EABORT (`TransactionError`) - Transaction was aborted (by user or because of an error).
1255
1259
  - EINJECT (`RequestError`) - Column name or parameter type is not a valid identifier. See [Identifiers](#identifiers).
1256
1260
 
@@ -1378,7 +1382,9 @@ transaction.begin(err => {
1378
1382
  ```
1379
1383
 
1380
1384
  __Errors__
1385
+ - ENOCONN (`TransactionError`) - No connection is specified for that transaction.
1381
1386
  - ENOTOPEN (`ConnectionError`) - Connection not yet open.
1387
+ - ECONNCLOSED (`ConnectionError`) - Connection is closed.
1382
1388
  - EALREADYBEGUN (`TransactionError`) - Transaction has already begun.
1383
1389
 
1384
1390
  If the transaction fails to begin once it has a connection, the error is a `TransactionError`, with the error it comes from as its `originalError`. The connection goes back to the pool, and the transaction can be begun again. A connection that may have sent the request to begin the transaction is closed rather than lent out again, as the server may have begun the transaction even though the request failed (for example, when it timed out).
@@ -1540,7 +1546,8 @@ ps.prepare('select @param as value', err => {
1540
1546
  ```
1541
1547
 
1542
1548
  __Errors__
1543
- - ENOTOPEN (`ConnectionError`) - Connection not yet open.
1549
+ - ENOCONN (`PreparedStatementError`) - No connection is specified for that prepared statement.
1550
+ - ECONNCLOSED (`ConnectionError`) - Connection is closed.
1544
1551
  - EALREADYPREPARED (`PreparedStatementError`) - Statement is already prepared.
1545
1552
  - ENOTBEGUN (`TransactionError`) - Transaction has not begun.
1546
1553
 
@@ -2215,8 +2222,9 @@ Name | Code | Message
2215
2222
  `ConnectionError` | ECONNCLOSED | Connection is closed.
2216
2223
  `TransactionError` | ENOTBEGUN | Transaction has not begun.
2217
2224
  `TransactionError` | EALREADYBEGUN | Transaction has already begun.
2218
- `TransactionError` | EREQINPROG | Can't commit/rollback transaction. There is a request in progress.
2225
+ `TransactionError` | EREQINPROG | Can't commit/rollback transaction or acquire connection for the request. There is a request in progress.
2219
2226
  `TransactionError` | EABORT | Transaction has been aborted.
2227
+ `TransactionError` | ENOCONN | No connection is specified for that transaction.
2220
2228
  `RequestError` | EREQUEST | Message from SQL Server. Error object contains additional details.
2221
2229
  `RequestError` | ECANCEL | Cancelled.
2222
2230
  `RequestError` | ETIMEOUT | Request timeout.
@@ -2227,6 +2235,7 @@ Name | Code | Message
2227
2235
  `PreparedStatementError` | EINJECT | Parameter name is not a valid identifier.
2228
2236
  `PreparedStatementError` | EALREADYPREPARED | Statement is already prepared.
2229
2237
  `PreparedStatementError` | ENOTPREPARED | Statement is not prepared.
2238
+ `PreparedStatementError` | ENOCONN | No connection is specified for that prepared statement.
2230
2239
 
2231
2240
  ### Detailed SQL Errors
2232
2241
 
@@ -401,7 +401,13 @@ class ConnectionPool extends EventEmitter {
401
401
  }))
402
402
 
403
403
  if (typeof callback === 'function') {
404
- acquirePromise.then(connection => callback(null, connection, this.config)).catch(callback)
404
+ // called back outside the promise chain, so that what the callback throws is not taken
405
+ // for a failure to acquire and passed back to it, but reaches the process as it would
406
+ // from any other callback
407
+ acquirePromise.then(
408
+ connection => process.nextTick(callback, null, connection, this.config),
409
+ err => process.nextTick(callback, err)
410
+ )
405
411
  return this
406
412
  }
407
413
 
@@ -4,7 +4,7 @@ const debug = require('debug')('mssql:base')
4
4
  const { EventEmitter } = require('node:events')
5
5
  const { IDS, objectHasProperty, getPoolId, isValidParameterName } = require('../utils')
6
6
  const globalConnection = require('../global-connection')
7
- const { TransactionError, PreparedStatementError } = require('../error')
7
+ const { ConnectionError, TransactionError, PreparedStatementError } = require('../error')
8
8
  const shared = require('../shared')
9
9
  const { TYPES, declare } = require('../datatypes')
10
10
  const { CHANNELS, tracePromise, traceCallback, publish } = require('../diagnostics')
@@ -244,6 +244,14 @@ class PreparedStatement extends EventEmitter {
244
244
 
245
245
  this.statement = statement || this.statement
246
246
 
247
+ if (!this.parent) {
248
+ return setImmediate(callback, new PreparedStatementError('No connection is specified for that prepared statement.', 'ENOCONN'))
249
+ }
250
+
251
+ if (!this.parent.connected) {
252
+ return setImmediate(callback, new ConnectionError('Connection is closed.', 'ECONNCLOSED'))
253
+ }
254
+
247
255
  this.parent.acquire(this, (err, connection, config) => {
248
256
  if (err) return callback(err)
249
257
 
@@ -4,7 +4,7 @@ const debug = require('debug')('mssql:base')
4
4
  const { EventEmitter } = require('node:events')
5
5
  const { IDS, getPoolId } = require('../utils')
6
6
  const globalConnection = require('../global-connection')
7
- const { TransactionError } = require('../error')
7
+ const { ConnectionError, TransactionError } = require('../error')
8
8
  const shared = require('../shared')
9
9
  const ISOLATION_LEVEL = require('../isolationlevel')
10
10
  const { CHANNELS, publish } = require('../diagnostics')
@@ -52,7 +52,7 @@ class Transaction extends EventEmitter {
52
52
  }
53
53
 
54
54
  get connected () {
55
- return this.parent.connected
55
+ return this.parent ? this.parent.connected : false
56
56
  }
57
57
 
58
58
  /**
@@ -164,6 +164,14 @@ class Transaction extends EventEmitter {
164
164
  }
165
165
  }
166
166
 
167
+ if (!this.parent) {
168
+ return setImmediate(callback, new TransactionError('No connection is specified for that transaction.', 'ENOCONN'))
169
+ }
170
+
171
+ if (!this.parent.connected) {
172
+ return setImmediate(callback, new ConnectionError('Connection is closed.', 'ECONNCLOSED'))
173
+ }
174
+
167
175
  setImmediate(callback)
168
176
  }
169
177
 
@@ -248,10 +248,24 @@ class Request extends BaseRequest {
248
248
 
249
249
  this.parent.release(connection)
250
250
 
251
+ // msnodesqlv8's table manager calls `done` from within promise chains, which would
252
+ // catch what the caller's callback throws and pass it back here as the driver's
253
+ // error, to be dropped. The caller is called back outside them, so that what its
254
+ // callback throws reaches the process as it would from any other callback.
251
255
  if (err) {
252
- callback(err)
256
+ process.nextTick(callback, err)
253
257
  } else {
254
- callback(null, table.rows.length)
258
+ process.nextTick(callback, null, table.rows.length)
259
+ }
260
+ }
261
+
262
+ // msnodesqlv8 throws, rather than calls back, for a query on a connection it has
263
+ // closed, so what it throws is handed to `done` as well, which releases the connection
264
+ const attempt = run => {
265
+ try {
266
+ run()
267
+ } catch (e) {
268
+ done(e)
255
269
  }
256
270
  }
257
271
 
@@ -317,13 +331,15 @@ class Request extends BaseRequest {
317
331
  return done(e)
318
332
  }
319
333
 
320
- return connection.queryRaw(statement, function (err) {
334
+ return attempt(() => connection.queryRaw(statement, function (err) {
321
335
  if (err) { return done(err) }
322
- go()
323
- })
336
+ attempt(go)
337
+ }))
324
338
  } else {
325
- go()
339
+ attempt(go)
326
340
  }
341
+ } else {
342
+ callback(err)
327
343
  }
328
344
  })
329
345
  })
@@ -532,10 +548,19 @@ class Request extends BaseRequest {
532
548
 
533
549
  debug('request(%d): query', IDS.get(this), command)
534
550
 
535
- const req = connection.queryRaw({
536
- query_str: command,
537
- query_timeout: (this.overrides.requestTimeout ?? config.requestTimeout) / 1000 // msnodesqlv8 timeouts are in seconds (<1 second not supported)
538
- }, params)
551
+ // msnodesqlv8 throws, rather than calls back, for a query on a connection it has closed
552
+ let req
553
+ try {
554
+ req = connection.queryRaw({
555
+ query_str: command,
556
+ query_timeout: (this.overrides.requestTimeout ?? config.requestTimeout) / 1000 // msnodesqlv8 timeouts are in seconds (<1 second not supported)
557
+ }, params)
558
+ } catch (e) {
559
+ this.parent.release(connection)
560
+ const err = new RequestError(e, 'EREQUEST')
561
+ err.code = 'EREQUEST'
562
+ return callback(err)
563
+ }
539
564
 
540
565
  this._setCurrentRequest(req)
541
566
 
@@ -65,8 +65,8 @@ class Transaction extends BaseTransaction {
65
65
  this._acquiredConfig = null
66
66
 
67
67
  // deferred so that tedious is done with the connection before it is closed, and so
68
- // that the callback runs outside the pool's promise chain, which would pass anything
69
- // the callback throws back to the acquire callback above as a second error
68
+ // that what the callback throws when tedious calls back at once is not caught below
69
+ // as though tedious had thrown it
70
70
  setImmediate(() => {
71
71
  if (discard) connection.close()
72
72
  this.parent.release(connection)
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "azure",
22
22
  "node-mssql"
23
23
  ],
24
- "version": "12.7.7",
24
+ "version": "12.7.9",
25
25
  "main": "index.js",
26
26
  "type": "commonjs",
27
27
  "repository": {