teradatasql 20.0.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.
- package/LICENSE +196 -0
- package/README.md +1447 -0
- package/THIRDPARTYLICENSE +40 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +50 -0
- package/lib/index.js.map +1 -0
- package/lib/teradata-connection.d.ts +74 -0
- package/lib/teradata-connection.d.ts.map +1 -0
- package/lib/teradata-connection.js +280 -0
- package/lib/teradata-connection.js.map +1 -0
- package/lib/teradata-cursor.d.ts +58 -0
- package/lib/teradata-cursor.d.ts.map +1 -0
- package/lib/teradata-cursor.js +746 -0
- package/lib/teradata-cursor.js.map +1 -0
- package/lib/teradata-exceptions.d.ts +19 -0
- package/lib/teradata-exceptions.d.ts.map +1 -0
- package/lib/teradata-exceptions.js +52 -0
- package/lib/teradata-exceptions.js.map +1 -0
- package/lib/teradata-logging.d.ts +23 -0
- package/lib/teradata-logging.d.ts.map +1 -0
- package/lib/teradata-logging.js +79 -0
- package/lib/teradata-logging.js.map +1 -0
- package/lib/teradatasql.dll +0 -0
- package/lib/teradatasql.dylib +0 -0
- package/lib/teradatasql.so +0 -0
- package/package.json +33 -0
- package/samples/AGKRBatchInsert.js +38 -0
- package/samples/AGKRInsertSelect.js +28 -0
- package/samples/BatchInsPerf.js +47 -0
- package/samples/BatchInsert.js +17 -0
- package/samples/BatchInsertCSV.js +54 -0
- package/samples/CharPadding.js +31 -0
- package/samples/CommitRollback.js +31 -0
- package/samples/DecimalDigits.js +49 -0
- package/samples/DriverDatabaseVersion.js +14 -0
- package/samples/ElicitFile.js +19 -0
- package/samples/ExportCSVResult.js +54 -0
- package/samples/ExportCSVResults.js +60 -0
- package/samples/FakeExportCSVResults.js +82 -0
- package/samples/FakeResultSetCon.js +72 -0
- package/samples/FakeResultSetEsc.js +72 -0
- package/samples/FastExportCSV.js +102 -0
- package/samples/FastExportTable.js +76 -0
- package/samples/FastLoadBatch.js +152 -0
- package/samples/FastLoadCSV.js +116 -0
- package/samples/HelpSession.js +18 -0
- package/samples/IgnoreErrors.js +125 -0
- package/samples/InsertLob.js +62 -0
- package/samples/InsertXML.js +37 -0
- package/samples/LoadCSVFile.js +41 -0
- package/samples/LobLocators.js +57 -0
- package/samples/MetadataFromPrepare.js +23 -0
- package/samples/ParamDataTypes.js +70 -0
- package/samples/ShowCommand.js +31 -0
- package/samples/StoredProc.js +77 -0
- package/samples/TJEncryptPassword.js +270 -0
- package/samples/airports.csv +9 -0
- package/samples/udfinc.c +6 -0
|
@@ -0,0 +1,746 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TeradataCursor = exports.STRING = exports.NUMBER = exports.DATE = exports.BINARY = void 0;
|
|
4
|
+
const teradata_logging_1 = require("./teradata-logging");
|
|
5
|
+
const teradata_exceptions_1 = require("./teradata-exceptions");
|
|
6
|
+
exports.BINARY = "Uint8Array";
|
|
7
|
+
exports.DATE = "Date";
|
|
8
|
+
exports.NUMBER = "number";
|
|
9
|
+
exports.STRING = "string";
|
|
10
|
+
class TeradataCursor {
|
|
11
|
+
constructor(connection, ffiLib, ffiRef, ffiByteArray) {
|
|
12
|
+
this.desc = null;
|
|
13
|
+
this.rowCount = 0n;
|
|
14
|
+
this.rowNumber = null;
|
|
15
|
+
this.uRowsHand = null;
|
|
16
|
+
this.arraySize = 1;
|
|
17
|
+
this.bClosed = false;
|
|
18
|
+
this.conn = connection;
|
|
19
|
+
this.lib = ffiLib;
|
|
20
|
+
this.ref = ffiRef;
|
|
21
|
+
this.byteArray = ffiByteArray;
|
|
22
|
+
this.logger = new teradata_logging_1.TeradataLogging(this.conn.uLog);
|
|
23
|
+
}
|
|
24
|
+
get description() {
|
|
25
|
+
return this.desc;
|
|
26
|
+
}
|
|
27
|
+
get rowcount() {
|
|
28
|
+
return this.rowCount;
|
|
29
|
+
}
|
|
30
|
+
get rownumber() {
|
|
31
|
+
return this.rowNumber;
|
|
32
|
+
}
|
|
33
|
+
get connection() {
|
|
34
|
+
return this.conn;
|
|
35
|
+
}
|
|
36
|
+
get uRowsHandle() {
|
|
37
|
+
return this.uRowsHand;
|
|
38
|
+
}
|
|
39
|
+
get arraysize() {
|
|
40
|
+
return this.arraySize;
|
|
41
|
+
}
|
|
42
|
+
set arraysize(value) {
|
|
43
|
+
if (Number.isInteger(value) && value > 0) {
|
|
44
|
+
this.arraySize = value;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
throw new TypeError(`unexpected value ${value}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
callproc(procname, parameters) {
|
|
51
|
+
this.logger.traceLog("> enter callproc TeradataCursor");
|
|
52
|
+
try {
|
|
53
|
+
let sCall = "{CALL " + procname;
|
|
54
|
+
if (parameters) {
|
|
55
|
+
sCall += " (";
|
|
56
|
+
for (let i = 0; i < parameters.length; i++) {
|
|
57
|
+
if (i > 0) {
|
|
58
|
+
sCall += ",";
|
|
59
|
+
}
|
|
60
|
+
sCall += "?";
|
|
61
|
+
}
|
|
62
|
+
sCall += ")";
|
|
63
|
+
}
|
|
64
|
+
sCall += "}";
|
|
65
|
+
this.logger.traceLog("sCall=" + sCall);
|
|
66
|
+
this.execute(sCall, parameters);
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
this.logger.traceLog("< leave callproc TeradataCursor");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
close() {
|
|
73
|
+
this.logger.traceLog("> enter close TeradataCursor");
|
|
74
|
+
try {
|
|
75
|
+
if (!this.bClosed) {
|
|
76
|
+
this.bClosed = true;
|
|
77
|
+
this._closeRows();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
this.logger.traceLog("< leave close TeradataCursor");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
_stopIfClosed() {
|
|
85
|
+
this.logger.traceLog("> enter _stopIfClosed TeradataCursor");
|
|
86
|
+
try {
|
|
87
|
+
if (this.bClosed) {
|
|
88
|
+
throw new teradata_exceptions_1.ProgrammingError("Cursor is closed");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
this.logger.traceLog("< leave _stopIfClosed TeradataCursor");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
_closeRows() {
|
|
96
|
+
this.logger.traceLog("> enter _closeRows TeradataCursor");
|
|
97
|
+
try {
|
|
98
|
+
if (this.uRowsHand) {
|
|
99
|
+
const dStartTime = Date.now();
|
|
100
|
+
const jsgoCloseRows = this.lib.jsgoCloseRows;
|
|
101
|
+
const jsgoFreePointer = this.lib.jsgoFreePointer;
|
|
102
|
+
const cStringPtrType = this.ref.refType(this.ref.types.char);
|
|
103
|
+
const outputPtrPtr = this.ref.alloc(cStringPtrType);
|
|
104
|
+
jsgoCloseRows(this.conn.uLog, this.uRowsHand, outputPtrPtr);
|
|
105
|
+
this.uRowsHand = null;
|
|
106
|
+
let outputString = this.ref.allocCString("");
|
|
107
|
+
outputString = this.ref.deref(outputPtrPtr);
|
|
108
|
+
if (outputString.length > 0) {
|
|
109
|
+
const msg = this.ref.readCString(outputString);
|
|
110
|
+
jsgoFreePointer(this.conn.uLog, outputString);
|
|
111
|
+
throw new teradata_exceptions_1.OperationalError(msg);
|
|
112
|
+
}
|
|
113
|
+
this.logger.timingLog("_closeRows took " + (Date.now() - dStartTime) + " ms");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
this.logger.traceLog("< leave _closeRows TeradataCursor");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
execute(operation, parameters, ignoreErrors = null) {
|
|
121
|
+
this.logger.traceLog("> enter execute TeradataCursor");
|
|
122
|
+
try {
|
|
123
|
+
if (parameters === undefined || parameters === null) {
|
|
124
|
+
this.executemany(operation, null, ignoreErrors);
|
|
125
|
+
}
|
|
126
|
+
else if (Array.isArray(parameters[0])) {
|
|
127
|
+
this.executemany(operation, parameters, ignoreErrors);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
this.executemany(operation, [parameters], ignoreErrors);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
this.logger.traceLog("< leave execute TeradataCursor");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
executemany(procname, seqOfParameters, ignoreErrors = null) {
|
|
138
|
+
this.logger.traceLog("> enter executemany TeradataCursor");
|
|
139
|
+
this.logger.debugLog(seqOfParameters, true);
|
|
140
|
+
try {
|
|
141
|
+
const dStartTimeBegin = Date.now();
|
|
142
|
+
this._stopIfClosed();
|
|
143
|
+
this._closeRows();
|
|
144
|
+
if (ignoreErrors !== null) {
|
|
145
|
+
if (typeof ignoreErrors === "number") {
|
|
146
|
+
ignoreErrors = [ignoreErrors];
|
|
147
|
+
}
|
|
148
|
+
for (let i = 0; i < ignoreErrors.length; i++) {
|
|
149
|
+
if (!Number.isInteger(ignoreErrors[i])) {
|
|
150
|
+
throw new TypeError(`ignoreErrors[${i}] ${ignoreErrors[i]} is not an integer`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
ignoreErrors = [];
|
|
156
|
+
}
|
|
157
|
+
const setIgnoreErrorCodes = [...ignoreErrors];
|
|
158
|
+
let dStartTime = Date.now();
|
|
159
|
+
const jsgoCreateRows = this.lib.jsgoCreateRows;
|
|
160
|
+
const jsgoFreePointer = this.lib.jsgoFreePointer;
|
|
161
|
+
const procnamePtr = this.ref.allocCString(procname);
|
|
162
|
+
const aao = [];
|
|
163
|
+
if (seqOfParameters !== null) {
|
|
164
|
+
for (const row of seqOfParameters) {
|
|
165
|
+
for (const field of row) {
|
|
166
|
+
let ao = Buffer.allocUnsafe(0);
|
|
167
|
+
if (typeof field === "string") {
|
|
168
|
+
const aby = Buffer.from(field, "utf8");
|
|
169
|
+
ao = Buffer.allocUnsafe(9);
|
|
170
|
+
ao.writeUInt8("S".charCodeAt(0), 0);
|
|
171
|
+
ao.writeBigUInt64BE(BigInt(aby.byteLength), 1);
|
|
172
|
+
ao = Buffer.concat([ao, aby]);
|
|
173
|
+
}
|
|
174
|
+
else if (typeof field === "number") {
|
|
175
|
+
ao = Buffer.allocUnsafe(9);
|
|
176
|
+
ao.writeUInt8("D".charCodeAt(0), 0);
|
|
177
|
+
ao.writeDoubleBE(field, 1);
|
|
178
|
+
}
|
|
179
|
+
else if (field === null || field === undefined) {
|
|
180
|
+
ao = Buffer.allocUnsafe(1);
|
|
181
|
+
ao.writeUInt8("N".charCodeAt(0), 0);
|
|
182
|
+
}
|
|
183
|
+
else if (field instanceof Date) {
|
|
184
|
+
const sDate = field.toISOString().slice(0, 10);
|
|
185
|
+
const sTime = field.toISOString().slice(11, 23);
|
|
186
|
+
const s = `${sDate} ${sTime}`;
|
|
187
|
+
const aby = Buffer.from(s, "utf8");
|
|
188
|
+
ao = Buffer.allocUnsafe(9);
|
|
189
|
+
ao.writeUInt8("X".charCodeAt(0), 0);
|
|
190
|
+
ao.writeBigUInt64BE(BigInt(aby.byteLength), 1);
|
|
191
|
+
ao = Buffer.concat([ao, aby]);
|
|
192
|
+
}
|
|
193
|
+
else if (typeof field === "bigint") {
|
|
194
|
+
ao = Buffer.allocUnsafe(9);
|
|
195
|
+
ao.writeUInt8("L".charCodeAt(0), 0);
|
|
196
|
+
ao.writeBigInt64BE(field, 1);
|
|
197
|
+
}
|
|
198
|
+
else if (field instanceof Uint8Array) {
|
|
199
|
+
ao = Buffer.allocUnsafe(9);
|
|
200
|
+
ao.writeUInt8("B".charCodeAt(0), 0);
|
|
201
|
+
ao.writeBigUInt64BE(BigInt(field.length), 1);
|
|
202
|
+
const buf = Buffer.from(field);
|
|
203
|
+
ao = Buffer.concat([ao, buf]);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
throw new TypeError(`unexpected type=${typeof field} value=${field}`);
|
|
207
|
+
}
|
|
208
|
+
aao.push(ao);
|
|
209
|
+
}
|
|
210
|
+
aao.push(Buffer.from("Z"));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
aao.push(Buffer.from("Z"));
|
|
214
|
+
const abyBindValuesBuffer = Buffer.concat(aao);
|
|
215
|
+
this.logger.debugLog(abyBindValuesBuffer, true);
|
|
216
|
+
const abyBindValues = Uint8Array.from(abyBindValuesBuffer);
|
|
217
|
+
this.logger.timingLog("executemany serialize bind value took " + (Date.now() - dStartTime) + " ms and produced " + abyBindValues.length + " bytes");
|
|
218
|
+
dStartTime = Date.now();
|
|
219
|
+
const cStringPtrType = this.ref.refType(this.ref.types.char);
|
|
220
|
+
const outputPtrPtr = this.ref.alloc(cStringPtrType);
|
|
221
|
+
const rowsHandlePtr = this.ref.alloc(this.ref.types.ulong);
|
|
222
|
+
jsgoCreateRows(this.conn.uLog, this.conn.uPoolHandle, procnamePtr, abyBindValues.length, abyBindValues, outputPtrPtr, rowsHandlePtr);
|
|
223
|
+
let outputString = this.ref.allocCString("");
|
|
224
|
+
outputString = this.ref.deref(outputPtrPtr);
|
|
225
|
+
if (outputString.length > 0) {
|
|
226
|
+
const sErr = this.ref.readCString(outputString);
|
|
227
|
+
jsgoFreePointer(this.conn.uLog, outputString);
|
|
228
|
+
const regex = /\[Error (\d+)\]/g;
|
|
229
|
+
const found = sErr.matchAll(regex);
|
|
230
|
+
const aErrorCodes = [];
|
|
231
|
+
if (found) {
|
|
232
|
+
for (const codes of found) {
|
|
233
|
+
aErrorCodes.push(parseInt(codes[1], 10));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
let bIgnore = false;
|
|
237
|
+
for (const errorCode of aErrorCodes) {
|
|
238
|
+
if (setIgnoreErrorCodes.includes(errorCode)) {
|
|
239
|
+
bIgnore = true;
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
this.logger.debugLog(`executemany bIgnore=${bIgnore} aErrorCodes=[${aErrorCodes}] setIgnoreErrorCodes=[${setIgnoreErrorCodes}]`);
|
|
244
|
+
if (bIgnore) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
throw new teradata_exceptions_1.OperationalError(sErr);
|
|
248
|
+
}
|
|
249
|
+
this.logger.timingLog("executemany createRows took " + (Date.now() - dStartTime) + " ms");
|
|
250
|
+
if (rowsHandlePtr) {
|
|
251
|
+
this.uRowsHand = this.ref.readUInt64LE(rowsHandlePtr);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
throw new teradata_exceptions_1.OperationalError("rowsHandlePtr is null.");
|
|
255
|
+
}
|
|
256
|
+
this._obtainResultMetaData();
|
|
257
|
+
this.logger.timingLog("executemany took " + (Date.now() - dStartTimeBegin) + " ms");
|
|
258
|
+
}
|
|
259
|
+
finally {
|
|
260
|
+
this.logger.traceLog("< leave executemany TeradataCursor");
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
fetchone() {
|
|
264
|
+
this.logger.traceLog("> enter fetchone TeradataCursor");
|
|
265
|
+
try {
|
|
266
|
+
const row = this.next();
|
|
267
|
+
return row;
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
if (error instanceof teradata_exceptions_1.OperationalError && error.message === "StopIteration") {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
throw error;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
finally {
|
|
278
|
+
this.logger.traceLog("< leave fetchone TeradataCursor");
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
fetchall() {
|
|
282
|
+
this.logger.traceLog("> enter fetchall TeradataCursor");
|
|
283
|
+
this._stopIfClosed();
|
|
284
|
+
try {
|
|
285
|
+
if (this.uRowsHandle) {
|
|
286
|
+
const dStartTime = Date.now();
|
|
287
|
+
let aRow = [];
|
|
288
|
+
let rows = this.fetchmany_();
|
|
289
|
+
while (rows) {
|
|
290
|
+
aRow = aRow.concat(rows);
|
|
291
|
+
rows = this.fetchmany_();
|
|
292
|
+
}
|
|
293
|
+
this.logger.timingLog("fetchall fetched " + aRow.length + " rows and took " + (Date.now() - dStartTime) + " ms");
|
|
294
|
+
return aRow;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
finally {
|
|
298
|
+
this.logger.traceLog("< leave fetchall TeradataCursor");
|
|
299
|
+
}
|
|
300
|
+
return [];
|
|
301
|
+
}
|
|
302
|
+
fetchmany(nDesiredRowCount) {
|
|
303
|
+
this.logger.traceLog("> enter fetchmany TeradataCursor");
|
|
304
|
+
this._stopIfClosed();
|
|
305
|
+
try {
|
|
306
|
+
if (this.uRowsHandle) {
|
|
307
|
+
const result = this.fetchmany_(nDesiredRowCount);
|
|
308
|
+
if (result) {
|
|
309
|
+
return result;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
finally {
|
|
314
|
+
this.logger.traceLog("< leave fetchmany TeradataCursor");
|
|
315
|
+
}
|
|
316
|
+
return [];
|
|
317
|
+
}
|
|
318
|
+
nextset() {
|
|
319
|
+
this.logger.traceLog("> enter nextset TeradataCursor");
|
|
320
|
+
try {
|
|
321
|
+
this._stopIfClosed();
|
|
322
|
+
if (this.uRowsHandle) {
|
|
323
|
+
const dStartTime = Date.now();
|
|
324
|
+
const jsgoNextResult = this.lib.jsgoNextResult;
|
|
325
|
+
const jsgoFreePointer = this.lib.jsgoFreePointer;
|
|
326
|
+
const cStringPtrType = this.ref.refType(this.ref.types.char);
|
|
327
|
+
const outputPtrPtr = this.ref.alloc(cStringPtrType);
|
|
328
|
+
const availPtr = this.ref.allocCString("C");
|
|
329
|
+
jsgoNextResult(this.conn.uLog, this.uRowsHand, outputPtrPtr, availPtr);
|
|
330
|
+
let outputString = this.ref.allocCString("");
|
|
331
|
+
outputString = this.ref.deref(outputPtrPtr);
|
|
332
|
+
if (outputString.length > 0) {
|
|
333
|
+
const msg = this.ref.readCString(outputString);
|
|
334
|
+
jsgoFreePointer(this.conn.uLog, outputString);
|
|
335
|
+
throw new teradata_exceptions_1.OperationalError(msg);
|
|
336
|
+
}
|
|
337
|
+
if (this.ref.readCString(availPtr) === "Y") {
|
|
338
|
+
this._obtainResultMetaData();
|
|
339
|
+
this.logger.timingLog("nextset() took " + (Date.now() - dStartTime) + " ms");
|
|
340
|
+
return true;
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
this.desc = null;
|
|
344
|
+
this.rowCount = 0n;
|
|
345
|
+
this.logger.timingLog("nextset() took " + (Date.now() - dStartTime) + " ms");
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
finally {
|
|
354
|
+
this.logger.traceLog("< leave nextset TeradataCursor");
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
setinputsizes(sizes) {
|
|
358
|
+
this._stopIfClosed();
|
|
359
|
+
}
|
|
360
|
+
setoutputsize(size, column) {
|
|
361
|
+
this._stopIfClosed();
|
|
362
|
+
}
|
|
363
|
+
next() {
|
|
364
|
+
this.logger.traceLog("> enter next TeradataCursor");
|
|
365
|
+
try {
|
|
366
|
+
this._stopIfClosed();
|
|
367
|
+
if (this.uRowsHandle) {
|
|
368
|
+
const row = this.fetchmany_(1);
|
|
369
|
+
if (row && row.length > 0) {
|
|
370
|
+
return row[0];
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
this.logger.debugLog("End of rows");
|
|
374
|
+
throw new teradata_exceptions_1.OperationalError("StopIteration");
|
|
375
|
+
}
|
|
376
|
+
finally {
|
|
377
|
+
this.logger.traceLog("< leave next TeradataCursor");
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
fetchmany_(nDesiredRowCount) {
|
|
381
|
+
this.logger.traceLog("> enter fetchmany_ TeradataCursor");
|
|
382
|
+
try {
|
|
383
|
+
const dStartTimeBegin = Date.now();
|
|
384
|
+
this.logger.debugLog(`fetchmany_ nDesiredRowCount=${nDesiredRowCount}`);
|
|
385
|
+
this.logger.debugLog(`fetchmany_ arraySize=${this.arraySize}`);
|
|
386
|
+
if (!nDesiredRowCount) {
|
|
387
|
+
nDesiredRowCount = this.arraySize;
|
|
388
|
+
}
|
|
389
|
+
const jsgoFetchRow = this.lib.jsgoFetchRow;
|
|
390
|
+
const jsgoFreePointer = this.lib.jsgoFreePointer;
|
|
391
|
+
const cStringPtrType = this.ref.refType(this.ref.types.char);
|
|
392
|
+
const outputPtrPtr = this.ref.alloc(cStringPtrType);
|
|
393
|
+
const columnValuesByteCountPtr = this.ref.alloc(this.ref.types.int64);
|
|
394
|
+
const outByteArray = this.ref.refType(this.byteArray);
|
|
395
|
+
const byteArrayPtrPtr = this.ref.alloc(outByteArray);
|
|
396
|
+
let dStartTime = Date.now();
|
|
397
|
+
jsgoFetchRow(this.conn.uLog, this.uRowsHand, outputPtrPtr, columnValuesByteCountPtr, byteArrayPtrPtr, nDesiredRowCount);
|
|
398
|
+
this.logger.timingLog("fetchmany_ call to jsgoFetchRow took " + (Date.now() - dStartTime) + " ms");
|
|
399
|
+
let outputString = this.ref.allocCString("");
|
|
400
|
+
outputString = this.ref.deref(outputPtrPtr);
|
|
401
|
+
if (outputString.length > 0) {
|
|
402
|
+
const msg = this.ref.readCString(outputString);
|
|
403
|
+
jsgoFreePointer(this.conn.uLog, outputString);
|
|
404
|
+
throw new teradata_exceptions_1.OperationalError(msg);
|
|
405
|
+
}
|
|
406
|
+
dStartTime = Date.now();
|
|
407
|
+
const rowsLength = this.ref.deref(columnValuesByteCountPtr);
|
|
408
|
+
const byteArrayPtr = this.ref.deref(byteArrayPtrPtr);
|
|
409
|
+
this.logger.timingLog("fetchmany_ call to ref.deref took " + (Date.now() - dStartTime) + " ms");
|
|
410
|
+
let nObservedRowCount = 0;
|
|
411
|
+
dStartTime = Date.now();
|
|
412
|
+
if (byteArrayPtr.length !== 0) {
|
|
413
|
+
this.logger.debugLog(`jsgoFetchRow rowsLength=${rowsLength}`);
|
|
414
|
+
if (this.logger.bDebugLog) {
|
|
415
|
+
console.log(byteArrayPtr.buffer.slice(byteArrayPtr.byteOffset, byteArrayPtr.byteOffset + rowsLength));
|
|
416
|
+
}
|
|
417
|
+
const byteBuffer = Buffer.from(this.ref.reinterpret(byteArrayPtr, rowsLength, 0));
|
|
418
|
+
const rows = [];
|
|
419
|
+
let row;
|
|
420
|
+
let i = 0;
|
|
421
|
+
while (i < rowsLength - 1) {
|
|
422
|
+
row = [];
|
|
423
|
+
while (byteBuffer[i] !== "Z".charCodeAt(0)) {
|
|
424
|
+
let iNew = 0;
|
|
425
|
+
if (byteBuffer[i] === "S".charCodeAt(0)) {
|
|
426
|
+
iNew = this._deserializeString(byteBuffer, i, row);
|
|
427
|
+
}
|
|
428
|
+
else if (byteBuffer[i] === "I".charCodeAt(0)) {
|
|
429
|
+
iNew = this._deserializeInt(byteBuffer, i, row);
|
|
430
|
+
}
|
|
431
|
+
else if (byteBuffer[i] === "N".charCodeAt(0)) {
|
|
432
|
+
iNew = this._deserializeNull(byteBuffer, i, row);
|
|
433
|
+
}
|
|
434
|
+
else if (byteBuffer[i] === "D".charCodeAt(0)) {
|
|
435
|
+
iNew = this._deserializeDouble(byteBuffer, i, row);
|
|
436
|
+
}
|
|
437
|
+
else if (byteBuffer[i] === "L".charCodeAt(0)) {
|
|
438
|
+
iNew = this._deserializeLong(byteBuffer, i, row);
|
|
439
|
+
}
|
|
440
|
+
else if (byteBuffer[i] === "M".charCodeAt(0)) {
|
|
441
|
+
iNew = this._deserializeNumber(byteBuffer, i, row);
|
|
442
|
+
}
|
|
443
|
+
else if (byteBuffer[i] === "U".charCodeAt(0)) {
|
|
444
|
+
iNew = this._deserializeDate(byteBuffer, i, row);
|
|
445
|
+
}
|
|
446
|
+
else if (byteBuffer[i] === "V".charCodeAt(0)) {
|
|
447
|
+
iNew = this._deserializeTime(byteBuffer, i, row);
|
|
448
|
+
}
|
|
449
|
+
else if (byteBuffer[i] === "W".charCodeAt(0)) {
|
|
450
|
+
iNew = this._deserializeTimeWithTimeZone(byteBuffer, i, row);
|
|
451
|
+
}
|
|
452
|
+
else if (byteBuffer[i] === "X".charCodeAt(0)) {
|
|
453
|
+
iNew = this._deserializeTimestamp(byteBuffer, i, row);
|
|
454
|
+
}
|
|
455
|
+
else if (byteBuffer[i] === "Y".charCodeAt(0)) {
|
|
456
|
+
iNew = this._deserializeTimestampWithTimeZone(byteBuffer, i, row);
|
|
457
|
+
}
|
|
458
|
+
else if (byteBuffer[i] === "B".charCodeAt(0)) {
|
|
459
|
+
iNew = this._deserializeBytes(byteBuffer, i, row);
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
throw new teradata_exceptions_1.OperationalError("Unknown Data Type:" + String.fromCharCode(byteBuffer[i]) + ".");
|
|
463
|
+
}
|
|
464
|
+
this.logger.debugLog(`fetchmany_() row[${row.length - 1}], typeCode=${byteBuffer[i].toString()} type=${typeof row[row.length - 1]} value=${row[row.length - 1]}`);
|
|
465
|
+
if (this.logger.bDebugLog) {
|
|
466
|
+
console.log("NODEJS-DEBUG deserialized row:");
|
|
467
|
+
console.log(row);
|
|
468
|
+
}
|
|
469
|
+
i = iNew;
|
|
470
|
+
}
|
|
471
|
+
rows.push(row);
|
|
472
|
+
nObservedRowCount += 1;
|
|
473
|
+
i += 1;
|
|
474
|
+
}
|
|
475
|
+
this.logger.timingLog("fetchmany_ deserialized " + rowsLength + " bytes and took " + (Date.now() - dStartTime) + " ms");
|
|
476
|
+
this.logger.debugLog(`fetchmany_ nObservedRowCount=${nObservedRowCount}`);
|
|
477
|
+
dStartTime = Date.now();
|
|
478
|
+
jsgoFreePointer(this.conn.uLog, byteArrayPtr);
|
|
479
|
+
this.logger.timingLog("fetchmany_ call to jsgoFreePointer took " + (Date.now() - dStartTime) + " ms");
|
|
480
|
+
if (rows.length === 0) {
|
|
481
|
+
throw new teradata_exceptions_1.OperationalError(`Found no row with byteArrayPtr.length = ${byteArrayPtr.length} `);
|
|
482
|
+
}
|
|
483
|
+
this.logger.timingLog("fetchmany_(" + nDesiredRowCount + ") fetched " + nObservedRowCount + " rows and took " + (Date.now() - dStartTimeBegin) + " ms");
|
|
484
|
+
return rows;
|
|
485
|
+
}
|
|
486
|
+
else {
|
|
487
|
+
return null;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
finally {
|
|
491
|
+
this.logger.traceLog("< leave fetchmany_ TeradataCursor");
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
_obtainResultMetaData() {
|
|
495
|
+
this.logger.traceLog("> enter _obtainResultMetaData TeradataCursor");
|
|
496
|
+
try {
|
|
497
|
+
const dStartTimeBegin = Date.now();
|
|
498
|
+
const jsgoResultMetaData = this.lib.jsgoResultMetaData;
|
|
499
|
+
const jsgoFreePointer = this.lib.jsgoFreePointer;
|
|
500
|
+
const cStringPtrType = this.ref.refType(this.ref.types.char);
|
|
501
|
+
const outputPtrPtr = this.ref.alloc(cStringPtrType);
|
|
502
|
+
const metaDataByteCountPtr = this.ref.alloc(this.ref.types.int);
|
|
503
|
+
const outByteArray = this.ref.refType(this.byteArray);
|
|
504
|
+
const byteArrayPtrPtr = this.ref.alloc(outByteArray);
|
|
505
|
+
const uActivityCount = this.ref.alloc(this.ref.types.ulong);
|
|
506
|
+
let dStartTime = Date.now();
|
|
507
|
+
jsgoResultMetaData(this.conn.uLog, this.uRowsHand, outputPtrPtr, uActivityCount, metaDataByteCountPtr, byteArrayPtrPtr);
|
|
508
|
+
this.logger.timingLog("_obtainResultMetaData call to jsgoResultMetaData took " + (Date.now() - dStartTime) + " ms");
|
|
509
|
+
let outputString = this.ref.allocCString("");
|
|
510
|
+
outputString = this.ref.deref(outputPtrPtr);
|
|
511
|
+
if (outputString.length > 0) {
|
|
512
|
+
const msg = this.ref.readCString(outputString);
|
|
513
|
+
jsgoFreePointer(this.conn.uLog, outputString);
|
|
514
|
+
throw new teradata_exceptions_1.OperationalError(msg);
|
|
515
|
+
}
|
|
516
|
+
dStartTime = Date.now();
|
|
517
|
+
this.rowCount = BigInt(this.ref.readUInt64LE(uActivityCount));
|
|
518
|
+
const byteArrayPtr = this.ref.deref(byteArrayPtrPtr);
|
|
519
|
+
const metadataLength = this.ref.deref(metaDataByteCountPtr);
|
|
520
|
+
if (metadataLength > 0) {
|
|
521
|
+
this.desc = [];
|
|
522
|
+
let i = 0;
|
|
523
|
+
const pcColumnMetaData = Buffer.from(this.ref.reinterpret(byteArrayPtr, metadataLength, 0));
|
|
524
|
+
while (pcColumnMetaData[i] !== "Z".charCodeAt(0)) {
|
|
525
|
+
const columnDesc = [];
|
|
526
|
+
i = this._deserializeString(pcColumnMetaData, i, columnDesc);
|
|
527
|
+
i = this._deserializeString(pcColumnMetaData, i, null);
|
|
528
|
+
i = this._deserializeString(pcColumnMetaData, i, columnDesc);
|
|
529
|
+
if (columnDesc[columnDesc.length - 1] === "b") {
|
|
530
|
+
columnDesc[columnDesc.length - 1] = exports.BINARY;
|
|
531
|
+
}
|
|
532
|
+
else if (columnDesc[columnDesc.length - 1] === "d") {
|
|
533
|
+
columnDesc[columnDesc.length - 1] = exports.NUMBER;
|
|
534
|
+
}
|
|
535
|
+
else if (columnDesc[columnDesc.length - 1] === "i" || columnDesc[columnDesc.length - 1] === "l") {
|
|
536
|
+
columnDesc[columnDesc.length - 1] = exports.NUMBER;
|
|
537
|
+
}
|
|
538
|
+
else if (columnDesc[columnDesc.length - 1] === "m") {
|
|
539
|
+
columnDesc[columnDesc.length - 1] = exports.NUMBER;
|
|
540
|
+
}
|
|
541
|
+
else if (columnDesc[columnDesc.length - 1] === "s") {
|
|
542
|
+
columnDesc[columnDesc.length - 1] = exports.STRING;
|
|
543
|
+
}
|
|
544
|
+
else if (columnDesc[columnDesc.length - 1] === "u") {
|
|
545
|
+
columnDesc[columnDesc.length - 1] = exports.STRING;
|
|
546
|
+
}
|
|
547
|
+
else if (columnDesc[columnDesc.length - 1] === "v" || columnDesc[columnDesc.length - 1] === "w") {
|
|
548
|
+
columnDesc[columnDesc.length - 1] = exports.STRING;
|
|
549
|
+
}
|
|
550
|
+
else if (columnDesc[columnDesc.length - 1] === "x") {
|
|
551
|
+
columnDesc[columnDesc.length - 1] = exports.DATE;
|
|
552
|
+
}
|
|
553
|
+
else if (columnDesc[columnDesc.length - 1] === "y") {
|
|
554
|
+
columnDesc[columnDesc.length - 1] = exports.STRING;
|
|
555
|
+
}
|
|
556
|
+
columnDesc.push(null);
|
|
557
|
+
i = this._deserializeLong(pcColumnMetaData, i, columnDesc);
|
|
558
|
+
i = this._deserializeLong(pcColumnMetaData, i, columnDesc);
|
|
559
|
+
i = this._deserializeLong(pcColumnMetaData, i, columnDesc);
|
|
560
|
+
i = this._deserializeBool(pcColumnMetaData, i, columnDesc);
|
|
561
|
+
this.logger.debugLog(columnDesc, true);
|
|
562
|
+
this.desc.push(columnDesc);
|
|
563
|
+
}
|
|
564
|
+
this.logger.timingLog("_obtainResultMetaData deserialized " + metadataLength + " bytes and took " + (Date.now() - dStartTime) + " ms");
|
|
565
|
+
jsgoFreePointer(this.conn.uLog, byteArrayPtr);
|
|
566
|
+
this.logger.timingLog("_obtainResultMetaData() took " + (Date.now() - dStartTimeBegin) + " ms");
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
finally {
|
|
570
|
+
this.logger.traceLog("< leave _obtainResultMetaData TeradataCursor");
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
_deserializeBool(pc, i, row) {
|
|
574
|
+
if (pc[i] === "T".charCodeAt(0) || pc[i] === "F".charCodeAt(0)) {
|
|
575
|
+
if (row) {
|
|
576
|
+
row.push(pc[i] === "T".charCodeAt(0));
|
|
577
|
+
}
|
|
578
|
+
return i + 1;
|
|
579
|
+
}
|
|
580
|
+
else if (pc[i] === "N".charCodeAt(0)) {
|
|
581
|
+
return this._deserializeNull(pc, i, row);
|
|
582
|
+
}
|
|
583
|
+
else {
|
|
584
|
+
throw new teradata_exceptions_1.OperationalError("Expected column type T/F/N.");
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
_deserializeBytes(pc, i, row) {
|
|
588
|
+
if (pc[i] === "B".charCodeAt(0)) {
|
|
589
|
+
i += 1;
|
|
590
|
+
const unByteCount = pc.readBigUInt64BE(i);
|
|
591
|
+
let uByteCount = 0;
|
|
592
|
+
if (unByteCount <= Number.MAX_SAFE_INTEGER) {
|
|
593
|
+
uByteCount = Number(unByteCount);
|
|
594
|
+
}
|
|
595
|
+
else {
|
|
596
|
+
throw new teradata_exceptions_1.OperationalError(`Data length > ${unByteCount} is not supported.`);
|
|
597
|
+
}
|
|
598
|
+
i += 8;
|
|
599
|
+
const abyBuffer = pc.slice(i, i + uByteCount);
|
|
600
|
+
const abyValue = new Uint8Array(abyBuffer);
|
|
601
|
+
i += uByteCount;
|
|
602
|
+
if (row) {
|
|
603
|
+
row.push(abyValue);
|
|
604
|
+
}
|
|
605
|
+
return i;
|
|
606
|
+
}
|
|
607
|
+
else if (pc[i] === "N".charCodeAt(0)) {
|
|
608
|
+
return this._deserializeNull(pc, i, row);
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
throw new teradata_exceptions_1.OperationalError("Expected column type B/N.");
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
_deserializeCharacterValue(abyTypeCode, pc, i, row) {
|
|
615
|
+
if (pc[i] === abyTypeCode) {
|
|
616
|
+
i += 1;
|
|
617
|
+
let uByteCount = 0;
|
|
618
|
+
const unByteCount = pc.readBigUInt64BE(i);
|
|
619
|
+
if (unByteCount <= Number.MAX_SAFE_INTEGER) {
|
|
620
|
+
uByteCount = Number(unByteCount);
|
|
621
|
+
}
|
|
622
|
+
else {
|
|
623
|
+
throw new teradata_exceptions_1.OperationalError(`Data length > ${unByteCount} is not supported.`);
|
|
624
|
+
}
|
|
625
|
+
i += 8;
|
|
626
|
+
const sValue = pc.toString("utf8", i, i + uByteCount);
|
|
627
|
+
i += uByteCount;
|
|
628
|
+
if (row) {
|
|
629
|
+
if (abyTypeCode === "L".charCodeAt(0)) {
|
|
630
|
+
throw new teradata_exceptions_1.OperationalError("BigInt should not be a char value.");
|
|
631
|
+
}
|
|
632
|
+
else if (abyTypeCode === "M".charCodeAt(0)) {
|
|
633
|
+
row.push(Number(sValue));
|
|
634
|
+
}
|
|
635
|
+
else if (abyTypeCode === "X".charCodeAt(0)) {
|
|
636
|
+
const timePieces = /^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})(\.[0-9]*)?/;
|
|
637
|
+
const u = timePieces.exec(sValue);
|
|
638
|
+
let date;
|
|
639
|
+
if (u) {
|
|
640
|
+
const nMillisecondsUTC = Date.UTC(parseInt(u[1], 10), parseInt(u[2], 10) - 1, parseInt(u[3], 10), parseInt(u[4], 10), parseInt(u[5], 10), parseInt(u[6], 10), (u[7] && parseFloat(u[7]) * 1000) || 0);
|
|
641
|
+
date = new Date(nMillisecondsUTC);
|
|
642
|
+
row.push(date);
|
|
643
|
+
}
|
|
644
|
+
else {
|
|
645
|
+
throw new teradata_exceptions_1.OperationalError("Unexpected timestamp value");
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
row.push(sValue);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
return i;
|
|
653
|
+
}
|
|
654
|
+
else if (pc[i] === "N".charCodeAt(0)) {
|
|
655
|
+
return this._deserializeNull(pc, i, row);
|
|
656
|
+
}
|
|
657
|
+
else {
|
|
658
|
+
throw new teradata_exceptions_1.OperationalError("Expected column type " + String.fromCharCode(abyTypeCode) + "/N.");
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
_deserializeDate(pc, i, row) {
|
|
662
|
+
return this._deserializeCharacterValue("U".charCodeAt(0), pc, i, row);
|
|
663
|
+
}
|
|
664
|
+
_deserializeDouble(pc, i, row) {
|
|
665
|
+
if (pc[i] === "D".charCodeAt(0)) {
|
|
666
|
+
i += 1;
|
|
667
|
+
const dValue = pc.readDoubleBE(i);
|
|
668
|
+
i += 8;
|
|
669
|
+
if (row) {
|
|
670
|
+
row.push(dValue);
|
|
671
|
+
}
|
|
672
|
+
return i;
|
|
673
|
+
}
|
|
674
|
+
else if (pc[i] === "N".charCodeAt(0)) {
|
|
675
|
+
return this._deserializeNull(pc, i, row);
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
throw new teradata_exceptions_1.OperationalError("Expected column type D/N.");
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
_deserializeInt(pc, i, row) {
|
|
682
|
+
if (pc[i] === "I".charCodeAt(0)) {
|
|
683
|
+
i += 1;
|
|
684
|
+
const nValue = pc.readInt32BE(i);
|
|
685
|
+
i += 4;
|
|
686
|
+
if (row) {
|
|
687
|
+
row.push(nValue);
|
|
688
|
+
}
|
|
689
|
+
return i;
|
|
690
|
+
}
|
|
691
|
+
else if (pc[i] === "N".charCodeAt(0)) {
|
|
692
|
+
return this._deserializeNull(pc, i, row);
|
|
693
|
+
}
|
|
694
|
+
else {
|
|
695
|
+
throw new teradata_exceptions_1.OperationalError("Expected column type I/N.");
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
_deserializeLong(pc, i, row) {
|
|
699
|
+
if (pc[i] === "L".charCodeAt(0)) {
|
|
700
|
+
i += 1;
|
|
701
|
+
const nValue = pc.readBigInt64BE(i);
|
|
702
|
+
i += 8;
|
|
703
|
+
if (row) {
|
|
704
|
+
row.push(nValue);
|
|
705
|
+
}
|
|
706
|
+
return i;
|
|
707
|
+
}
|
|
708
|
+
else if (pc[i] === "N".charCodeAt(0)) {
|
|
709
|
+
return this._deserializeNull(pc, i, row);
|
|
710
|
+
}
|
|
711
|
+
else {
|
|
712
|
+
throw new teradata_exceptions_1.OperationalError("Expected column type L/N.");
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
_deserializeNull(pc, i, row) {
|
|
716
|
+
if (pc[i] === "N".charCodeAt(0)) {
|
|
717
|
+
if (row) {
|
|
718
|
+
row.push(null);
|
|
719
|
+
}
|
|
720
|
+
return i + 1;
|
|
721
|
+
}
|
|
722
|
+
else {
|
|
723
|
+
throw new teradata_exceptions_1.OperationalError("Expected column type N.");
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
_deserializeNumber(pc, i, row) {
|
|
727
|
+
return this._deserializeCharacterValue("M".charCodeAt(0), pc, i, row);
|
|
728
|
+
}
|
|
729
|
+
_deserializeString(pc, i, row) {
|
|
730
|
+
return this._deserializeCharacterValue("S".charCodeAt(0), pc, i, row);
|
|
731
|
+
}
|
|
732
|
+
_deserializeTime(pc, i, row) {
|
|
733
|
+
return this._deserializeCharacterValue("V".charCodeAt(0), pc, i, row);
|
|
734
|
+
}
|
|
735
|
+
_deserializeTimeWithTimeZone(pc, i, row) {
|
|
736
|
+
return this._deserializeCharacterValue("W".charCodeAt(0), pc, i, row);
|
|
737
|
+
}
|
|
738
|
+
_deserializeTimestamp(pc, i, row) {
|
|
739
|
+
return this._deserializeCharacterValue("X".charCodeAt(0), pc, i, row);
|
|
740
|
+
}
|
|
741
|
+
_deserializeTimestampWithTimeZone(pc, i, row) {
|
|
742
|
+
return this._deserializeCharacterValue("Y".charCodeAt(0), pc, i, row);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
exports.TeradataCursor = TeradataCursor;
|
|
746
|
+
//# sourceMappingURL=teradata-cursor.js.map
|