node-firebird-driver 3.2.2 → 3.4.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/README.md +1 -1
- package/dist/lib/impl/attachment.d.ts +4 -4
- package/dist/lib/impl/attachment.js +8 -6
- package/dist/lib/impl/attachment.js.map +1 -1
- package/dist/lib/impl/blob.js.map +1 -1
- package/dist/lib/impl/client.js +3 -2
- package/dist/lib/impl/client.js.map +1 -1
- package/dist/lib/impl/date-time.js +2 -1
- package/dist/lib/impl/date-time.js.map +1 -1
- package/dist/lib/impl/events.js +2 -1
- package/dist/lib/impl/events.js.map +1 -1
- package/dist/lib/impl/fb-util.d.ts +2 -1
- package/dist/lib/impl/fb-util.js +100 -81
- package/dist/lib/impl/fb-util.js.map +1 -1
- package/dist/lib/impl/resultset.js +11 -5
- package/dist/lib/impl/resultset.js.map +1 -1
- package/dist/lib/impl/statement.d.ts +3 -1
- package/dist/lib/impl/statement.js +4 -2
- package/dist/lib/impl/statement.js.map +1 -1
- package/dist/lib/impl/time-zones.js +5 -3
- package/dist/lib/impl/time-zones.js.map +1 -1
- package/dist/lib/impl/transaction.js +2 -1
- package/dist/lib/impl/transaction.js.map +1 -1
- package/dist/lib/index.d.ts +27 -1
- package/dist/lib/index.js +25 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/test/tests.js +197 -68
- package/dist/test/tests.js.map +1 -1
- package/package.json +6 -5
- package/src/lib/impl/attachment.ts +290 -253
- package/src/lib/impl/blob.ts +37 -35
- package/src/lib/impl/client.ts +60 -61
- package/src/lib/impl/date-time.ts +33 -33
- package/src/lib/impl/events.ts +17 -18
- package/src/lib/impl/fb-util.ts +552 -448
- package/src/lib/impl/resultset.ts +94 -86
- package/src/lib/impl/statement.ts +157 -127
- package/src/lib/impl/time-zones.ts +643 -641
- package/src/lib/impl/transaction.ts +37 -38
- package/src/lib/index.ts +331 -270
- package/src/test/tests.ts +1028 -860
- package/tsconfig.json +7 -13
package/dist/test/tests.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.runCommonTests = runCommonTests;
|
|
|
4
4
|
const lib_1 = require("../lib");
|
|
5
5
|
const fs = require("fs-extra-promise");
|
|
6
6
|
const tmp = require("temp-fs");
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
7
8
|
require('dotenv').config({ path: '../../.env' });
|
|
8
9
|
function runCommonTests(client) {
|
|
9
10
|
function dateToString(d) {
|
|
@@ -13,20 +14,22 @@ function runCommonTests(client) {
|
|
|
13
14
|
return d && `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${d.getMilliseconds()}`;
|
|
14
15
|
}
|
|
15
16
|
function timeTzToString(zd) {
|
|
16
|
-
if (!zd)
|
|
17
|
+
if (!zd) {
|
|
17
18
|
return null;
|
|
18
|
-
|
|
19
|
+
}
|
|
20
|
+
const d = new Date(zd.date.getTime() + zd.offset * 60 * 1000);
|
|
19
21
|
return `time '${d.getUTCHours()}:${d.getUTCMinutes()}:${d.getUTCSeconds()}.${d.getUTCMilliseconds()} ${zd.timeZone}'`;
|
|
20
22
|
}
|
|
21
23
|
function dateTimeToString(d) {
|
|
22
24
|
return d && `${dateToString(d)} ${timeToString(d)}`;
|
|
23
25
|
}
|
|
24
26
|
function dateTimeTzToString(zd) {
|
|
25
|
-
if (!zd)
|
|
27
|
+
if (!zd) {
|
|
26
28
|
return null;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
}
|
|
30
|
+
const d = new Date(zd.date.getTime() + zd.offset * 60 * 1000);
|
|
31
|
+
return (`timestamp '${(d.getUTCFullYear() + '').padStart(4, '0')}-${d.getUTCMonth() + 1}-${d.getUTCDate()} ` +
|
|
32
|
+
`${d.getUTCHours()}:${d.getUTCMinutes()}:${d.getUTCSeconds()}.${d.getUTCMilliseconds()} ${zd.timeZone}'`);
|
|
30
33
|
}
|
|
31
34
|
describe('node-firebird-driver', () => {
|
|
32
35
|
const testConfig = {
|
|
@@ -34,19 +37,17 @@ function runCommonTests(client) {
|
|
|
34
37
|
password: process.env.ISC_PASSWORD,
|
|
35
38
|
host: process.env.NODE_FB_TEST_HOST,
|
|
36
39
|
port: process.env.NODE_FB_TEST_PORT,
|
|
37
|
-
tmpDir: process.env.NODE_FB_TEST_TMP_DIR
|
|
40
|
+
tmpDir: process.env.NODE_FB_TEST_TMP_DIR,
|
|
38
41
|
};
|
|
39
42
|
function isLocal() {
|
|
40
|
-
return testConfig.host == undefined ||
|
|
41
|
-
testConfig.host == 'localhost' ||
|
|
42
|
-
testConfig.host == '127.0.0.1';
|
|
43
|
+
return testConfig.host == undefined || testConfig.host == 'localhost' || testConfig.host == '127.0.0.1';
|
|
43
44
|
}
|
|
44
45
|
function getTempFile(name) {
|
|
45
46
|
const database = `${testConfig.tmpDir}/${name}`;
|
|
46
|
-
return (testConfig.host ?? '') +
|
|
47
|
+
return ((testConfig.host ?? '') +
|
|
47
48
|
(testConfig.host && testConfig.port ? `/${testConfig.port}` : '') +
|
|
48
49
|
(testConfig.host ? ':' : '') +
|
|
49
|
-
database;
|
|
50
|
+
database);
|
|
50
51
|
}
|
|
51
52
|
jest.setTimeout(10000);
|
|
52
53
|
beforeAll(() => {
|
|
@@ -58,21 +59,22 @@ function runCommonTests(client) {
|
|
|
58
59
|
}
|
|
59
60
|
const defaultOptions = {
|
|
60
61
|
password: testConfig.password,
|
|
61
|
-
username: testConfig.username
|
|
62
|
+
username: testConfig.username,
|
|
62
63
|
};
|
|
63
64
|
client.defaultCreateDatabaseOptions = {
|
|
64
65
|
forcedWrite: false,
|
|
65
|
-
...defaultOptions
|
|
66
|
+
...defaultOptions,
|
|
66
67
|
};
|
|
67
68
|
client.defaultConnectOptions = {
|
|
68
|
-
...defaultOptions
|
|
69
|
+
...defaultOptions,
|
|
69
70
|
};
|
|
70
71
|
});
|
|
71
72
|
afterAll(async () => {
|
|
72
73
|
await client.dispose();
|
|
73
74
|
expect(client.isValid).toBeFalsy();
|
|
74
|
-
if (isLocal())
|
|
75
|
+
if (isLocal()) {
|
|
75
76
|
fs.rmdirSync(testConfig.tmpDir);
|
|
77
|
+
}
|
|
76
78
|
});
|
|
77
79
|
describe('Client', () => {
|
|
78
80
|
test('#createDatabase()', async () => {
|
|
@@ -90,22 +92,55 @@ function runCommonTests(client) {
|
|
|
90
92
|
expect(attachment1.isValid).toBeFalsy();
|
|
91
93
|
expect(attachment2.isValid).toBeFalsy();
|
|
92
94
|
});
|
|
95
|
+
test('setDatabaseReadWriteMode', async () => {
|
|
96
|
+
const filename = getTempFile('setDatabaseReadWriteMode.fdb');
|
|
97
|
+
const attachment1 = await client.createDatabase(filename);
|
|
98
|
+
await attachment1.disconnect();
|
|
99
|
+
const attachment2 = await client.connect(filename, {
|
|
100
|
+
setDatabaseReadWriteMode: lib_1.DatabaseReadWriteMode.READ_ONLY,
|
|
101
|
+
});
|
|
102
|
+
try {
|
|
103
|
+
const transaction = await attachment2.startTransaction();
|
|
104
|
+
await expect(attachment2.execute(transaction, 'create table t1 (id integer)')).rejects.toThrow();
|
|
105
|
+
await transaction.rollback();
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
await attachment2.disconnect();
|
|
109
|
+
}
|
|
110
|
+
const attachment3 = await client.connect(filename, {
|
|
111
|
+
setDatabaseReadWriteMode: lib_1.DatabaseReadWriteMode.READ_WRITE,
|
|
112
|
+
});
|
|
113
|
+
try {
|
|
114
|
+
const transaction = await attachment3.startTransaction();
|
|
115
|
+
await attachment3.execute(transaction, 'create table t1 (id integer)');
|
|
116
|
+
await transaction.commit();
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
await attachment3.disconnect();
|
|
120
|
+
}
|
|
121
|
+
const attachment4 = await client.connect(filename);
|
|
122
|
+
await attachment4.dropDatabase();
|
|
123
|
+
});
|
|
93
124
|
});
|
|
94
125
|
describe('Attachment', () => {
|
|
95
126
|
test('#startTransaction()', async () => {
|
|
96
127
|
const attachment = await client.createDatabase(getTempFile('Attachment-startTransaction.fdb'));
|
|
97
|
-
const isolationQuery =
|
|
128
|
+
const isolationQuery = "select rdb$get_context('SYSTEM', 'ISOLATION_LEVEL') from rdb$database";
|
|
98
129
|
const transaction1 = await attachment.startTransaction();
|
|
99
130
|
expect(transaction1.isValid).toBeTruthy();
|
|
100
131
|
expect((await attachment.executeSingleton(transaction1, isolationQuery))[0]).toBe('SNAPSHOT');
|
|
101
132
|
await transaction1.commit();
|
|
102
133
|
expect(transaction1.isValid).toBeFalsy();
|
|
103
|
-
const transaction2 = await attachment.startTransaction({
|
|
134
|
+
const transaction2 = await attachment.startTransaction({
|
|
135
|
+
isolation: lib_1.TransactionIsolation.READ_COMMITTED,
|
|
136
|
+
});
|
|
104
137
|
expect(transaction2.isValid).toBeTruthy();
|
|
105
138
|
expect((await attachment.executeSingleton(transaction2, isolationQuery))[0]).toBe('READ COMMITTED');
|
|
106
139
|
await transaction2.commit();
|
|
107
140
|
expect(transaction2.isValid).toBeFalsy();
|
|
108
|
-
const transaction3 = await attachment.startTransaction({
|
|
141
|
+
const transaction3 = await attachment.startTransaction({
|
|
142
|
+
isolation: lib_1.TransactionIsolation.CONSISTENCY,
|
|
143
|
+
});
|
|
109
144
|
expect(transaction3.isValid).toBeTruthy();
|
|
110
145
|
expect((await attachment.executeSingleton(transaction3, isolationQuery))[0]).toBe('CONSISTENCY');
|
|
111
146
|
await transaction3.commit();
|
|
@@ -125,15 +160,33 @@ function runCommonTests(client) {
|
|
|
125
160
|
}
|
|
126
161
|
catch (e) {
|
|
127
162
|
error = e;
|
|
128
|
-
expect(error.message).toBe('Dynamic SQL Error\n' +
|
|
129
|
-
'-SQL error code = -104\n' +
|
|
130
|
-
'-Token unknown - line 1, column 8\n' +
|
|
131
|
-
'-select');
|
|
163
|
+
expect(error.message).toBe('Dynamic SQL Error\n' + '-SQL error code = -104\n' + '-Token unknown - line 1, column 8\n' + '-select');
|
|
132
164
|
}
|
|
133
165
|
expect(error).toBeTruthy();
|
|
134
166
|
await transaction.commit();
|
|
135
167
|
await attachment.dropDatabase();
|
|
136
168
|
});
|
|
169
|
+
test('statement.type', async () => {
|
|
170
|
+
const attachment = await client.createDatabase(getTempFile('Statement-type.fdb'));
|
|
171
|
+
const transaction = await attachment.startTransaction();
|
|
172
|
+
const s1 = await attachment.prepare(transaction, 'select * from rdb$database');
|
|
173
|
+
expect(await s1.type).toBe(lib_1.StatementType.SELECT);
|
|
174
|
+
await s1.dispose();
|
|
175
|
+
const s2 = await attachment.prepare(transaction, "insert into rdb$types (rdb$type_name, rdb$type, rdb$field_name) values ('A', 1, 'B')");
|
|
176
|
+
expect(await s2.type).toBe(lib_1.StatementType.INSERT);
|
|
177
|
+
await s2.dispose();
|
|
178
|
+
const s3 = await attachment.prepare(transaction, 'update rdb$database set rdb$description = null');
|
|
179
|
+
expect(await s3.type).toBe(lib_1.StatementType.UPDATE);
|
|
180
|
+
await s3.dispose();
|
|
181
|
+
const s4 = await attachment.prepare(transaction, 'delete from rdb$types where 1 = 0');
|
|
182
|
+
expect(await s4.type).toBe(lib_1.StatementType.DELETE);
|
|
183
|
+
await s4.dispose();
|
|
184
|
+
const s5 = await attachment.prepare(transaction, 'create table t_stmt_type (n integer)');
|
|
185
|
+
expect(await s5.type).toBe(lib_1.StatementType.DDL);
|
|
186
|
+
await s5.dispose();
|
|
187
|
+
await transaction.commit();
|
|
188
|
+
await attachment.dropDatabase();
|
|
189
|
+
});
|
|
137
190
|
//// TODO: #executeTransaction
|
|
138
191
|
test('#execute()', async () => {
|
|
139
192
|
const attachment = await client.createDatabase(getTempFile('Attachment-execute.fdb'));
|
|
@@ -202,7 +255,7 @@ function runCommonTests(client) {
|
|
|
202
255
|
const attachment = await client.createDatabase(getTempFile('Attachment-queueEvents.fdb'));
|
|
203
256
|
const eventNames = [
|
|
204
257
|
['EVENT1', 16],
|
|
205
|
-
['EVENT2', 8]
|
|
258
|
+
['EVENT2', 8],
|
|
206
259
|
];
|
|
207
260
|
const eventsObj = eventNames.map(([name, expected]) => {
|
|
208
261
|
let resolver = undefined;
|
|
@@ -210,20 +263,21 @@ function runCommonTests(client) {
|
|
|
210
263
|
name,
|
|
211
264
|
expected,
|
|
212
265
|
count: 0,
|
|
213
|
-
promise: new Promise(resolve => resolver = resolve)
|
|
266
|
+
promise: new Promise((resolve) => (resolver = resolve)),
|
|
214
267
|
};
|
|
215
268
|
return { ...obj, resolver };
|
|
216
269
|
});
|
|
217
|
-
const eventsMap = new Map(eventsObj.map(ev => [ev.name, ev]));
|
|
270
|
+
const eventsMap = new Map(eventsObj.map((ev) => [ev.name, ev]));
|
|
218
271
|
const eventHandler = async (counters) => {
|
|
219
272
|
counters.forEach(([name, count]) => {
|
|
220
273
|
const obj = eventsMap.get(name);
|
|
221
274
|
const newCount = obj.count + count;
|
|
222
275
|
obj.count = newCount;
|
|
223
|
-
if (newCount >= obj.expected)
|
|
276
|
+
if (newCount >= obj.expected) {
|
|
224
277
|
obj.resolver();
|
|
278
|
+
}
|
|
225
279
|
});
|
|
226
|
-
if (Array.from(eventsMap.values()).every(obj => obj.count >= obj.expected)) {
|
|
280
|
+
if (Array.from(eventsMap.values()).every((obj) => obj.count >= obj.expected)) {
|
|
227
281
|
if (events) {
|
|
228
282
|
await events.cancel();
|
|
229
283
|
expect(events.isValid).toBeFalsy();
|
|
@@ -256,10 +310,11 @@ function runCommonTests(client) {
|
|
|
256
310
|
await transaction.commit();
|
|
257
311
|
expect(transaction.isValid).toBeFalsy();
|
|
258
312
|
}
|
|
259
|
-
await Promise.all(eventsObj.map(ev => ev.promise));
|
|
260
|
-
if (events)
|
|
313
|
+
await Promise.all(eventsObj.map((ev) => ev.promise));
|
|
314
|
+
if (events) {
|
|
261
315
|
await events.cancel();
|
|
262
|
-
|
|
316
|
+
}
|
|
317
|
+
eventsObj.forEach((ev) => expect(ev.count).toBeGreaterThanOrEqual(ev.expected));
|
|
263
318
|
await attachment.dropDatabase();
|
|
264
319
|
});
|
|
265
320
|
test('#cancelOperation()', async () => {
|
|
@@ -272,9 +327,10 @@ function runCommonTests(client) {
|
|
|
272
327
|
await attachment.execute(transaction1, 'update t1 set n1 = n1 + 1');
|
|
273
328
|
await attachment.enableCancellation(true);
|
|
274
329
|
const transaction2 = await attachment.startTransaction();
|
|
275
|
-
const promise = attachment
|
|
276
|
-
.
|
|
277
|
-
|
|
330
|
+
const promise = attachment
|
|
331
|
+
.execute(transaction2, 'update t1 set n1 = n1 - 1')
|
|
332
|
+
.catch((e) => `Error: ${e.message}`);
|
|
333
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
278
334
|
await attachment.cancelOperation();
|
|
279
335
|
await expect(promise).resolves.toEqual('Error: operation was cancelled');
|
|
280
336
|
await transaction2.commit();
|
|
@@ -432,55 +488,116 @@ function runCommonTests(client) {
|
|
|
432
488
|
const fields = [
|
|
433
489
|
{ name: 'x_short', type: 'numeric(2)', valToStr: (v) => v },
|
|
434
490
|
{ name: 'x_int', type: 'integer', valToStr: (v) => v },
|
|
435
|
-
{
|
|
491
|
+
{
|
|
492
|
+
name: 'x_int_scale',
|
|
493
|
+
type: 'numeric(5, 2)',
|
|
494
|
+
valToStr: (v) => v,
|
|
495
|
+
},
|
|
436
496
|
{ name: 'x_bigint', type: 'bigint', valToStr: (v) => v },
|
|
437
|
-
{
|
|
497
|
+
{
|
|
498
|
+
name: 'x_bigint_scale',
|
|
499
|
+
type: 'numeric(15, 2)',
|
|
500
|
+
valToStr: (v) => v,
|
|
501
|
+
},
|
|
438
502
|
{ name: 'x_int128', type: 'int128', valToStr: (v) => v },
|
|
439
|
-
{
|
|
503
|
+
{
|
|
504
|
+
name: 'x_int128_scale',
|
|
505
|
+
type: 'numeric(20, 2)',
|
|
506
|
+
valToStr: (v) => v,
|
|
507
|
+
},
|
|
440
508
|
{ name: 'x_dec16', type: 'decfloat(16)', valToStr: (v) => v },
|
|
441
509
|
{ name: 'x_dec34', type: 'decfloat(34)', valToStr: (v) => v },
|
|
442
|
-
{
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
510
|
+
{
|
|
511
|
+
name: 'x_double',
|
|
512
|
+
type: 'double precision',
|
|
513
|
+
valToStr: (v) => v,
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
name: 'x_date1',
|
|
517
|
+
type: 'date',
|
|
518
|
+
valToStr: (v) => `date '${dateToString(v)}'`,
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
name: 'x_date2',
|
|
522
|
+
type: 'date',
|
|
523
|
+
valToStr: (v) => `date '${dateToString(v)}'`,
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
name: 'x_date3',
|
|
527
|
+
type: 'date',
|
|
528
|
+
valToStr: (v) => `date '${dateToString(v)}'`,
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
name: 'x_time',
|
|
532
|
+
type: 'time',
|
|
533
|
+
valToStr: (v) => `time '${timeToString(v)}'`,
|
|
534
|
+
},
|
|
447
535
|
{
|
|
448
536
|
name: 'x_time_tz1',
|
|
449
537
|
type: 'time with time zone',
|
|
450
|
-
valToStr: (v) => `${timeTzToString({ date: v.date, timeZone: 'GMT', offset: 0 })} at time zone '${v.timeZone}'
|
|
538
|
+
valToStr: (v) => `${timeTzToString({ date: v.date, timeZone: 'GMT', offset: 0 })} at time zone '${v.timeZone}'`,
|
|
451
539
|
},
|
|
452
540
|
{
|
|
453
541
|
name: 'x_time_tz2',
|
|
454
542
|
type: 'time with time zone',
|
|
455
|
-
valToStr: (v) => `${timeTzToString({ date: v.date, timeZone: 'GMT', offset: 0 })} at time zone '${v.timeZone}'
|
|
543
|
+
valToStr: (v) => `${timeTzToString({ date: v.date, timeZone: 'GMT', offset: 0 })} at time zone '${v.timeZone}'`,
|
|
544
|
+
},
|
|
545
|
+
{
|
|
546
|
+
name: 'x_timestamp1',
|
|
547
|
+
type: 'timestamp',
|
|
548
|
+
valToStr: (v) => `timestamp '${dateTimeToString(v)}'`,
|
|
549
|
+
},
|
|
550
|
+
{
|
|
551
|
+
name: 'x_timestamp2',
|
|
552
|
+
type: 'timestamp',
|
|
553
|
+
valToStr: (v) => `timestamp '${dateTimeToString(v)}'`,
|
|
554
|
+
},
|
|
555
|
+
{
|
|
556
|
+
name: 'x_timestamp3',
|
|
557
|
+
type: 'timestamp',
|
|
558
|
+
valToStr: (v) => `timestamp '${dateTimeToString(v)}'`,
|
|
456
559
|
},
|
|
457
|
-
{ name: 'x_timestamp1', type: 'timestamp', valToStr: (v) => `timestamp '${dateTimeToString(v)}'` },
|
|
458
|
-
{ name: 'x_timestamp2', type: 'timestamp', valToStr: (v) => `timestamp '${dateTimeToString(v)}'` },
|
|
459
|
-
{ name: 'x_timestamp3', type: 'timestamp', valToStr: (v) => `timestamp '${dateTimeToString(v)}'` },
|
|
460
560
|
{
|
|
461
561
|
name: 'x_timestamp_tz1',
|
|
462
562
|
type: 'timestamp with time zone',
|
|
463
|
-
valToStr: (v) => `${dateTimeTzToString({ date: v.date, timeZone: 'GMT', offset: 0 })} at time zone '${v.timeZone}'
|
|
563
|
+
valToStr: (v) => `${dateTimeTzToString({ date: v.date, timeZone: 'GMT', offset: 0 })} at time zone '${v.timeZone}'`,
|
|
464
564
|
},
|
|
465
565
|
{
|
|
466
566
|
name: 'x_timestamp_tz2',
|
|
467
567
|
type: 'timestamp with time zone',
|
|
468
|
-
valToStr: (v) => `${dateTimeTzToString({ date: v.date, timeZone: 'GMT', offset: 0 })} at time zone '${v.timeZone}'
|
|
568
|
+
valToStr: (v) => `${dateTimeTzToString({ date: v.date, timeZone: 'GMT', offset: 0 })} at time zone '${v.timeZone}'`,
|
|
469
569
|
},
|
|
470
570
|
{ name: 'x_boolean', type: 'boolean', valToStr: (v) => v },
|
|
471
|
-
{
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
571
|
+
{
|
|
572
|
+
name: 'x_varchar',
|
|
573
|
+
type: 'varchar(10) character set utf8',
|
|
574
|
+
valToStr: (v) => `'${v}'`,
|
|
575
|
+
},
|
|
576
|
+
{
|
|
577
|
+
name: 'x_char',
|
|
578
|
+
type: 'char(10) character set utf8',
|
|
579
|
+
valToStr: (v) => `'${v}'`,
|
|
580
|
+
},
|
|
581
|
+
{
|
|
582
|
+
name: 'x_blob1',
|
|
583
|
+
type: 'blob',
|
|
584
|
+
valToStr: (v) => `'${v.toString()}'`,
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
name: 'x_blob2',
|
|
588
|
+
type: 'blob',
|
|
589
|
+
valToStr: () => `'${blobBuffer.toString()}'`,
|
|
590
|
+
},
|
|
475
591
|
];
|
|
476
|
-
const statement1 = await attachment.prepare(transaction, `create table t1 (${fields.map(f => `${f.name} ${f.type}`).join(', ')})`);
|
|
592
|
+
const statement1 = await attachment.prepare(transaction, `create table t1 (${fields.map((f) => `${f.name} ${f.type}`).join(', ')})`);
|
|
477
593
|
await statement1.execute(transaction);
|
|
478
594
|
await statement1.dispose();
|
|
479
595
|
await transaction.commitRetaining();
|
|
480
596
|
const recordCount = 5;
|
|
481
597
|
let parameters;
|
|
482
|
-
{
|
|
483
|
-
|
|
598
|
+
{
|
|
599
|
+
// scope
|
|
600
|
+
const statement2a = await attachment.prepare(transaction, `insert into t1 (${fields.map((f) => f.name).join(', ')}) values (${fields.map(() => '?').join(', ')})`);
|
|
484
601
|
// Test execution in a new transaction, after the one used in prepare was committed.
|
|
485
602
|
await transaction.commit();
|
|
486
603
|
transaction = await attachment.startTransaction();
|
|
@@ -507,32 +624,41 @@ function runCommonTests(client) {
|
|
|
507
624
|
new Date(2020, 1 - 1, 1, 11, 56, 32, 123),
|
|
508
625
|
{
|
|
509
626
|
date: new Date(Date.UTC(2020, 1 - 1, 1, 11, 56, 32, 123)),
|
|
510
|
-
timeZone: 'America/New_York'
|
|
627
|
+
timeZone: 'America/New_York',
|
|
511
628
|
},
|
|
512
629
|
{
|
|
513
630
|
date: new Date(Date.UTC(2020, 1 - 1, 1, 11, 56, 32, 123)),
|
|
514
|
-
timeZone: 'America/Sao_Paulo'
|
|
631
|
+
timeZone: 'America/Sao_Paulo',
|
|
515
632
|
},
|
|
516
633
|
new Date(2017, 3 - 1, 26, 11, 56, 32, 123),
|
|
517
634
|
new Date(new Date(2000, 3 - 1, 26, 11, 56, 32, 123).setFullYear(50)),
|
|
518
635
|
new Date(9999, 3 - 1, 26, 11, 56, 32, 123),
|
|
519
|
-
{
|
|
520
|
-
|
|
636
|
+
{
|
|
637
|
+
date: new Date(Date.UTC(2021, 6 - 1, 7, 11, 56, 32, 123)),
|
|
638
|
+
timeZone: 'America/New_York',
|
|
639
|
+
},
|
|
640
|
+
{
|
|
641
|
+
date: new Date(Date.UTC(2021, 6 - 1, 7, 11, 56, 32, 123)),
|
|
642
|
+
timeZone: 'America/Sao_Paulo',
|
|
643
|
+
},
|
|
521
644
|
true,
|
|
522
645
|
'123áé4567',
|
|
523
646
|
'123áé4567',
|
|
524
647
|
blobBuffer,
|
|
525
|
-
blob
|
|
648
|
+
blob,
|
|
526
649
|
];
|
|
527
|
-
for (let i = 0; i < recordCount; ++i)
|
|
650
|
+
for (let i = 0; i < recordCount; ++i) {
|
|
528
651
|
await statement2a.execute(transaction, parameters);
|
|
652
|
+
}
|
|
529
653
|
await statement2a.dispose();
|
|
530
654
|
}
|
|
531
|
-
{
|
|
532
|
-
|
|
655
|
+
{
|
|
656
|
+
// scope
|
|
657
|
+
const statement2b = await attachment.prepare(transaction, `insert into t1 (${fields.map((f) => f.name).join(', ')}) ` +
|
|
533
658
|
`values (${parameters.map((val, index) => fields[index].valToStr(val)).join(', ')})`);
|
|
534
|
-
for (let i = 0; i < recordCount; ++i)
|
|
659
|
+
for (let i = 0; i < recordCount; ++i) {
|
|
535
660
|
await statement2b.execute(transaction);
|
|
661
|
+
}
|
|
536
662
|
await statement2b.dispose();
|
|
537
663
|
}
|
|
538
664
|
await transaction.commitRetaining();
|
|
@@ -666,7 +792,7 @@ function runCommonTests(client) {
|
|
|
666
792
|
test('#fetch() with fetchSize and exception', async () => {
|
|
667
793
|
const attachment = await client.createDatabase(getTempFile('ResultSet-fetch-with-fetchSize.fdb'));
|
|
668
794
|
const transaction = await attachment.startTransaction();
|
|
669
|
-
await attachment.execute(transaction,
|
|
795
|
+
await attachment.execute(transaction, "create exception e1 'e1'");
|
|
670
796
|
await transaction.commitRetaining();
|
|
671
797
|
const rs = await attachment.executeQuery(transaction, `
|
|
672
798
|
execute block returns (n integer)
|
|
@@ -705,8 +831,9 @@ function runCommonTests(client) {
|
|
|
705
831
|
const resultBuffer = Buffer.alloc(blobLength);
|
|
706
832
|
let size = 0;
|
|
707
833
|
let n;
|
|
708
|
-
while (size < blobLength && (n = await readStream.read(resultBuffer.slice(size))) > 0)
|
|
834
|
+
while (size < blobLength && (n = await readStream.read(resultBuffer.slice(size))) > 0) {
|
|
709
835
|
size += n;
|
|
836
|
+
}
|
|
710
837
|
await readStream.close();
|
|
711
838
|
expect(resultBuffer.toString().length).toEqual(buffer.toString().length);
|
|
712
839
|
expect(resultBuffer.toString()).toEqual(buffer.toString());
|
|
@@ -721,7 +848,9 @@ function runCommonTests(client) {
|
|
|
721
848
|
const transaction = await attachment.startTransaction();
|
|
722
849
|
await attachment.execute(transaction, 'create table t1 (b blob)');
|
|
723
850
|
await transaction.commitRetaining();
|
|
724
|
-
const blobStream = await attachment.createBlob(transaction, {
|
|
851
|
+
const blobStream = await attachment.createBlob(transaction, {
|
|
852
|
+
type: 'STREAM',
|
|
853
|
+
});
|
|
725
854
|
await blobStream.write(Buffer.alloc(10, '1234567890'));
|
|
726
855
|
await blobStream.close();
|
|
727
856
|
await attachment.execute(transaction, 'insert into t1 (b) values (?)', [blobStream.blob]);
|