tedious 2.2.0 → 2.2.4
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 +1 -1
- package/lib/bulk-load.js +1 -1
- package/lib/connection.js +148 -131
- package/lib/data-type.js +79 -1669
- package/lib/data-types/bigint.js +46 -0
- package/lib/data-types/binary.js +57 -0
- package/lib/data-types/bit.js +38 -0
- package/lib/data-types/bitn.js +8 -0
- package/lib/data-types/char.js +72 -0
- package/lib/data-types/daten.js +48 -0
- package/lib/data-types/datetime.js +68 -0
- package/lib/data-types/datetime2n.js +105 -0
- package/lib/data-types/datetimen.js +8 -0
- package/lib/data-types/datetimeoffsetn.js +91 -0
- package/lib/data-types/decimal.js +88 -0
- package/lib/data-types/decimaln.js +10 -0
- package/lib/data-types/float.js +38 -0
- package/lib/data-types/floatn.js +8 -0
- package/lib/data-types/image.js +46 -0
- package/lib/data-types/int.js +41 -0
- package/lib/data-types/intn.js +8 -0
- package/lib/data-types/money.js +38 -0
- package/lib/data-types/moneyn.js +8 -0
- package/lib/data-types/nchar.js +72 -0
- package/lib/data-types/ntext.js +11 -0
- package/lib/data-types/null.js +7 -0
- package/lib/data-types/numeric.js +88 -0
- package/lib/data-types/numericn.js +10 -0
- package/lib/data-types/nvarchar.js +86 -0
- package/lib/data-types/real.js +38 -0
- package/lib/data-types/smalldatetime.js +60 -0
- package/lib/data-types/smallint.js +41 -0
- package/lib/data-types/smallmoney.js +41 -0
- package/lib/data-types/sql-variant.js +12 -0
- package/lib/data-types/text.js +51 -0
- package/lib/data-types/timen.js +95 -0
- package/lib/data-types/tinyint.js +41 -0
- package/lib/data-types/tvp.js +83 -0
- package/lib/data-types/udt.js +8 -0
- package/lib/data-types/uniqueidentifiern.js +46 -0
- package/lib/data-types/varbinary.js +77 -0
- package/lib/data-types/varchar.js +86 -0
- package/lib/data-types/xml.js +8 -0
- package/lib/instance-lookup.js +8 -7
- package/lib/message-io.js +1 -1
- package/lib/ntlm-payload.js +5 -5
- package/lib/packet.js +3 -3
- package/lib/prelogin-payload.js +7 -7
- package/lib/request.js +37 -16
- package/lib/tracking-buffer/bigint.js +1 -1
- package/lib/tracking-buffer/writable-tracking-buffer.js +52 -48
- package/lib/value-parser.js +13 -13
- package/package.json +1 -1
package/lib/request.js
CHANGED
|
@@ -26,6 +26,9 @@ var EventEmitter = require('events').EventEmitter;
|
|
|
26
26
|
var TYPES = require('./data-type').typeByName;
|
|
27
27
|
var RequestError = require('./errors').RequestError;
|
|
28
28
|
|
|
29
|
+
// TODO: Figure out how to type the `rows` parameter here.
|
|
30
|
+
|
|
31
|
+
|
|
29
32
|
module.exports = function (_EventEmitter) {
|
|
30
33
|
(0, _inherits3.default)(Request, _EventEmitter);
|
|
31
34
|
|
|
@@ -37,21 +40,36 @@ module.exports = function (_EventEmitter) {
|
|
|
37
40
|
_this.sqlTextOrProcedure = sqlTextOrProcedure;
|
|
38
41
|
_this.parameters = [];
|
|
39
42
|
_this.parametersByName = {};
|
|
43
|
+
_this.originalParameters = [];
|
|
44
|
+
_this.preparing = false;
|
|
45
|
+
_this.handle = undefined;
|
|
40
46
|
_this.canceled = false;
|
|
41
47
|
_this.paused = false;
|
|
48
|
+
_this.error = undefined;
|
|
49
|
+
_this.connection = undefined;
|
|
42
50
|
_this.userCallback = callback;
|
|
43
|
-
_this.callback = function () {
|
|
51
|
+
_this.callback = function (err) {
|
|
44
52
|
if (this.preparing) {
|
|
45
|
-
this.
|
|
46
|
-
|
|
53
|
+
this.preparing = false;
|
|
54
|
+
if (err) {
|
|
55
|
+
this.emit('error', err);
|
|
56
|
+
} else {
|
|
57
|
+
this.emit('prepared');
|
|
58
|
+
}
|
|
47
59
|
} else {
|
|
48
60
|
this.userCallback.apply(this, arguments);
|
|
49
|
-
|
|
61
|
+
this.emit('requestCompleted');
|
|
50
62
|
}
|
|
51
63
|
};
|
|
52
64
|
return _this;
|
|
53
65
|
}
|
|
54
66
|
|
|
67
|
+
// TODO: `type` must be a valid TDS value type
|
|
68
|
+
// TODO: This should be `Connection`, not `any`.
|
|
69
|
+
|
|
70
|
+
// TODO: Figure out the type here.
|
|
71
|
+
|
|
72
|
+
|
|
55
73
|
(0, _createClass3.default)(Request, [{
|
|
56
74
|
key: 'addParameter',
|
|
57
75
|
value: function addParameter(name, type, value, options) {
|
|
@@ -69,8 +87,11 @@ module.exports = function (_EventEmitter) {
|
|
|
69
87
|
scale: options.scale
|
|
70
88
|
};
|
|
71
89
|
this.parameters.push(parameter);
|
|
72
|
-
|
|
90
|
+
this.parametersByName[name] = parameter;
|
|
73
91
|
}
|
|
92
|
+
|
|
93
|
+
// TODO: `type` must be a valid TDS value type
|
|
94
|
+
|
|
74
95
|
}, {
|
|
75
96
|
key: 'addOutputParameter',
|
|
76
97
|
value: function addOutputParameter(name, type, value, options) {
|
|
@@ -78,7 +99,7 @@ module.exports = function (_EventEmitter) {
|
|
|
78
99
|
options = {};
|
|
79
100
|
}
|
|
80
101
|
options.output = true;
|
|
81
|
-
|
|
102
|
+
this.addParameter(name, type, value, options);
|
|
82
103
|
}
|
|
83
104
|
}, {
|
|
84
105
|
key: 'makeParamsParameter',
|
|
@@ -115,7 +136,7 @@ module.exports = function (_EventEmitter) {
|
|
|
115
136
|
var parameter = this.originalParameters[i];
|
|
116
137
|
this.parameters.push(parameter);
|
|
117
138
|
}
|
|
118
|
-
|
|
139
|
+
this.sqlTextOrProcedure = 'sp_executesql';
|
|
119
140
|
}
|
|
120
141
|
}, {
|
|
121
142
|
key: 'transformIntoPrepareRpc',
|
|
@@ -129,11 +150,11 @@ module.exports = function (_EventEmitter) {
|
|
|
129
150
|
this.addParameter('stmt', TYPES.NVarChar, this.sqlTextOrProcedure);
|
|
130
151
|
this.sqlTextOrProcedure = 'sp_prepare';
|
|
131
152
|
this.preparing = true;
|
|
132
|
-
|
|
153
|
+
this.on('returnValue', function (name, value) {
|
|
133
154
|
if (name === 'handle') {
|
|
134
|
-
|
|
155
|
+
_this2.handle = value;
|
|
135
156
|
} else {
|
|
136
|
-
|
|
157
|
+
_this2.error = RequestError(`Tedious > Unexpected output parameter ${name} from sp_prepare`);
|
|
137
158
|
}
|
|
138
159
|
});
|
|
139
160
|
}
|
|
@@ -142,7 +163,7 @@ module.exports = function (_EventEmitter) {
|
|
|
142
163
|
value: function transformIntoUnprepareRpc() {
|
|
143
164
|
this.parameters = [];
|
|
144
165
|
this.addParameter('handle', TYPES.Int, this.handle);
|
|
145
|
-
|
|
166
|
+
this.sqlTextOrProcedure = 'sp_unprepare';
|
|
146
167
|
}
|
|
147
168
|
}, {
|
|
148
169
|
key: 'transformIntoExecuteRpc',
|
|
@@ -160,18 +181,18 @@ module.exports = function (_EventEmitter) {
|
|
|
160
181
|
return;
|
|
161
182
|
}
|
|
162
183
|
|
|
163
|
-
|
|
184
|
+
this.sqlTextOrProcedure = 'sp_execute';
|
|
164
185
|
}
|
|
165
186
|
}, {
|
|
166
187
|
key: 'validateParameters',
|
|
167
188
|
value: function validateParameters() {
|
|
168
189
|
for (var i = 0, len = this.parameters.length; i < len; i++) {
|
|
169
190
|
var parameter = this.parameters[i];
|
|
170
|
-
var
|
|
171
|
-
if (
|
|
172
|
-
return this.error = new RequestError('Validation failed for parameter \'' + parameter.name + '\'. ' +
|
|
191
|
+
var _value = parameter.type.validate(parameter.value);
|
|
192
|
+
if (_value instanceof TypeError) {
|
|
193
|
+
return this.error = new RequestError('Validation failed for parameter \'' + parameter.name + '\'. ' + _value.message, 'EPARAM');
|
|
173
194
|
}
|
|
174
|
-
parameter.value =
|
|
195
|
+
parameter.value = _value;
|
|
175
196
|
}
|
|
176
197
|
return null;
|
|
177
198
|
}
|
|
@@ -70,7 +70,7 @@ function numberToInt64LE(num) {
|
|
|
70
70
|
var hi = Math.abs(num);
|
|
71
71
|
var lo = hi % 0x100000000;
|
|
72
72
|
hi = hi / 0x100000000 | 0;
|
|
73
|
-
var buf = new Buffer(8);
|
|
73
|
+
var buf = new Buffer(8).fill(0);
|
|
74
74
|
for (var i = 0; i <= 7; i++) {
|
|
75
75
|
buf[i] = lo & 0xff;
|
|
76
76
|
lo = i === 3 ? hi : lo >>> 8;
|
|
@@ -28,21 +28,23 @@ module.exports = function () {
|
|
|
28
28
|
(0, _classCallCheck3.default)(this, WritableTrackingBuffer);
|
|
29
29
|
|
|
30
30
|
this.initialSize = initialSize;
|
|
31
|
-
this.encoding = encoding;
|
|
32
|
-
this.doubleSizeGrowth = doubleSizeGrowth;
|
|
33
|
-
this.
|
|
34
|
-
this.
|
|
35
|
-
this.buffer = new Buffer(this.initialSize);
|
|
31
|
+
this.encoding = encoding || 'ucs2';
|
|
32
|
+
this.doubleSizeGrowth = doubleSizeGrowth || false;
|
|
33
|
+
this.buffer = new Buffer(this.initialSize).fill(0);
|
|
34
|
+
this.compositeBuffer = new Buffer(0);
|
|
36
35
|
this.position = 0;
|
|
37
36
|
}
|
|
38
37
|
|
|
38
|
+
// $FlowFixMe: Flow does not like getter/setters that have side-effects.
|
|
39
|
+
|
|
40
|
+
|
|
39
41
|
(0, _createClass3.default)(WritableTrackingBuffer, [{
|
|
40
42
|
key: 'copyFrom',
|
|
41
43
|
value: function copyFrom(buffer) {
|
|
42
44
|
var length = buffer.length;
|
|
43
45
|
this.makeRoomFor(length);
|
|
44
46
|
buffer.copy(this.buffer, this.position);
|
|
45
|
-
|
|
47
|
+
this.position += length;
|
|
46
48
|
}
|
|
47
49
|
}, {
|
|
48
50
|
key: 'makeRoomFor',
|
|
@@ -53,9 +55,9 @@ module.exports = function () {
|
|
|
53
55
|
while (size < requiredLength) {
|
|
54
56
|
size *= 2;
|
|
55
57
|
}
|
|
56
|
-
|
|
58
|
+
this.newBuffer(size);
|
|
57
59
|
} else {
|
|
58
|
-
|
|
60
|
+
this.newBuffer(requiredLength);
|
|
59
61
|
}
|
|
60
62
|
}
|
|
61
63
|
}
|
|
@@ -63,13 +65,9 @@ module.exports = function () {
|
|
|
63
65
|
key: 'newBuffer',
|
|
64
66
|
value: function newBuffer(size) {
|
|
65
67
|
var buffer = this.buffer.slice(0, this.position);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this.compositeBuffer = buffer;
|
|
70
|
-
}
|
|
71
|
-
this.buffer = size === 0 ? ZERO_LENGTH_BUFFER : new Buffer(size);
|
|
72
|
-
return this.position = 0;
|
|
68
|
+
this.compositeBuffer = Buffer.concat([this.compositeBuffer, buffer]);
|
|
69
|
+
this.buffer = size === 0 ? ZERO_LENGTH_BUFFER : new Buffer(size).fill(0);
|
|
70
|
+
this.position = 0;
|
|
73
71
|
}
|
|
74
72
|
}, {
|
|
75
73
|
key: 'writeUInt8',
|
|
@@ -77,7 +75,7 @@ module.exports = function () {
|
|
|
77
75
|
var length = 1;
|
|
78
76
|
this.makeRoomFor(length);
|
|
79
77
|
this.buffer.writeUInt8(value, this.position);
|
|
80
|
-
|
|
78
|
+
this.position += length;
|
|
81
79
|
}
|
|
82
80
|
}, {
|
|
83
81
|
key: 'writeUInt16LE',
|
|
@@ -85,12 +83,12 @@ module.exports = function () {
|
|
|
85
83
|
var length = 2;
|
|
86
84
|
this.makeRoomFor(length);
|
|
87
85
|
this.buffer.writeUInt16LE(value, this.position);
|
|
88
|
-
|
|
86
|
+
this.position += length;
|
|
89
87
|
}
|
|
90
88
|
}, {
|
|
91
89
|
key: 'writeUShort',
|
|
92
90
|
value: function writeUShort(value) {
|
|
93
|
-
|
|
91
|
+
this.writeUInt16LE(value);
|
|
94
92
|
}
|
|
95
93
|
}, {
|
|
96
94
|
key: 'writeUInt16BE',
|
|
@@ -98,7 +96,7 @@ module.exports = function () {
|
|
|
98
96
|
var length = 2;
|
|
99
97
|
this.makeRoomFor(length);
|
|
100
98
|
this.buffer.writeUInt16BE(value, this.position);
|
|
101
|
-
|
|
99
|
+
this.position += length;
|
|
102
100
|
}
|
|
103
101
|
}, {
|
|
104
102
|
key: 'writeUInt24LE',
|
|
@@ -108,7 +106,7 @@ module.exports = function () {
|
|
|
108
106
|
this.buffer[this.position + 2] = value >>> 16 & 0xff;
|
|
109
107
|
this.buffer[this.position + 1] = value >>> 8 & 0xff;
|
|
110
108
|
this.buffer[this.position] = value & 0xff;
|
|
111
|
-
|
|
109
|
+
this.position += length;
|
|
112
110
|
}
|
|
113
111
|
}, {
|
|
114
112
|
key: 'writeUInt32LE',
|
|
@@ -116,13 +114,13 @@ module.exports = function () {
|
|
|
116
114
|
var length = 4;
|
|
117
115
|
this.makeRoomFor(length);
|
|
118
116
|
this.buffer.writeUInt32LE(value, this.position);
|
|
119
|
-
|
|
117
|
+
this.position += length;
|
|
120
118
|
}
|
|
121
119
|
}, {
|
|
122
120
|
key: 'writeInt64LE',
|
|
123
121
|
value: function writeInt64LE(value) {
|
|
124
122
|
var buf = bigint.numberToInt64LE(value);
|
|
125
|
-
|
|
123
|
+
this.copyFrom(buf);
|
|
126
124
|
}
|
|
127
125
|
}, {
|
|
128
126
|
key: 'writeUInt32BE',
|
|
@@ -130,20 +128,20 @@ module.exports = function () {
|
|
|
130
128
|
var length = 4;
|
|
131
129
|
this.makeRoomFor(length);
|
|
132
130
|
this.buffer.writeUInt32BE(value, this.position);
|
|
133
|
-
|
|
131
|
+
this.position += length;
|
|
134
132
|
}
|
|
135
133
|
}, {
|
|
136
134
|
key: 'writeUInt40LE',
|
|
137
135
|
value: function writeUInt40LE(value) {
|
|
138
136
|
// inspired by https://github.com/dpw/node-buffer-more-ints
|
|
139
137
|
this.writeInt32LE(value & -1);
|
|
140
|
-
|
|
138
|
+
this.writeUInt8(Math.floor(value * SHIFT_RIGHT_32));
|
|
141
139
|
}
|
|
142
140
|
}, {
|
|
143
141
|
key: 'writeUInt64LE',
|
|
144
142
|
value: function writeUInt64LE(value) {
|
|
145
143
|
this.writeInt32LE(value & -1);
|
|
146
|
-
|
|
144
|
+
this.writeUInt32LE(Math.floor(value * SHIFT_RIGHT_32));
|
|
147
145
|
}
|
|
148
146
|
}, {
|
|
149
147
|
key: 'writeInt8',
|
|
@@ -151,7 +149,7 @@ module.exports = function () {
|
|
|
151
149
|
var length = 1;
|
|
152
150
|
this.makeRoomFor(length);
|
|
153
151
|
this.buffer.writeInt8(value, this.position);
|
|
154
|
-
|
|
152
|
+
this.position += length;
|
|
155
153
|
}
|
|
156
154
|
}, {
|
|
157
155
|
key: 'writeInt16LE',
|
|
@@ -159,7 +157,7 @@ module.exports = function () {
|
|
|
159
157
|
var length = 2;
|
|
160
158
|
this.makeRoomFor(length);
|
|
161
159
|
this.buffer.writeInt16LE(value, this.position);
|
|
162
|
-
|
|
160
|
+
this.position += length;
|
|
163
161
|
}
|
|
164
162
|
}, {
|
|
165
163
|
key: 'writeInt16BE',
|
|
@@ -167,7 +165,7 @@ module.exports = function () {
|
|
|
167
165
|
var length = 2;
|
|
168
166
|
this.makeRoomFor(length);
|
|
169
167
|
this.buffer.writeInt16BE(value, this.position);
|
|
170
|
-
|
|
168
|
+
this.position += length;
|
|
171
169
|
}
|
|
172
170
|
}, {
|
|
173
171
|
key: 'writeInt32LE',
|
|
@@ -175,7 +173,7 @@ module.exports = function () {
|
|
|
175
173
|
var length = 4;
|
|
176
174
|
this.makeRoomFor(length);
|
|
177
175
|
this.buffer.writeInt32LE(value, this.position);
|
|
178
|
-
|
|
176
|
+
this.position += length;
|
|
179
177
|
}
|
|
180
178
|
}, {
|
|
181
179
|
key: 'writeInt32BE',
|
|
@@ -183,7 +181,7 @@ module.exports = function () {
|
|
|
183
181
|
var length = 4;
|
|
184
182
|
this.makeRoomFor(length);
|
|
185
183
|
this.buffer.writeInt32BE(value, this.position);
|
|
186
|
-
|
|
184
|
+
this.position += length;
|
|
187
185
|
}
|
|
188
186
|
}, {
|
|
189
187
|
key: 'writeFloatLE',
|
|
@@ -191,7 +189,7 @@ module.exports = function () {
|
|
|
191
189
|
var length = 4;
|
|
192
190
|
this.makeRoomFor(length);
|
|
193
191
|
this.buffer.writeFloatLE(value, this.position);
|
|
194
|
-
|
|
192
|
+
this.position += length;
|
|
195
193
|
}
|
|
196
194
|
}, {
|
|
197
195
|
key: 'writeDoubleLE',
|
|
@@ -199,42 +197,46 @@ module.exports = function () {
|
|
|
199
197
|
var length = 8;
|
|
200
198
|
this.makeRoomFor(length);
|
|
201
199
|
this.buffer.writeDoubleLE(value, this.position);
|
|
202
|
-
|
|
200
|
+
this.position += length;
|
|
203
201
|
}
|
|
204
202
|
}, {
|
|
205
203
|
key: 'writeString',
|
|
206
204
|
value: function writeString(value, encoding) {
|
|
207
|
-
|
|
205
|
+
if (encoding == undefined) {
|
|
206
|
+
encoding = this.encoding;
|
|
207
|
+
}
|
|
208
208
|
|
|
209
209
|
var length = Buffer.byteLength(value, encoding);
|
|
210
210
|
this.makeRoomFor(length);
|
|
211
211
|
|
|
212
|
-
|
|
212
|
+
// $FlowFixMe https://github.com/facebook/flow/pull/5398
|
|
213
|
+
this.buffer.write(value, this.position, encoding);
|
|
213
214
|
this.position += length;
|
|
214
|
-
|
|
215
|
-
return bytesWritten;
|
|
216
215
|
}
|
|
217
216
|
}, {
|
|
218
217
|
key: 'writeBVarchar',
|
|
219
218
|
value: function writeBVarchar(value, encoding) {
|
|
220
219
|
this.writeUInt8(value.length);
|
|
221
|
-
|
|
220
|
+
this.writeString(value, encoding);
|
|
222
221
|
}
|
|
223
222
|
}, {
|
|
224
223
|
key: 'writeUsVarchar',
|
|
225
224
|
value: function writeUsVarchar(value, encoding) {
|
|
226
225
|
this.writeUInt16LE(value.length);
|
|
227
|
-
|
|
226
|
+
this.writeString(value, encoding);
|
|
228
227
|
}
|
|
228
|
+
|
|
229
|
+
// TODO: Figure out what types are passed in other than `Buffer`
|
|
230
|
+
|
|
229
231
|
}, {
|
|
230
232
|
key: 'writeUsVarbyte',
|
|
231
233
|
value: function writeUsVarbyte(value, encoding) {
|
|
232
|
-
if (encoding ==
|
|
234
|
+
if (encoding == undefined) {
|
|
233
235
|
encoding = this.encoding;
|
|
234
236
|
}
|
|
235
237
|
|
|
236
238
|
var length = void 0;
|
|
237
|
-
if (Buffer
|
|
239
|
+
if (value instanceof Buffer) {
|
|
238
240
|
length = value.length;
|
|
239
241
|
} else {
|
|
240
242
|
value = value.toString();
|
|
@@ -242,12 +244,13 @@ module.exports = function () {
|
|
|
242
244
|
}
|
|
243
245
|
this.writeUInt16LE(length);
|
|
244
246
|
|
|
245
|
-
if (Buffer
|
|
246
|
-
|
|
247
|
+
if (value instanceof Buffer) {
|
|
248
|
+
this.writeBuffer(value);
|
|
247
249
|
} else {
|
|
248
250
|
this.makeRoomFor(length);
|
|
251
|
+
// $FlowFixMe https://github.com/facebook/flow/pull/5398
|
|
249
252
|
this.buffer.write(value, this.position, encoding);
|
|
250
|
-
|
|
253
|
+
this.position += length;
|
|
251
254
|
}
|
|
252
255
|
}
|
|
253
256
|
}, {
|
|
@@ -258,7 +261,7 @@ module.exports = function () {
|
|
|
258
261
|
}
|
|
259
262
|
|
|
260
263
|
var length = void 0;
|
|
261
|
-
if (Buffer
|
|
264
|
+
if (value instanceof Buffer) {
|
|
262
265
|
length = value.length;
|
|
263
266
|
} else {
|
|
264
267
|
value = value.toString();
|
|
@@ -274,17 +277,18 @@ module.exports = function () {
|
|
|
274
277
|
if (length > 0) {
|
|
275
278
|
// One chunk.
|
|
276
279
|
this.writeUInt32LE(length);
|
|
277
|
-
if (Buffer
|
|
280
|
+
if (value instanceof Buffer) {
|
|
278
281
|
this.writeBuffer(value);
|
|
279
282
|
} else {
|
|
280
283
|
this.makeRoomFor(length);
|
|
284
|
+
// $FlowFixMe https://github.com/facebook/flow/pull/5398
|
|
281
285
|
this.buffer.write(value, this.position, encoding);
|
|
282
286
|
this.position += length;
|
|
283
287
|
}
|
|
284
288
|
}
|
|
285
289
|
|
|
286
290
|
// PLP_TERMINATOR (no more chunks).
|
|
287
|
-
|
|
291
|
+
this.writeUInt32LE(0);
|
|
288
292
|
}
|
|
289
293
|
}, {
|
|
290
294
|
key: 'writeBuffer',
|
|
@@ -292,13 +296,13 @@ module.exports = function () {
|
|
|
292
296
|
var length = value.length;
|
|
293
297
|
this.makeRoomFor(length);
|
|
294
298
|
value.copy(this.buffer, this.position);
|
|
295
|
-
|
|
299
|
+
this.position += length;
|
|
296
300
|
}
|
|
297
301
|
}, {
|
|
298
302
|
key: 'writeMoney',
|
|
299
303
|
value: function writeMoney(value) {
|
|
300
304
|
this.writeInt32LE(Math.floor(value * SHIFT_RIGHT_32));
|
|
301
|
-
|
|
305
|
+
this.writeInt32LE(value & -1);
|
|
302
306
|
}
|
|
303
307
|
}, {
|
|
304
308
|
key: 'data',
|
package/lib/value-parser.js
CHANGED
|
@@ -185,7 +185,7 @@ function valueParse(parser, metaData, options, callback) {
|
|
|
185
185
|
if (metaData.dataLength === MAX) {
|
|
186
186
|
return readMaxChars(parser, codepage, callback);
|
|
187
187
|
} else {
|
|
188
|
-
return readChars(parser, dataLength, codepage, callback);
|
|
188
|
+
return readChars(parser, dataLength, codepage, NULL, callback);
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
case 'NVarChar':
|
|
@@ -193,7 +193,7 @@ function valueParse(parser, metaData, options, callback) {
|
|
|
193
193
|
if (metaData.dataLength === MAX) {
|
|
194
194
|
return readMaxNChars(parser, callback);
|
|
195
195
|
} else {
|
|
196
|
-
return readNChars(parser, dataLength, callback);
|
|
196
|
+
return readNChars(parser, dataLength, NULL, callback);
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
case 'VarBinary':
|
|
@@ -201,28 +201,28 @@ function valueParse(parser, metaData, options, callback) {
|
|
|
201
201
|
if (metaData.dataLength === MAX) {
|
|
202
202
|
return readMaxBinary(parser, callback);
|
|
203
203
|
} else {
|
|
204
|
-
return readBinary(parser, dataLength, callback);
|
|
204
|
+
return readBinary(parser, dataLength, NULL, callback);
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
case 'Text':
|
|
208
208
|
if (textPointerNull) {
|
|
209
209
|
return callback(null);
|
|
210
210
|
} else {
|
|
211
|
-
return readChars(parser, dataLength, metaData.collation.codepage, callback);
|
|
211
|
+
return readChars(parser, dataLength, metaData.collation.codepage, PLP_NULL, callback);
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
case 'NText':
|
|
215
215
|
if (textPointerNull) {
|
|
216
216
|
return callback(null);
|
|
217
217
|
} else {
|
|
218
|
-
return readNChars(parser, dataLength, callback);
|
|
218
|
+
return readNChars(parser, dataLength, PLP_NULL, callback);
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
case 'Image':
|
|
222
222
|
if (textPointerNull) {
|
|
223
223
|
return callback(null);
|
|
224
224
|
} else {
|
|
225
|
-
return readBinary(parser, dataLength, callback);
|
|
225
|
+
return readBinary(parser, dataLength, PLP_NULL, callback);
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
case 'Xml':
|
|
@@ -359,20 +359,20 @@ function valueParse(parser, metaData, options, callback) {
|
|
|
359
359
|
});
|
|
360
360
|
}
|
|
361
361
|
|
|
362
|
-
function readBinary(parser, dataLength, callback) {
|
|
363
|
-
if (dataLength ===
|
|
362
|
+
function readBinary(parser, dataLength, nullValue, callback) {
|
|
363
|
+
if (dataLength === nullValue) {
|
|
364
364
|
return callback(null);
|
|
365
365
|
} else {
|
|
366
366
|
return parser.readBuffer(dataLength, callback);
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
369
|
|
|
370
|
-
function readChars(parser, dataLength, codepage, callback) {
|
|
370
|
+
function readChars(parser, dataLength, codepage, nullValue, callback) {
|
|
371
371
|
if (codepage == null) {
|
|
372
372
|
codepage = DEFAULT_ENCODING;
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
-
if (dataLength ===
|
|
375
|
+
if (dataLength === nullValue) {
|
|
376
376
|
return callback(null);
|
|
377
377
|
} else {
|
|
378
378
|
return parser.readBuffer(dataLength, function (data) {
|
|
@@ -381,8 +381,8 @@ function readChars(parser, dataLength, codepage, callback) {
|
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
-
function readNChars(parser, dataLength, callback) {
|
|
385
|
-
if (dataLength ===
|
|
384
|
+
function readNChars(parser, dataLength, nullValue, callback) {
|
|
385
|
+
if (dataLength === nullValue) {
|
|
386
386
|
return callback(null);
|
|
387
387
|
} else {
|
|
388
388
|
return parser.readBuffer(dataLength, function (data) {
|
|
@@ -440,7 +440,7 @@ function readMax(parser, callback) {
|
|
|
440
440
|
}
|
|
441
441
|
|
|
442
442
|
function readMaxKnownLength(parser, totalLength, callback) {
|
|
443
|
-
var data = new Buffer(totalLength);
|
|
443
|
+
var data = new Buffer(totalLength).fill(0);
|
|
444
444
|
|
|
445
445
|
var offset = 0;
|
|
446
446
|
function next(done) {
|
package/package.json
CHANGED