tedious 11.5.0 → 11.8.0

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.
@@ -0,0 +1,61 @@
1
+ // @ts-check
2
+
3
+ const { createBenchmark, createConnection } = require('../common');
4
+
5
+ const { Request, TYPES } = require('../../src/tedious');
6
+
7
+ const bench = createBenchmark(main, {
8
+ n: [10, 100],
9
+ size: [
10
+ 10,
11
+ 100,
12
+ 1000,
13
+ 10000
14
+ ]
15
+ });
16
+
17
+ function main({ n, size }) {
18
+ createConnection((connection) => {
19
+ const request = new Request(`
20
+ CREATE TABLE "#tmpTestTable" (
21
+ "id" int NOT NULL
22
+ )
23
+ `, (err) => {
24
+ if (err) {
25
+ throw err;
26
+ }
27
+
28
+ let i = 0;
29
+
30
+ bench.start();
31
+
32
+ (function cb() {
33
+ const bulkLoad = connection.newBulkLoad('#tmpTestTable', (err) => {
34
+ if (err) {
35
+ throw err;
36
+ }
37
+
38
+ if (i++ === n) {
39
+ bench.end(n);
40
+
41
+ connection.close();
42
+
43
+ return;
44
+ }
45
+
46
+ cb();
47
+ });
48
+
49
+ bulkLoad.addColumn('id', TYPES.Int, { nullable: false });
50
+
51
+ const rows = [];
52
+ for (let j = 0; j < size; j++) {
53
+ rows.push([ j ]);
54
+ }
55
+ connection.execBulkLoad(bulkLoad, rows);
56
+ })();
57
+ });
58
+
59
+ connection.execSqlBatch(request);
60
+ });
61
+ }
package/lib/bulk-load.js CHANGED
@@ -54,7 +54,12 @@ const DONE_STATUS = {
54
54
  * @private
55
55
  */
56
56
 
57
- const rowTokenBuffer = Buffer.from([_token.TYPE.ROW]); // A transform that converts rows to packets.
57
+ const rowTokenBuffer = Buffer.from([_token.TYPE.ROW]);
58
+ const textPointerAndTimestampBuffer = Buffer.from([// TextPointer length
59
+ 0x10, // TextPointer
60
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Timestamp
61
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
62
+ const textPointerNullBuffer = Buffer.from([0x00]); // A transform that converts rows to packets.
58
63
 
59
64
  class RowTransform extends _stream.Transform {
60
65
  /**
@@ -120,6 +125,16 @@ class RowTransform extends _stream.Transform {
120
125
  precision: c.precision,
121
126
  value: value
122
127
  };
128
+
129
+ if (c.type.name === 'Text' || c.type.name === 'Image' || c.type.name === 'NText') {
130
+ if (value == null) {
131
+ this.push(textPointerNullBuffer);
132
+ continue;
133
+ }
134
+
135
+ this.push(textPointerAndTimestampBuffer);
136
+ }
137
+
123
138
  this.push(c.type.generateParameterLength(parameter, this.mainOptions));
124
139
 
125
140
  for (const chunk of c.type.generateParameterData(parameter, this.mainOptions)) {
@@ -160,12 +175,11 @@ class RowTransform extends _stream.Transform {
160
175
  * bulkLoad.addColumn('myInt', TYPES.Int, { nullable: false });
161
176
  * bulkLoad.addColumn('myString', TYPES.NVarChar, { length: 50, nullable: true });
162
177
  *
163
- * // add rows
164
- * bulkLoad.addRow({ myInt: 7, myString: 'hello' });
165
- * bulkLoad.addRow({ myInt: 23, myString: 'world' });
166
- *
167
178
  * // execute
168
- * connection.execBulkLoad(bulkLoad);
179
+ * connection.execBulkLoad(bulkLoad, [
180
+ * { myInt: 7, myString: 'hello' },
181
+ * { myInt: 23, myString: 'world' }
182
+ * ]);
169
183
  * ```
170
184
  */
171
185
 
@@ -325,10 +339,10 @@ class BulkLoad extends _events.EventEmitter {
325
339
  *
326
340
  * @param name The name of the column.
327
341
  * @param type One of the supported `data types`.
328
- * @param __namedParameters Type [[ColumnOptions]]<p> Additional column type information. At a minimum, `nullable` must be set to true or false.
342
+ * @param __namedParameters Additional column type information. At a minimum, `nullable` must be set to true or false.
329
343
  * @param length For VarChar, NVarChar, VarBinary. Use length as `Infinity` for VarChar(max), NVarChar(max) and VarBinary(max).
330
344
  * @param nullable Indicates whether the column accepts NULL values.
331
- * @param objName If the name of the column is different from the name of the property found on `rowObj` arguments passed to [[addRow]], then you can use this option to specify the property name.
345
+ * @param objName If the name of the column is different from the name of the property found on `rowObj` arguments passed to [[addRow]] or [[Connection.execBulkLoad]], then you can use this option to specify the property name.
332
346
  * @param precision For Numeric, Decimal.
333
347
  * @param scale For Numeric, Decimal, Time, DateTime2, DateTimeOffset.
334
348
  */
@@ -380,27 +394,16 @@ class BulkLoad extends _events.EventEmitter {
380
394
  this.columnsByName[name] = column;
381
395
  }
382
396
  /**
383
- * Adds a row to the bulk insert. This method accepts arguments in three different formats:
397
+ * Adds a row to the bulk insert.
384
398
  *
385
399
  * ```js
386
- * bulkLoad.addRow( rowObj )
387
- * bulkLoad.addRow( columnArray )
388
- * bulkLoad.addRow( col0, col1, ... colN )`
400
+ * bulkLoad.addRow({ first_name: 'Bill', last_name: 'Gates' });
389
401
  * ```
390
- * * `rowObj`
391
- *
392
- * An object of key/value pairs representing column name (or objName) and value.
393
402
  *
394
- * * `columnArray`
403
+ * @param row An object of key/value pairs representing column name (or objName) and value.
395
404
  *
396
- * An array representing the values of each column in the same order which they were added to the bulkLoad object.
397
- *
398
- * * `col0, col1, ... colN`
399
- *
400
- * If there are at least two columns, values can be passed as multiple arguments instead of an array. They
401
- * must be in the same order the columns were added in.
402
- *
403
- * @param input
405
+ * @deprecated This method is deprecated. Instead of adding rows individually, you should pass
406
+ * all row objects when calling [[Connection.execBulkLoad]]. This method will be removed in the future.
404
407
  */
405
408
 
406
409
 
@@ -566,7 +569,12 @@ class BulkLoad extends _events.EventEmitter {
566
569
 
567
570
  tBuf.writeUInt16LE(flags); // TYPE_INFO
568
571
 
569
- tBuf.writeBuffer(c.type.generateTypeInfo(c, this.options)); // ColName
572
+ tBuf.writeBuffer(c.type.generateTypeInfo(c, this.options)); // TableName
573
+
574
+ if (c.type.hasTableName) {
575
+ tBuf.writeUsVarchar(this.table, 'ucs2');
576
+ } // ColName
577
+
570
578
 
571
579
  tBuf.writeBVarchar(c.name, 'ucs2');
572
580
  }
@@ -629,6 +637,11 @@ class BulkLoad extends _events.EventEmitter {
629
637
  *
630
638
  * After that, the stream emits a ['drain' event](https://nodejs.org/dist/latest-v10.x/docs/api/stream.html#stream_event_drain)
631
639
  * when it is ready to resume data transfer.
640
+ *
641
+ * @deprecated
642
+ * This method is deprecated. Instead of writing rows to the stream returned by this method,
643
+ * you can pass any object that implements the `Iterable` or `AsyncIterable` interface (e.g. a `Readable`
644
+ * stream or an `AsyncGenerator`) when calling [[Connection.execBulkLoad]]. This method will be removed in the future.
632
645
  */
633
646
 
634
647
 
package/lib/collation.js CHANGED
@@ -6,10 +6,157 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.codepageBySortId = exports.codepageByLcid = void 0;
7
7
  // http://technet.microsoft.com/en-us/library/aa176553(v=sql.80).aspx
8
8
  const codepageByLcid = {
9
- [0x436]: 'CP1252',
10
- [0x401]: 'CP1256',
11
- [0x801]: 'CP1256',
12
- [0xC01]: 'CP1256',
9
+ // Arabic_*
10
+ [0x0401]: 'CP1256',
11
+ // Chinese_Taiwan_Stroke_*
12
+ // Chinese_Traditional_Stroke_Count_*
13
+ [0x0404]: 'CP950',
14
+ // Czech_*
15
+ [0x0405]: 'CP1250',
16
+ // Danish_Greenlandic_*
17
+ // Danish_Norwegian_*
18
+ [0x0406]: 'CP1252',
19
+ // Greek_*
20
+ [0x0408]: 'CP1253',
21
+ // Latin1_General_*
22
+ [0x0409]: 'CP1252',
23
+ // Traditional_Spanish_*
24
+ [0x040A]: 'CP1252',
25
+ // Finnish_Swedish_*
26
+ [0x040B]: 'CP1252',
27
+ // French_*
28
+ [0x040C]: 'CP1252',
29
+ // Hebrew_*
30
+ [0x040D]: 'CP1255',
31
+ // Hungarian_*
32
+ [0x040E]: 'CP1250',
33
+ // Icelandic_*
34
+ [0x040F]: 'CP1252',
35
+ // Japanese_*
36
+ // Japanese_XJIS_*
37
+ [0x0411]: 'CP932',
38
+ // Korean_*
39
+ // Korean_Wansung_*
40
+ [0x0412]: 'CP949',
41
+ // Norwegian_*
42
+ [0x0414]: 'CP1252',
43
+ // Polish_*
44
+ [0x0415]: 'CP1250',
45
+ // Romansh_*
46
+ [0x0417]: 'CP1252',
47
+ // Romanian_*
48
+ [0x0418]: 'CP1250',
49
+ // Cyrillic_*
50
+ [0x0419]: 'CP1251',
51
+ // Croatian_*
52
+ [0x041A]: 'CP1250',
53
+ // Slovak_*
54
+ [0x041B]: 'CP1250',
55
+ // Albanian_*
56
+ [0x041C]: 'CP1250',
57
+ // Thai_*
58
+ [0x041E]: 'CP874',
59
+ // Turkish_*
60
+ [0x041F]: 'CP1254',
61
+ // Urdu_*
62
+ [0x0420]: 'CP1256',
63
+ // Ukrainian_*
64
+ [0x0422]: 'CP1251',
65
+ // Slovenian_*
66
+ [0x0424]: 'CP1250',
67
+ // Estonian_*
68
+ [0x0425]: 'CP1257',
69
+ // Latvian_BIN
70
+ [0x0426]: 'CP1257',
71
+ // Lithuanian_BIN
72
+ [0x0427]: 'CP1257',
73
+ // Persian_100_BIN
74
+ [0x0429]: 'CP1256',
75
+ // Vietnamese_BIN
76
+ [0x042A]: 'CP1258',
77
+ // Azeri_Latin_100_BIN
78
+ [0x042C]: 'CP1254',
79
+ // Upper_Sorbian_100_BIN
80
+ [0x042E]: 'CP1252',
81
+ // Macedonian_FYROM_90_BIN
82
+ [0x042F]: 'CP1251',
83
+ // Sami_Norway_100_BIN
84
+ [0x043B]: 'CP1252',
85
+ // Kazakh_90_BIN
86
+ [0x043F]: 'CP1251',
87
+ // Turkmen_100_BIN
88
+ [0x0442]: 'CP1250',
89
+ // Uzbek_Latin_90_BIN
90
+ [0x0443]: 'CP1254',
91
+ // Tatar_90_BIN
92
+ [0x0444]: 'CP1251',
93
+ // Welsh_100_BIN
94
+ [0x0452]: 'CP1252',
95
+ // Frisian_100_BIN
96
+ [0x0462]: 'CP1252',
97
+ // Bashkir_100_BIN
98
+ [0x046D]: 'CP1251',
99
+ // Mapudungan_100_BIN
100
+ [0x047A]: 'CP1252',
101
+ // Mohawk_100_BIN
102
+ [0x047C]: 'CP1252',
103
+ // Breton_100_BIN
104
+ [0x047E]: 'CP1252',
105
+ // Uighur_100_BIN
106
+ [0x0480]: 'CP1256',
107
+ // Corsican_100_BIN
108
+ [0x0483]: 'CP1252',
109
+ // Yakut_100_BIN
110
+ [0x0485]: 'CP1251',
111
+ // Dari_100_BIN
112
+ [0x048C]: 'CP1256',
113
+ // Chinese_PRC_BIN
114
+ // Chinese_Simplified_Pinyin_100_BIN
115
+ [0x0804]: 'CP936',
116
+ // Serbian_Latin_100_BIN
117
+ [0x081A]: 'CP1250',
118
+ // Azeri_Cyrillic_100_BIN
119
+ [0x082C]: 'CP1251',
120
+ // Sami_Sweden_Finland_100_BIN
121
+ [0x083B]: 'CP1252',
122
+ // Tamazight_100_BIN
123
+ [0x085F]: 'CP1252',
124
+ // Chinese_Hong_Kong_Stroke_90_BIN
125
+ [0x0C04]: 'CP950',
126
+ // Modern_Spanish_BIN
127
+ [0x0C0A]: 'CP1252',
128
+ // Serbian_Cyrillic_100_BIN
129
+ [0x0C1A]: 'CP1251',
130
+ // Chinese_Traditional_Pinyin_100_BIN
131
+ [0x1404]: 'CP950',
132
+ // Bosnian_Latin_100_BIN
133
+ [0x141A]: 'CP1250',
134
+ // Bosnian_Cyrillic_100_BIN
135
+ [0x201A]: 'CP1251',
136
+ // German
137
+ [0x0407]: 'CP1252',
138
+ // German_PhoneBook_BIN
139
+ [0x10407]: 'CP1252',
140
+ // Hungarian_Technical_BIN
141
+ [0x1040E]: 'CP1250',
142
+ // Japanese_Unicode_BIN
143
+ [0x10411]: 'CP932',
144
+ // Georgian_Modern_Sort_BIN
145
+ [0x10437]: 'CP1252',
146
+ // Chinese_PRC_Stroke_BIN
147
+ // Chinese_Simplified_Stroke_Order_100_BIN
148
+ [0x20804]: 'CP936',
149
+ // Chinese_Traditional_Stroke_Order_100_BIN
150
+ [0x21404]: 'CP950',
151
+ // Chinese_Taiwan_Bopomofo_BIN
152
+ // Chinese_Traditional_Bopomofo_100_BIN
153
+ [0x30404]: 'CP950',
154
+ // Japanese_Bushu_Kakusu_100_BIN
155
+ [0x40411]: 'CP932',
156
+ // These LCIDs might not actually be supported by SQL Server
157
+ [0x0436]: 'CP1252',
158
+ [0x0801]: 'CP1256',
159
+ [0x0C01]: 'CP1256',
13
160
  [0x1001]: 'CP1256',
14
161
  [0x1401]: 'CP1256',
15
162
  [0x1801]: 'CP1256',
@@ -27,17 +174,9 @@ const codepageByLcid = {
27
174
  [0x423]: 'CP1251',
28
175
  [0x402]: 'CP1251',
29
176
  [0x403]: 'CP1252',
30
- [0x30404]: 'CP950',
31
- [0x404]: 'CP950',
32
- [0x804]: 'CP936',
33
- [0x20804]: 'CP936',
34
177
  [0x1004]: 'CP936',
35
- [0x41a]: 'CP1250',
36
- [0x405]: 'CP1250',
37
- [0x406]: 'CP1252',
38
178
  [0x413]: 'CP1252',
39
179
  [0x813]: 'CP1252',
40
- [0x409]: 'CP1252',
41
180
  [0x809]: 'CP1252',
42
181
  [0x1009]: 'CP1252',
43
182
  [0x1409]: 'CP1252',
@@ -46,52 +185,25 @@ const codepageByLcid = {
46
185
  [0x1C09]: 'CP1252',
47
186
  [0x2409]: 'CP1252',
48
187
  [0x2009]: 'CP1252',
49
- [0x425]: 'CP1257',
50
188
  [0x0438]: 'CP1252',
51
- [0x429]: 'CP1256',
52
- [0x40B]: 'CP1252',
53
- [0x40C]: 'CP1252',
54
189
  [0x80C]: 'CP1252',
55
190
  [0x100C]: 'CP1252',
56
191
  [0xC0C]: 'CP1252',
57
192
  [0x140C]: 'CP1252',
58
- [0x10437]: 'CP1252',
59
- [0x10407]: 'CP1252',
60
- [0x407]: 'CP1252',
61
193
  [0x807]: 'CP1252',
62
194
  [0xC07]: 'CP1252',
63
195
  [0x1007]: 'CP1252',
64
196
  [0x1407]: 'CP1252',
65
- [0x408]: 'CP1253',
66
- [0x40D]: 'CP1255',
67
197
  [0x439]: 'CPUTF8',
68
- [0x40E]: 'CP1250',
69
198
  [0x104E]: 'CP1250',
70
- [0x40F]: 'CP1252',
71
199
  [0x421]: 'CP1252',
72
200
  [0x410]: 'CP1252',
73
201
  [0x810]: 'CP1252',
74
- [0x411]: 'CP932',
75
- [0x10411]: 'CP932',
76
- [0x412]: 'CP949',
77
- [0x426]: 'CP1257',
78
- [0x427]: 'CP1257',
79
202
  [0x827]: 'CP1257',
80
- [0x41C]: 'CP1251',
81
- [0x414]: 'CP1252',
82
203
  [0x814]: 'CP1252',
83
- [0x415]: 'CP1250',
84
204
  [0x816]: 'CP1252',
85
205
  [0x416]: 'CP1252',
86
- [0x418]: 'CP1250',
87
- [0x419]: 'CP1251',
88
- [0x81A]: 'CP1251',
89
- [0xC1A]: 'CP1251',
90
- [0x41B]: 'CP1250',
91
- [0x424]: 'CP1250',
92
206
  [0x80A]: 'CP1252',
93
- [0x40A]: 'CP1252',
94
- [0xC0A]: 'CP1252',
95
207
  [0x100A]: 'CP1252',
96
208
  [0x140A]: 'CP1252',
97
209
  [0x180A]: 'CP1252',
@@ -105,12 +217,7 @@ const codepageByLcid = {
105
217
  [0x380A]: 'CP1252',
106
218
  [0x3C0A]: 'CP1252',
107
219
  [0x400A]: 'CP1252',
108
- [0x41D]: 'CP1252',
109
- [0x41E]: 'CP874',
110
- [0x41F]: 'CP1254',
111
- [0x422]: 'CP1251',
112
- [0x420]: 'CP1256',
113
- [0x42A]: 'CP1258'
220
+ [0x41D]: 'CP1252'
114
221
  };
115
222
  exports.codepageByLcid = codepageByLcid;
116
223
  const codepageBySortId = {
package/lib/connection.js CHANGED
@@ -109,7 +109,7 @@ const DEFAULT_PACKET_SIZE = 4 * 1024;
109
109
  * @private
110
110
  */
111
111
 
112
- const DEFAULT_TEXTSIZE = '2147483647';
112
+ const DEFAULT_TEXTSIZE = 2147483647;
113
113
  /**
114
114
  * @private
115
115
  */
@@ -930,7 +930,13 @@ class Connection extends _events.EventEmitter {
930
930
  throw new TypeError('The "config.options.textsize" property must be of type number or null.');
931
931
  }
932
932
 
933
- this.config.options.textsize = config.options.textsize;
933
+ if (config.options.textsize > 2147483647) {
934
+ throw new TypeError('The "config.options.textsize" can\'t be greater than 2147483647.');
935
+ } else if (config.options.textsize < -1) {
936
+ throw new TypeError('The "config.options.textsize" can\'t be smaller than -1.');
937
+ }
938
+
939
+ this.config.options.textsize = config.options.textsize | 0;
934
940
  }
935
941
 
936
942
  if (config.options.trustServerCertificate !== undefined) {
@@ -2053,16 +2059,69 @@ class Connection extends _events.EventEmitter {
2053
2059
  return new _bulkLoad.default(table, this.config.options, options, callback);
2054
2060
  }
2055
2061
  /**
2056
- * Executes a [[BulkLoad]].
2062
+ * Execute a [[BulkLoad]].
2063
+ *
2064
+ * ```js
2065
+ * // We want to perform a bulk load into a table with the following format:
2066
+ * // CREATE TABLE employees (first_name nvarchar(255), last_name nvarchar(255), day_of_birth date);
2067
+ *
2068
+ * const bulkLoad = connection.newBulkLoad('employees', (err, rowCount) => {
2069
+ * // ...
2070
+ * });
2071
+ *
2072
+ * // First, we need to specify the columns that we want to write to,
2073
+ * // and their definitions. These definitions must match the actual table,
2074
+ * // otherwise the bulk load will fail.
2075
+ * bulkLoad.addColumn('first_name', TYPES.NVarchar, { nullable: false });
2076
+ * bulkLoad.addColumn('last_name', TYPES.NVarchar, { nullable: false });
2077
+ * bulkLoad.addColumn('date_of_birth', TYPES.Date, { nullable: false });
2078
+ *
2079
+ * // Now, we can specify each row to be written.
2080
+ * //
2081
+ * // Note that these rows are held in memory until the
2082
+ * // bulk load was performed, so if you need to write a large
2083
+ * // number of rows (e.g. by reading from a CSV file),
2084
+ * // using a streaming bulk load is advisable to keep memory usage low.
2085
+ * bulkLoad.addRow({ 'first_name': 'Steve', 'last_name': 'Jobs', 'day_of_birth': new Date('02-24-1955') });
2086
+ * bulkLoad.addRow({ 'first_name': 'Bill', 'last_name': 'Gates', 'day_of_birth': new Date('10-28-1955') });
2087
+ *
2088
+ * connection.execBulkLoad(bulkLoad);
2089
+ * ```
2057
2090
  *
2058
- * @param bulkLoad
2091
+ * @param bulkLoad A previously created [[BulkLoad]].
2092
+ *
2093
+ * @deprecated Adding rows to a [[BulkLoad]] via [[BulkLoad.addRow]] or [[BulkLoad.getRowStream]]
2094
+ * is deprecated and will be removed in the future. You should migrate to calling [[Connection.execBulkLoad]]
2095
+ * with a `Iterable` or `AsyncIterable` as the second argument instead.
2059
2096
  */
2060
2097
 
2061
2098
 
2062
- execBulkLoad(bulkLoad) {
2099
+ execBulkLoad(bulkLoad, rows) {
2063
2100
  bulkLoad.executionStarted = true;
2064
2101
 
2065
- if (!bulkLoad.streamingMode) {
2102
+ if (rows) {
2103
+ if (bulkLoad.streamingMode) {
2104
+ throw new Error("Connection.execBulkLoad can't be called with a BulkLoad that was put in streaming mode.");
2105
+ }
2106
+
2107
+ if (bulkLoad.firstRowWritten) {
2108
+ throw new Error("Connection.execBulkLoad can't be called with a BulkLoad that already has rows written to it.");
2109
+ }
2110
+
2111
+ const rowStream = _stream.Readable.from(rows); // Destroy the packet transform if an error happens in the row stream,
2112
+ // e.g. if an error is thrown from within a generator or stream.
2113
+
2114
+
2115
+ rowStream.on('error', err => {
2116
+ bulkLoad.rowToPacketTransform.destroy(err);
2117
+ }); // Destroy the row stream if an error happens in the packet transform,
2118
+ // e.g. if the bulk load is cancelled.
2119
+
2120
+ bulkLoad.rowToPacketTransform.on('error', err => {
2121
+ rowStream.destroy(err);
2122
+ });
2123
+ rowStream.pipe(bulkLoad.rowToPacketTransform);
2124
+ } else if (!bulkLoad.streamingMode) {
2066
2125
  // If the bulkload was not put into streaming mode by the user,
2067
2126
  // we end the rowToPacketTransform here for them.
2068
2127
  //
@@ -2501,6 +2560,7 @@ class Connection extends _events.EventEmitter {
2501
2560
  payloadStream.unpipe(message); // Only set a request error if no error was set yet.
2502
2561
 
2503
2562
  (_request$error = request.error) !== null && _request$error !== void 0 ? _request$error : request.error = error;
2563
+ payloadStream.unpipe(message);
2504
2564
  message.ignore = true;
2505
2565
  message.end();
2506
2566
  });
@@ -36,7 +36,7 @@ const Image = {
36
36
  }
37
37
 
38
38
  const buffer = Buffer.alloc(4);
39
- buffer.writeInt32LE(parameter.length, 0);
39
+ buffer.writeInt32LE(parameter.value.length, 0);
40
40
  return buffer;
41
41
  },
42
42
 
@@ -4,32 +4,65 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ const NULL_LENGTH = Buffer.from([0xFF, 0xFF, 0xFF, 0xFF]);
7
8
  const NText = {
8
9
  id: 0x63,
9
10
  type: 'NTEXT',
10
11
  name: 'NText',
11
12
  hasTableName: true,
13
+ declaration: function () {
14
+ return 'ntext';
15
+ },
16
+ resolveLength: function (parameter) {
17
+ const value = parameter.value; // Temporary solution. Remove 'any' later.
12
18
 
13
- declaration() {
14
- throw new Error('not implemented');
19
+ if (value != null) {
20
+ return value.length;
21
+ } else {
22
+ return -1;
23
+ }
15
24
  },
16
25
 
17
- generateTypeInfo() {
18
- throw new Error('not implemented');
26
+ generateTypeInfo(parameter, _options) {
27
+ const buffer = Buffer.alloc(10);
28
+ buffer.writeUInt8(this.id, 0);
29
+ buffer.writeInt32LE(parameter.length, 1); // TODO: Collation handling
30
+
31
+ return buffer;
19
32
  },
20
33
 
21
- generateParameterLength() {
22
- throw new Error('not implemented');
34
+ generateParameterLength(parameter, options) {
35
+ if (parameter.value == null) {
36
+ return NULL_LENGTH;
37
+ }
38
+
39
+ const buffer = Buffer.alloc(4);
40
+ buffer.writeInt32LE(Buffer.byteLength(parameter.value, 'ucs2'), 0);
41
+ return buffer;
23
42
  },
24
43
 
25
- generateParameterData() {
26
- throw new Error('not implemented');
44
+ generateParameterData: function* (parameter, options) {
45
+ if (parameter.value == null) {
46
+ return;
47
+ }
48
+
49
+ yield Buffer.from(parameter.value.toString(), 'ucs2');
27
50
  },
51
+ validate: function (value) {
52
+ if (value == null) {
53
+ return null;
54
+ }
28
55
 
29
- validate() {
30
- throw new Error('not implemented');
31
- }
56
+ if (typeof value !== 'string') {
57
+ if (typeof value.toString !== 'function') {
58
+ throw new TypeError('Invalid string.');
59
+ }
60
+
61
+ value = value.toString();
62
+ }
32
63
 
64
+ return value;
65
+ }
33
66
  };
34
67
  var _default = NText;
35
68
  exports.default = _default;
@@ -37,7 +37,7 @@ const Text = {
37
37
  }
38
38
 
39
39
  const buffer = Buffer.alloc(4);
40
- buffer.writeInt32LE(parameter.length, 0);
40
+ buffer.writeInt32LE(parameter.value.length, 0);
41
41
  return buffer;
42
42
  },
43
43
 
package/package.json CHANGED
@@ -27,7 +27,7 @@
27
27
  "homepage": "https://github.com/tediousjs/tedious",
28
28
  "bugs": "https://github.com/tediousjs/tedious/issues",
29
29
  "license": "MIT",
30
- "version": "11.5.0",
30
+ "version": "11.8.0",
31
31
  "main": "./lib/tedious.js",
32
32
  "repository": {
33
33
  "type": "git",