mssql 7.2.1 → 8.0.2
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/CHANGELOG.txt +25 -2
- package/LICENSE.md +22 -22
- package/README.md +136 -208
- package/bin/mssql +0 -0
- package/lib/base/connection-pool.js +5 -40
- package/lib/base/index.js +7 -0
- package/lib/base/prepared-statement.js +4 -0
- package/lib/base/request.js +13 -11
- package/lib/base/transaction.js +4 -0
- package/lib/cli.js +113 -113
- package/lib/isolationlevel.js +9 -9
- package/lib/msnodesqlv8/connection-pool.js +4 -2
- package/lib/msnodesqlv8/index.js +7 -0
- package/lib/msnodesqlv8/request.js +7 -1
- package/lib/shared.js +7 -0
- package/lib/table.js +7 -0
- package/lib/tedious/connection-pool.js +10 -10
- package/lib/tedious/index.js +7 -0
- package/lib/tedious/request.js +9 -13
- package/package.json +6 -6
- package/test.js +40 -47
- package/lib/connectionstring.js +0 -289
package/lib/base/request.js
CHANGED
|
@@ -26,7 +26,7 @@ class Request extends EventEmitter {
|
|
|
26
26
|
/**
|
|
27
27
|
* Create new Request.
|
|
28
28
|
*
|
|
29
|
-
* @param {Connection|ConnectionPool|Transaction|PreparedStatement} parent If
|
|
29
|
+
* @param {Connection|ConnectionPool|Transaction|PreparedStatement} parent If omitted, global connection is used instead.
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
32
|
constructor (parent) {
|
|
@@ -39,6 +39,8 @@ class Request extends EventEmitter {
|
|
|
39
39
|
this._paused = false
|
|
40
40
|
this.parent = parent || globalConnection.pool
|
|
41
41
|
this.parameters = {}
|
|
42
|
+
this.stream = null
|
|
43
|
+
this.arrayRowMode = null
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
get paused () {
|
|
@@ -224,8 +226,8 @@ class Request extends EventEmitter {
|
|
|
224
226
|
*/
|
|
225
227
|
|
|
226
228
|
batch (batch, callback) {
|
|
227
|
-
if (this.stream
|
|
228
|
-
if (this.arrayRowMode
|
|
229
|
+
if (this.stream === null && this.parent) this.stream = this.parent.config.stream
|
|
230
|
+
if (this.arrayRowMode === null && this.parent) this.arrayRowMode = this.parent.config.arrayRowMode
|
|
229
231
|
this.rowsAffected = 0
|
|
230
232
|
|
|
231
233
|
if (typeof callback === 'function') {
|
|
@@ -288,11 +290,11 @@ class Request extends EventEmitter {
|
|
|
288
290
|
*/
|
|
289
291
|
|
|
290
292
|
_batch (batch, callback) {
|
|
291
|
-
if (!this.
|
|
293
|
+
if (!this.parent) {
|
|
292
294
|
return setImmediate(callback, new RequestError('No connection is specified for that request.', 'ENOCONN'))
|
|
293
295
|
}
|
|
294
296
|
|
|
295
|
-
if (!this.
|
|
297
|
+
if (!this.parent.connected) {
|
|
296
298
|
return setImmediate(callback, new ConnectionError('Connection is closed.', 'ECONNCLOSED'))
|
|
297
299
|
}
|
|
298
300
|
|
|
@@ -317,8 +319,8 @@ class Request extends EventEmitter {
|
|
|
317
319
|
options = {}
|
|
318
320
|
}
|
|
319
321
|
|
|
320
|
-
if (this.stream
|
|
321
|
-
if (this.arrayRowMode
|
|
322
|
+
if (this.stream === null && this.parent) this.stream = this.parent.config.stream
|
|
323
|
+
if (this.arrayRowMode === null && this.parent) this.arrayRowMode = this.parent.config.arrayRowMode
|
|
322
324
|
|
|
323
325
|
if (this.stream || typeof callback === 'function') {
|
|
324
326
|
this._bulk(table, options, (err, rowsAffected) => {
|
|
@@ -419,8 +421,8 @@ class Request extends EventEmitter {
|
|
|
419
421
|
*/
|
|
420
422
|
|
|
421
423
|
query (command, callback) {
|
|
422
|
-
if (this.stream
|
|
423
|
-
if (this.arrayRowMode
|
|
424
|
+
if (this.stream === null && this.parent) this.stream = this.parent.config.stream
|
|
425
|
+
if (this.arrayRowMode === null && this.parent) this.arrayRowMode = this.parent.config.arrayRowMode
|
|
424
426
|
this.rowsAffected = 0
|
|
425
427
|
|
|
426
428
|
if (typeof callback === 'function') {
|
|
@@ -508,8 +510,8 @@ class Request extends EventEmitter {
|
|
|
508
510
|
*/
|
|
509
511
|
|
|
510
512
|
execute (command, callback) {
|
|
511
|
-
if (this.stream
|
|
512
|
-
if (this.arrayRowMode
|
|
513
|
+
if (this.stream === null && this.parent) this.stream = this.parent.config.stream
|
|
514
|
+
if (this.arrayRowMode === null && this.parent) this.arrayRowMode = this.parent.config.arrayRowMode
|
|
513
515
|
this.rowsAffected = 0
|
|
514
516
|
|
|
515
517
|
if (typeof callback === 'function') {
|
package/lib/base/transaction.js
CHANGED
package/lib/cli.js
CHANGED
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const fs = require('fs')
|
|
4
|
-
const path = require('path')
|
|
5
|
-
const sql = require('./tedious')
|
|
6
|
-
|
|
7
|
-
const exit = process.exit
|
|
8
|
-
const write = text => process.stdout.write(text)
|
|
9
|
-
Buffer.prototype.toJSON = () => {
|
|
10
|
-
return `0x${this.toString('hex')}`
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// Resolve config path
|
|
14
|
-
|
|
15
|
-
let cfgPath = path.resolve(process.argv[2] || process.cwd())
|
|
16
|
-
if (fs.lstatSync(cfgPath).isDirectory()) {
|
|
17
|
-
cfgPath = path.resolve(cfgPath, './.mssql.json')
|
|
18
|
-
}
|
|
19
|
-
if (!fs.existsSync(cfgPath)) {
|
|
20
|
-
console.error('Config file not found.')
|
|
21
|
-
exit(1)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Config checks & parse
|
|
25
|
-
|
|
26
|
-
let config
|
|
27
|
-
try {
|
|
28
|
-
config = fs.readFileSync(cfgPath)
|
|
29
|
-
} catch (err) {
|
|
30
|
-
console.error(`Failed to load config file. ${err.message}`)
|
|
31
|
-
exit(1)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
config = JSON.parse(config)
|
|
36
|
-
} catch (err) {
|
|
37
|
-
console.error(`Failed to parse config file. ${err.message}`)
|
|
38
|
-
exit(1)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Read stdin
|
|
42
|
-
|
|
43
|
-
const buffer = []
|
|
44
|
-
|
|
45
|
-
process.stdin.setEncoding('utf8')
|
|
46
|
-
process.stdin.on('readable', () => buffer.push(process.stdin.read()))
|
|
47
|
-
|
|
48
|
-
process.stdin.on('end', () => {
|
|
49
|
-
const statement = buffer.join('')
|
|
50
|
-
let rst = 0
|
|
51
|
-
let index = 0
|
|
52
|
-
|
|
53
|
-
if (!statement.length) {
|
|
54
|
-
console.error('Statement is empty.')
|
|
55
|
-
exit(1)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
sql.connect(config, err => {
|
|
59
|
-
if (err) {
|
|
60
|
-
console.error(err.message)
|
|
61
|
-
exit(1)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
write('[')
|
|
65
|
-
|
|
66
|
-
const request = new sql.Request()
|
|
67
|
-
request.stream = true
|
|
68
|
-
request.on('recordset', () => {
|
|
69
|
-
index = 0
|
|
70
|
-
if (rst++ > 0) {
|
|
71
|
-
write('],')
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return write('[')
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
request.on('error', err => {
|
|
78
|
-
console.error(err.message)
|
|
79
|
-
sql.close()
|
|
80
|
-
return exit(1)
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
request.on('row', row => {
|
|
84
|
-
if (index++ > 0) {
|
|
85
|
-
write(',')
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return write(JSON.stringify(row))
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
request.on('done', () => {
|
|
92
|
-
if (rst > 0) {
|
|
93
|
-
write(']')
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
write(']\n')
|
|
97
|
-
sql.close()
|
|
98
|
-
return exit(0)
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
request.query(statement)
|
|
102
|
-
})
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
process.on('uncaughtException', err => {
|
|
106
|
-
if (err.code === 'EPIPE') {
|
|
107
|
-
console.error('Failed to pipe output stream.')
|
|
108
|
-
} else {
|
|
109
|
-
console.error(err.message)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
exit(1)
|
|
113
|
-
})
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const sql = require('./tedious')
|
|
6
|
+
|
|
7
|
+
const exit = process.exit
|
|
8
|
+
const write = text => process.stdout.write(text)
|
|
9
|
+
Buffer.prototype.toJSON = () => {
|
|
10
|
+
return `0x${this.toString('hex')}`
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Resolve config path
|
|
14
|
+
|
|
15
|
+
let cfgPath = path.resolve(process.argv[2] || process.cwd())
|
|
16
|
+
if (fs.lstatSync(cfgPath).isDirectory()) {
|
|
17
|
+
cfgPath = path.resolve(cfgPath, './.mssql.json')
|
|
18
|
+
}
|
|
19
|
+
if (!fs.existsSync(cfgPath)) {
|
|
20
|
+
console.error('Config file not found.')
|
|
21
|
+
exit(1)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Config checks & parse
|
|
25
|
+
|
|
26
|
+
let config
|
|
27
|
+
try {
|
|
28
|
+
config = fs.readFileSync(cfgPath)
|
|
29
|
+
} catch (err) {
|
|
30
|
+
console.error(`Failed to load config file. ${err.message}`)
|
|
31
|
+
exit(1)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
config = JSON.parse(config)
|
|
36
|
+
} catch (err) {
|
|
37
|
+
console.error(`Failed to parse config file. ${err.message}`)
|
|
38
|
+
exit(1)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Read stdin
|
|
42
|
+
|
|
43
|
+
const buffer = []
|
|
44
|
+
|
|
45
|
+
process.stdin.setEncoding('utf8')
|
|
46
|
+
process.stdin.on('readable', () => buffer.push(process.stdin.read()))
|
|
47
|
+
|
|
48
|
+
process.stdin.on('end', () => {
|
|
49
|
+
const statement = buffer.join('')
|
|
50
|
+
let rst = 0
|
|
51
|
+
let index = 0
|
|
52
|
+
|
|
53
|
+
if (!statement.length) {
|
|
54
|
+
console.error('Statement is empty.')
|
|
55
|
+
exit(1)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
sql.connect(config, err => {
|
|
59
|
+
if (err) {
|
|
60
|
+
console.error(err.message)
|
|
61
|
+
exit(1)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
write('[')
|
|
65
|
+
|
|
66
|
+
const request = new sql.Request()
|
|
67
|
+
request.stream = true
|
|
68
|
+
request.on('recordset', () => {
|
|
69
|
+
index = 0
|
|
70
|
+
if (rst++ > 0) {
|
|
71
|
+
write('],')
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return write('[')
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
request.on('error', err => {
|
|
78
|
+
console.error(err.message)
|
|
79
|
+
sql.close()
|
|
80
|
+
return exit(1)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
request.on('row', row => {
|
|
84
|
+
if (index++ > 0) {
|
|
85
|
+
write(',')
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return write(JSON.stringify(row))
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
request.on('done', () => {
|
|
92
|
+
if (rst > 0) {
|
|
93
|
+
write(']')
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
write(']\n')
|
|
97
|
+
sql.close()
|
|
98
|
+
return exit(0)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
request.query(statement)
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
process.on('uncaughtException', err => {
|
|
106
|
+
if (err.code === 'EPIPE') {
|
|
107
|
+
console.error('Failed to pipe output stream.')
|
|
108
|
+
} else {
|
|
109
|
+
console.error(err.message)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
exit(1)
|
|
113
|
+
})
|
package/lib/isolationlevel.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
READ_UNCOMMITTED: 0x01,
|
|
5
|
-
READ_COMMITTED: 0x02,
|
|
6
|
-
REPEATABLE_READ: 0x03,
|
|
7
|
-
SERIALIZABLE: 0x04,
|
|
8
|
-
SNAPSHOT: 0x05
|
|
9
|
-
}
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
READ_UNCOMMITTED: 0x01,
|
|
5
|
+
READ_COMMITTED: 0x02,
|
|
6
|
+
REPEATABLE_READ: 0x03,
|
|
7
|
+
SERIALIZABLE: 0x04,
|
|
8
|
+
SNAPSHOT: 0x05
|
|
9
|
+
}
|
|
@@ -6,9 +6,11 @@ const BaseConnectionPool = require('../base/connection-pool')
|
|
|
6
6
|
const { IDS, INCREMENT } = require('../utils')
|
|
7
7
|
const shared = require('../shared')
|
|
8
8
|
const ConnectionError = require('../error/connection-error')
|
|
9
|
+
const { platform } = require('os')
|
|
9
10
|
|
|
10
|
-
const
|
|
11
|
-
const
|
|
11
|
+
const CONNECTION_DRIVER = ['darwin', 'linux'].includes(platform()) ? 'ODBC Driver 17 for SQL Server' : 'SQL Server Native Client 11.0'
|
|
12
|
+
const CONNECTION_STRING_PORT = `Driver=${CONNECTION_DRIVER};Server=#{server},#{port};Database=#{database};Uid=#{user};Pwd=#{password};Trusted_Connection=#{trusted};Encrypt=#{encrypt};`
|
|
13
|
+
const CONNECTION_STRING_NAMED_INSTANCE = `Driver=${CONNECTION_DRIVER};Server=#{server}\\#{instance};Database=#{database};Uid=#{user};Pwd=#{password};Trusted_Connection=#{trusted};Encrypt=#{encrypt};`
|
|
12
14
|
|
|
13
15
|
class ConnectionPool extends BaseConnectionPool {
|
|
14
16
|
_poolCreate () {
|
package/lib/msnodesqlv8/index.js
CHANGED
|
@@ -22,6 +22,13 @@ Object.defineProperty(module.exports, 'Promise', {
|
|
|
22
22
|
}
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
+
Object.defineProperty(module.exports, 'valueHandler', {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
value: base.valueHandler,
|
|
28
|
+
writable: false,
|
|
29
|
+
configurable: false
|
|
30
|
+
})
|
|
31
|
+
|
|
25
32
|
base.driver.name = 'msnodesqlv8'
|
|
26
33
|
base.driver.ConnectionPool = ConnectionPool
|
|
27
34
|
base.driver.Transaction = Transaction
|
|
@@ -8,6 +8,7 @@ const { IDS, objectHasProperty } = require('../utils')
|
|
|
8
8
|
const { TYPES, DECLARATIONS, declare } = require('../datatypes')
|
|
9
9
|
const { PARSERS: UDT } = require('../udt')
|
|
10
10
|
const Table = require('../table')
|
|
11
|
+
const { valueHandler } = require('../shared')
|
|
11
12
|
|
|
12
13
|
const JSON_COLUMN_ID = 'JSON_F52E2B61-18A1-11d1-B105-00805F49916B'
|
|
13
14
|
const XML_COLUMN_ID = 'XML_F52E2B61-18A1-11d1-B105-00805F49916B'
|
|
@@ -122,7 +123,12 @@ const createColumns = function (metadata, arrayRowMode) {
|
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
const valueCorrection = function (value, metadata) {
|
|
125
|
-
|
|
126
|
+
const type = metadata && objectHasProperty(metadata, 'sqlType') && objectHasProperty(DECLARATIONS, metadata.sqlType)
|
|
127
|
+
? DECLARATIONS[metadata.sqlType]
|
|
128
|
+
: null
|
|
129
|
+
if (type && valueHandler.has(type)) {
|
|
130
|
+
return valueHandler.get(type)(value)
|
|
131
|
+
} else if ((metadata.sqlType === 'time') && (value != null)) {
|
|
126
132
|
value.setFullYear(1970)
|
|
127
133
|
return value
|
|
128
134
|
} else if ((metadata.sqlType === 'udt') && (value != null)) {
|
package/lib/shared.js
CHANGED
package/lib/table.js
CHANGED
|
@@ -34,24 +34,23 @@ class ConnectionPool extends BaseConnectionPool {
|
|
|
34
34
|
}, this.config.authentication)
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
cfg.options.database = this.config.database
|
|
38
|
-
cfg.options.port = this.config.port
|
|
39
|
-
cfg.options.connectTimeout = this.config.connectionTimeout || this.config.timeout || 15000
|
|
40
|
-
cfg.options.requestTimeout = this.config.requestTimeout != null ? this.config.requestTimeout : 15000
|
|
37
|
+
cfg.options.database = cfg.options.database || this.config.database
|
|
38
|
+
cfg.options.port = cfg.options.port || this.config.port
|
|
39
|
+
cfg.options.connectTimeout = cfg.options.connectTimeout || this.config.connectionTimeout || this.config.timeout || 15000
|
|
40
|
+
cfg.options.requestTimeout = cfg.options.requestTimeout || this.config.requestTimeout != null ? this.config.requestTimeout : 15000
|
|
41
41
|
cfg.options.tdsVersion = cfg.options.tdsVersion || '7_4'
|
|
42
|
-
cfg.options.rowCollectionOnDone = false
|
|
43
|
-
cfg.options.rowCollectionOnRequestCompletion = false
|
|
44
|
-
cfg.options.useColumnNames = false
|
|
42
|
+
cfg.options.rowCollectionOnDone = cfg.options.rowCollectionOnDone || false
|
|
43
|
+
cfg.options.rowCollectionOnRequestCompletion = cfg.options.rowCollectionOnRequestCompletion || false
|
|
44
|
+
cfg.options.useColumnNames = cfg.options.useColumnNames || false
|
|
45
45
|
cfg.options.appName = cfg.options.appName || 'node-mssql'
|
|
46
46
|
|
|
47
47
|
// tedious always connect via tcp when port is specified
|
|
48
48
|
if (cfg.options.instanceName) delete cfg.options.port
|
|
49
49
|
|
|
50
50
|
if (isNaN(cfg.options.requestTimeout)) cfg.options.requestTimeout = 15000
|
|
51
|
-
if (cfg.options.requestTimeout === Infinity) cfg.options.requestTimeout = 0
|
|
52
|
-
if (cfg.options.requestTimeout < 0) cfg.options.requestTimeout = 0
|
|
51
|
+
if (cfg.options.requestTimeout === Infinity || cfg.options.requestTimeout < 0) cfg.options.requestTimeout = 0
|
|
53
52
|
|
|
54
|
-
if (this.config.debug) {
|
|
53
|
+
if (!cfg.options.debug && this.config.debug) {
|
|
55
54
|
cfg.options.debug = {
|
|
56
55
|
packet: true,
|
|
57
56
|
token: true,
|
|
@@ -73,6 +72,7 @@ class ConnectionPool extends BaseConnectionPool {
|
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
debug('connection(%d): established', IDS.get(tedious))
|
|
75
|
+
this.collation = tedious.databaseCollation
|
|
76
76
|
resolveOnce(tedious)
|
|
77
77
|
})
|
|
78
78
|
IDS.add(tedious, 'Connection')
|
package/lib/tedious/index.js
CHANGED
|
@@ -22,6 +22,13 @@ Object.defineProperty(module.exports, 'Promise', {
|
|
|
22
22
|
}
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
+
Object.defineProperty(module.exports, 'valueHandler', {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
value: base.valueHandler,
|
|
28
|
+
writable: false,
|
|
29
|
+
configurable: false
|
|
30
|
+
})
|
|
31
|
+
|
|
25
32
|
base.driver.name = 'tedious'
|
|
26
33
|
base.driver.ConnectionPool = ConnectionPool
|
|
27
34
|
base.driver.Transaction = Transaction
|
package/lib/tedious/request.js
CHANGED
|
@@ -8,6 +8,7 @@ const { IDS, objectHasProperty } = require('../utils')
|
|
|
8
8
|
const { TYPES, DECLARATIONS, declare, cast } = require('../datatypes')
|
|
9
9
|
const Table = require('../table')
|
|
10
10
|
const { PARSERS: UDT } = require('../udt')
|
|
11
|
+
const { valueHandler } = require('../shared')
|
|
11
12
|
|
|
12
13
|
const JSON_COLUMN_ID = 'JSON_F52E2B61-18A1-11d1-B105-00805F49916B'
|
|
13
14
|
const XML_COLUMN_ID = 'XML_F52E2B61-18A1-11d1-B105-00805F49916B'
|
|
@@ -159,7 +160,10 @@ const createColumns = function (metadata, arrayRowMode) {
|
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
const valueCorrection = function (value, metadata) {
|
|
162
|
-
|
|
163
|
+
const type = getMssqlType(metadata.type)
|
|
164
|
+
if (valueHandler.has(type)) {
|
|
165
|
+
return valueHandler.get(type)(value)
|
|
166
|
+
} else if ((metadata.type === tds.TYPES.UDT) && (value != null)) {
|
|
163
167
|
if (UDT[metadata.udtInfo.typeName]) {
|
|
164
168
|
return UDT[metadata.udtInfo.typeName](value)
|
|
165
169
|
} else {
|
|
@@ -334,26 +338,18 @@ class Request extends BaseRequest {
|
|
|
334
338
|
bulk.addColumn(col.name, getTediousType(col.type), { nullable: col.nullable, length: col.length, scale: col.scale, precision: col.precision })
|
|
335
339
|
}
|
|
336
340
|
|
|
337
|
-
for (const row of table.rows) {
|
|
338
|
-
try {
|
|
339
|
-
bulk.addRow(row)
|
|
340
|
-
} catch (e) {
|
|
341
|
-
return handleError(true, connection, e)
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
341
|
if (table.create) {
|
|
346
342
|
const objectid = table.temporary ? `tempdb..[${table.name}]` : table.path
|
|
347
343
|
const req = new tds.Request(`if object_id('${objectid.replace(/'/g, '\'\'')}') is null ${table.declare()}`, err => {
|
|
348
344
|
if (err) return done(err)
|
|
349
345
|
|
|
350
|
-
connection.execBulkLoad(bulk)
|
|
346
|
+
connection.execBulkLoad(bulk, table.rows)
|
|
351
347
|
})
|
|
352
348
|
this._setCurrentRequest(req)
|
|
353
349
|
|
|
354
350
|
connection.execSqlBatch(req)
|
|
355
351
|
} else {
|
|
356
|
-
connection.execBulkLoad(bulk)
|
|
352
|
+
connection.execBulkLoad(bulk, table.rows)
|
|
357
353
|
}
|
|
358
354
|
})
|
|
359
355
|
})
|
|
@@ -608,7 +604,7 @@ class Request extends BaseRequest {
|
|
|
608
604
|
row.push(col.value)
|
|
609
605
|
} else {
|
|
610
606
|
const exi = row[col.metadata.colName]
|
|
611
|
-
if (exi
|
|
607
|
+
if (exi !== undefined) {
|
|
612
608
|
if (exi instanceof Array) {
|
|
613
609
|
exi.push(col.value)
|
|
614
610
|
} else {
|
|
@@ -645,7 +641,7 @@ class Request extends BaseRequest {
|
|
|
645
641
|
const param = this.parameters[name]
|
|
646
642
|
|
|
647
643
|
try {
|
|
648
|
-
param.value = getTediousType(param.type).validate(param.value)
|
|
644
|
+
param.value = getTediousType(param.type).validate(param.value, this.parent.collation)
|
|
649
645
|
} catch (e) {
|
|
650
646
|
e.message = `Validation failed for parameter '${name}'. ${e.message}`
|
|
651
647
|
const err = new RequestError(e, 'EPARAM')
|
package/package.json
CHANGED
|
@@ -21,20 +21,20 @@
|
|
|
21
21
|
"azure",
|
|
22
22
|
"node-mssql"
|
|
23
23
|
],
|
|
24
|
-
"version": "
|
|
24
|
+
"version": "8.0.2",
|
|
25
25
|
"main": "index.js",
|
|
26
26
|
"repository": "github:tediousjs/node-mssql",
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@tediousjs/connection-string": "^0.3.0",
|
|
30
|
-
"debug": "^4.3.
|
|
30
|
+
"debug": "^4.3.3",
|
|
31
31
|
"rfdc": "^1.3.0",
|
|
32
|
-
"tarn": "^3.0.
|
|
33
|
-
"tedious": "^
|
|
32
|
+
"tarn": "^3.0.2",
|
|
33
|
+
"tedious": "^14.0.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"mocha": "^
|
|
37
|
-
"standard": "^16.0.
|
|
36
|
+
"mocha": "^9.1.3",
|
|
37
|
+
"standard": "^16.0.4"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": ">=10"
|
package/test.js
CHANGED
|
@@ -1,47 +1,40 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
console.error(e);
|
|
42
|
-
} finally {
|
|
43
|
-
await pool.close();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
main().catch(console.error);
|
|
1
|
+
'use strict'
|
|
2
|
+
const mssql = require('./')
|
|
3
|
+
|
|
4
|
+
const [, , max] = process.argv
|
|
5
|
+
|
|
6
|
+
const sqlConfig = {
|
|
7
|
+
password: 'P@ssw0rd',
|
|
8
|
+
database: 'test',
|
|
9
|
+
stream: false,
|
|
10
|
+
// driver: 'msnodesqlv8',
|
|
11
|
+
options: {
|
|
12
|
+
trustServerCertificate: true,
|
|
13
|
+
enableArithAbort: true,
|
|
14
|
+
encrypt: true,
|
|
15
|
+
abortTransactionOnError: false
|
|
16
|
+
},
|
|
17
|
+
pool: {
|
|
18
|
+
max: max ? parseInt(max) : 10,
|
|
19
|
+
min: 0
|
|
20
|
+
},
|
|
21
|
+
port: 1433,
|
|
22
|
+
user: 'sa',
|
|
23
|
+
server: 'localhost',
|
|
24
|
+
arrayRowMode: true
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
mssql.connect(sqlConfig).then((pool) => {
|
|
28
|
+
console.log('Connected to SQL server')
|
|
29
|
+
const request = pool.request()
|
|
30
|
+
request.stream = true
|
|
31
|
+
request.on('error', (err) => {
|
|
32
|
+
console.error('good', err)
|
|
33
|
+
})
|
|
34
|
+
return request.query('SELECT * FROM nontable')
|
|
35
|
+
}).catch((err) => {
|
|
36
|
+
console.error('bad', err)
|
|
37
|
+
}).then(() => {
|
|
38
|
+
console.log('Disconnecting from SQL server')
|
|
39
|
+
return mssql.close()
|
|
40
|
+
}).then(() => console.log('Disconnected'))
|