node-firebird-native-api 3.1.0 → 3.1.3
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 +8 -6
- package/dist/generate-files/index.js +2 -1
- package/dist/generate-files/index.js.map +1 -1
- package/dist/generate-files/patch.js +31 -94
- package/dist/generate-files/patch.js.map +1 -1
- package/dist/lib/cloop-gen.js +8 -4
- package/dist/lib/cloop-gen.js.map +1 -1
- package/dist/lib/index.js +3 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/test/test.js +12 -16
- package/dist/test/test.js.map +1 -1
- package/package.json +8 -7
- package/src/generate-files/firebird.cloop.json +10436 -7796
- package/src/generate-files/index.ts +5 -5
- package/src/generate-files/patch.ts +148 -221
- package/src/lib/cloop-gen.ts +1494 -925
- package/src/lib/index.ts +13 -13
- package/src/native/classes.h +6 -157
- package/src/test/test.ts +537 -542
- package/tsconfig.json +7 -13
- package/tslint.json +0 -6
package/src/test/test.ts
CHANGED
|
@@ -4,549 +4,544 @@ import * as tmp from 'temp-fs';
|
|
|
4
4
|
import { disposeMaster, getDefaultLibraryFilename, getMaster, Master, Provider, Util } from '../lib';
|
|
5
5
|
import { XpbBuilder } from '../lib';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
8
8
|
require('dotenv').config({ path: '../../.env' });
|
|
9
9
|
|
|
10
|
-
|
|
11
10
|
describe('node-firebird-native-api', () => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
status.disposeSync();
|
|
549
|
-
}
|
|
550
|
-
});
|
|
551
|
-
});
|
|
11
|
+
const testConfig = {
|
|
12
|
+
username: process.env.ISC_USER,
|
|
13
|
+
password: process.env.ISC_PASSWORD,
|
|
14
|
+
host: process.env.NODE_FB_TEST_HOST,
|
|
15
|
+
port: process.env.NODE_FB_TEST_PORT,
|
|
16
|
+
tmpDir: process.env.NODE_FB_TEST_TMP_DIR,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
let master: Master;
|
|
20
|
+
let dispatcher: Provider;
|
|
21
|
+
|
|
22
|
+
function isLocal(): boolean {
|
|
23
|
+
return testConfig.host == undefined || testConfig.host == 'localhost' || testConfig.host == '127.0.0.1';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function getTempFile(name: string): string {
|
|
27
|
+
const database = `${testConfig.tmpDir}/${name}`;
|
|
28
|
+
return (
|
|
29
|
+
(testConfig.host ?? '') +
|
|
30
|
+
(testConfig.host && testConfig.port ? `/${testConfig.port}` : '') +
|
|
31
|
+
(testConfig.host ? ':' : '') +
|
|
32
|
+
database
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
jest.setTimeout(10000);
|
|
37
|
+
|
|
38
|
+
beforeAll(() => {
|
|
39
|
+
if (isLocal() && !testConfig.tmpDir) {
|
|
40
|
+
testConfig.tmpDir = tmp.mkdirSync().path.toString();
|
|
41
|
+
|
|
42
|
+
// Important for MacOS tests with non-embedded server.
|
|
43
|
+
fs.chmodSync(testConfig.tmpDir, 0o777);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const tempMaster = getMaster(getDefaultLibraryFilename());
|
|
47
|
+
|
|
48
|
+
master = getMaster(getDefaultLibraryFilename());
|
|
49
|
+
dispatcher = master.getDispatcherSync()!;
|
|
50
|
+
|
|
51
|
+
// Test premature shutdown prevention. 'master' variable should still be usable.
|
|
52
|
+
expect(disposeMaster(tempMaster)).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
afterAll(() => {
|
|
56
|
+
if (!master) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const status = master.getStatusSync()!;
|
|
61
|
+
const fb_shutrsn_app_stopped = -3;
|
|
62
|
+
dispatcher.shutdownSync(status, 0, fb_shutrsn_app_stopped);
|
|
63
|
+
status.disposeSync();
|
|
64
|
+
|
|
65
|
+
dispatcher.releaseSync();
|
|
66
|
+
|
|
67
|
+
if (isLocal()) {
|
|
68
|
+
fs.rmdirSync(testConfig.tmpDir!);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
expect(disposeMaster(master)).toBe(true);
|
|
72
|
+
expect(disposeMaster(master)).toBe(false);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('getMaster', () => {
|
|
76
|
+
test('with error', () => {
|
|
77
|
+
expect(() => getMaster('not-a-firebird-client-library')).toThrow();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('Master', () => {
|
|
82
|
+
test('#getStatus()', () => {
|
|
83
|
+
const status = master.getStatusSync()!;
|
|
84
|
+
expect(status).toBeTruthy();
|
|
85
|
+
status.disposeSync();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('#getDispatcher()', () => {
|
|
89
|
+
const thisDispatcher = master.getDispatcherSync()!;
|
|
90
|
+
expect(thisDispatcher).toBeTruthy();
|
|
91
|
+
thisDispatcher.addRefSync();
|
|
92
|
+
expect(thisDispatcher.releaseSync()).toBe(1);
|
|
93
|
+
expect(thisDispatcher.releaseSync()).toBe(0);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('#getUtilInterface()', () => {
|
|
97
|
+
const util = master.getUtilInterfaceSync();
|
|
98
|
+
expect(util).toBeTruthy();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('Util', () => {
|
|
103
|
+
const DATE_2016_10_14 = 57675;
|
|
104
|
+
let util: Util;
|
|
105
|
+
|
|
106
|
+
beforeAll(() => {
|
|
107
|
+
util = master.getUtilInterfaceSync()!;
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('#encodeDate()', () => {
|
|
111
|
+
const n = util.encodeDateSync(2016, 10, 14);
|
|
112
|
+
expect(n).toBe(DATE_2016_10_14);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('#decodeDate()', () => {
|
|
116
|
+
const year = new Uint32Array(1);
|
|
117
|
+
const month = new Uint32Array(1);
|
|
118
|
+
const day = new Uint32Array(1);
|
|
119
|
+
|
|
120
|
+
util.decodeDateSync(DATE_2016_10_14, year, month, day);
|
|
121
|
+
|
|
122
|
+
expect(year[0]).toBe(2016);
|
|
123
|
+
expect(month[0]).toBe(10);
|
|
124
|
+
expect(day[0]).toBe(14);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('#getClientVersion()', () => {
|
|
128
|
+
const rawVersion = util.getClientVersionSync();
|
|
129
|
+
const majorVersion = rawVersion >> 8;
|
|
130
|
+
expect(majorVersion).toBeGreaterThanOrEqual(3);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('Provider', () => {
|
|
135
|
+
test('wrong status class', () => {
|
|
136
|
+
expect(() =>
|
|
137
|
+
dispatcher.createDatabaseSync(master as any, getTempFile('wrong-class.fdb'), 0, undefined),
|
|
138
|
+
).toThrow();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('#createDatabaseSync()', () => {
|
|
142
|
+
const status = master.getStatusSync()!;
|
|
143
|
+
try {
|
|
144
|
+
const attachment = dispatcher.createDatabaseSync(
|
|
145
|
+
status,
|
|
146
|
+
getTempFile('Provider-createDatabaseSync.fdb'),
|
|
147
|
+
0,
|
|
148
|
+
undefined,
|
|
149
|
+
)!;
|
|
150
|
+
attachment.dropDatabaseSync(status);
|
|
151
|
+
} finally {
|
|
152
|
+
status.disposeSync();
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('#createDatabaseAsync()', async () => {
|
|
157
|
+
const status = master.getStatusSync()!;
|
|
158
|
+
try {
|
|
159
|
+
const attachment = (await dispatcher.createDatabaseAsync(
|
|
160
|
+
status,
|
|
161
|
+
getTempFile('Attachment-createDatabase.fdb'),
|
|
162
|
+
0,
|
|
163
|
+
undefined,
|
|
164
|
+
))!;
|
|
165
|
+
await attachment.dropDatabaseAsync(status);
|
|
166
|
+
} finally {
|
|
167
|
+
status.disposeSync();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('#createDatabaseAsync() with XpbBuilder buffer', async () => {
|
|
172
|
+
const util = master.getUtilInterfaceSync();
|
|
173
|
+
|
|
174
|
+
const status = master.getStatusSync()!;
|
|
175
|
+
const dpbBuilder = util!.getXpbBuilderSync(status, XpbBuilder.DPB, undefined, 0)!;
|
|
176
|
+
try {
|
|
177
|
+
dpbBuilder.insertTagSync(status, 1);
|
|
178
|
+
|
|
179
|
+
const buffer = dpbBuilder.getBufferSync(status)!;
|
|
180
|
+
const length = dpbBuilder.getBufferLengthSync(status);
|
|
181
|
+
|
|
182
|
+
const attachment = (await dispatcher.createDatabaseAsync(
|
|
183
|
+
status,
|
|
184
|
+
getTempFile('Attachment-createDatabase-xpb.fdb'),
|
|
185
|
+
length,
|
|
186
|
+
buffer,
|
|
187
|
+
))!;
|
|
188
|
+
await attachment.dropDatabaseAsync(status);
|
|
189
|
+
} finally {
|
|
190
|
+
dpbBuilder.disposeSync();
|
|
191
|
+
status.disposeSync();
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe('Attachment', () => {
|
|
197
|
+
test('#dropDatabaseSync()', () => {
|
|
198
|
+
const status = master.getStatusSync()!;
|
|
199
|
+
try {
|
|
200
|
+
const attachment = dispatcher.createDatabaseSync(
|
|
201
|
+
status,
|
|
202
|
+
getTempFile('Attachment-dropDatabaseSync.fdb'),
|
|
203
|
+
0,
|
|
204
|
+
undefined,
|
|
205
|
+
)!;
|
|
206
|
+
attachment.dropDatabaseSync(status);
|
|
207
|
+
} finally {
|
|
208
|
+
status.disposeSync();
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('#dropDatabaseAsync()', async () => {
|
|
213
|
+
const status = master.getStatusSync()!;
|
|
214
|
+
try {
|
|
215
|
+
const attachment = (await dispatcher.createDatabaseAsync(
|
|
216
|
+
status,
|
|
217
|
+
getTempFile('Attachment-dropDatabase.fdb'),
|
|
218
|
+
0,
|
|
219
|
+
undefined,
|
|
220
|
+
))!;
|
|
221
|
+
await attachment.dropDatabaseAsync(status);
|
|
222
|
+
} finally {
|
|
223
|
+
status.disposeSync();
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test('#detachSync()', () => {
|
|
228
|
+
const status = master.getStatusSync()!;
|
|
229
|
+
try {
|
|
230
|
+
const filename = getTempFile('Attachment-detachSync.fdb');
|
|
231
|
+
const attachment = dispatcher.createDatabaseSync(status, filename, 0, undefined)!;
|
|
232
|
+
attachment.detachSync(status);
|
|
233
|
+
fs.removeSync(filename);
|
|
234
|
+
} finally {
|
|
235
|
+
status.disposeSync();
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test('#detachAsync()', async () => {
|
|
240
|
+
const status = master.getStatusSync()!;
|
|
241
|
+
try {
|
|
242
|
+
const filename = getTempFile('Attachment-detach.fdb');
|
|
243
|
+
const attachment = (await dispatcher.createDatabaseAsync(status, filename, 0, undefined))!;
|
|
244
|
+
await attachment.detachAsync(status);
|
|
245
|
+
await fs.removeAsync(filename);
|
|
246
|
+
} finally {
|
|
247
|
+
status.disposeSync();
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test('#startTransactionSync()', () => {
|
|
252
|
+
const status = master.getStatusSync()!;
|
|
253
|
+
try {
|
|
254
|
+
const filename = getTempFile('Attachment-startTransactionSync.fdb');
|
|
255
|
+
|
|
256
|
+
const attachment = dispatcher.createDatabaseSync(status, filename, 0, undefined)!;
|
|
257
|
+
try {
|
|
258
|
+
const transaction = attachment.startTransactionSync(status, 0, undefined)!;
|
|
259
|
+
transaction.commitSync(status);
|
|
260
|
+
} finally {
|
|
261
|
+
attachment.dropDatabaseSync(status);
|
|
262
|
+
}
|
|
263
|
+
} finally {
|
|
264
|
+
status.disposeSync();
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test('#startTransactionAsync()', async () => {
|
|
269
|
+
const status = master.getStatusSync()!;
|
|
270
|
+
try {
|
|
271
|
+
const filename = getTempFile('Attachment-startTransaction.fdb');
|
|
272
|
+
|
|
273
|
+
const attachment = (await dispatcher.createDatabaseAsync(status, filename, 0, undefined))!;
|
|
274
|
+
try {
|
|
275
|
+
const transaction = (await attachment.startTransactionAsync(status, 0, undefined))!;
|
|
276
|
+
await transaction.commitAsync(status);
|
|
277
|
+
} finally {
|
|
278
|
+
await attachment.dropDatabaseAsync(status);
|
|
279
|
+
}
|
|
280
|
+
} finally {
|
|
281
|
+
status.disposeSync();
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test('#executeSync()', () => {
|
|
286
|
+
const status = master.getStatusSync()!;
|
|
287
|
+
try {
|
|
288
|
+
const filename = getTempFile('Attachment-executeSync.fdb');
|
|
289
|
+
const stmt1 = 'create table t1 (n1 integer)';
|
|
290
|
+
const stmt2 = 'insert into t1 values (1)';
|
|
291
|
+
const stmt3 = 'select'; // error
|
|
292
|
+
|
|
293
|
+
const attachment = dispatcher.createDatabaseSync(status, filename, 0, undefined)!;
|
|
294
|
+
try {
|
|
295
|
+
const transaction = attachment.startTransactionSync(status, 0, undefined)!;
|
|
296
|
+
try {
|
|
297
|
+
attachment.executeSync(status, transaction, 0, stmt1, 3, undefined, undefined, undefined, undefined);
|
|
298
|
+
transaction.commitRetainingSync(status);
|
|
299
|
+
attachment.executeSync(status, transaction, 0, stmt2, 3, undefined, undefined, undefined, undefined);
|
|
300
|
+
|
|
301
|
+
let error: Error | undefined;
|
|
302
|
+
try {
|
|
303
|
+
attachment.executeSync(status, transaction, 0, stmt3, 3, undefined, undefined, undefined, undefined);
|
|
304
|
+
} catch (e) {
|
|
305
|
+
error = e as Error;
|
|
306
|
+
expect(error.message).toBe(
|
|
307
|
+
'Dynamic SQL Error\n' + '-SQL error code = -104\n' + '-Unexpected end of command - line 1, column 1',
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
expect(error).toBeTruthy();
|
|
312
|
+
} finally {
|
|
313
|
+
transaction.commitSync(status);
|
|
314
|
+
}
|
|
315
|
+
} finally {
|
|
316
|
+
attachment.dropDatabaseSync(status);
|
|
317
|
+
}
|
|
318
|
+
} finally {
|
|
319
|
+
status.disposeSync();
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
test('#executeAsync()', async () => {
|
|
324
|
+
const status = master.getStatusSync()!;
|
|
325
|
+
try {
|
|
326
|
+
const filename = getTempFile('Attachment-execute.fdb');
|
|
327
|
+
const stmt1 = 'create table t1 (n1 integer)';
|
|
328
|
+
const stmt2 = 'insert into t1 values (1)';
|
|
329
|
+
const stmt3 = 'select'; // error
|
|
330
|
+
|
|
331
|
+
const attachment = (await dispatcher.createDatabaseAsync(status, filename, 0, undefined))!;
|
|
332
|
+
try {
|
|
333
|
+
const transaction = (await attachment.startTransactionAsync(status, 0, undefined))!;
|
|
334
|
+
try {
|
|
335
|
+
await attachment.executeAsync(status, transaction, 0, stmt1, 3, undefined, undefined, undefined, undefined);
|
|
336
|
+
await transaction.commitRetainingAsync(status);
|
|
337
|
+
await attachment.executeAsync(status, transaction, 0, stmt2, 3, undefined, undefined, undefined, undefined);
|
|
338
|
+
|
|
339
|
+
let error: Error | undefined;
|
|
340
|
+
try {
|
|
341
|
+
await attachment.executeAsync(
|
|
342
|
+
status,
|
|
343
|
+
transaction,
|
|
344
|
+
0,
|
|
345
|
+
stmt3,
|
|
346
|
+
3,
|
|
347
|
+
undefined,
|
|
348
|
+
undefined,
|
|
349
|
+
undefined,
|
|
350
|
+
undefined,
|
|
351
|
+
);
|
|
352
|
+
} catch (e) {
|
|
353
|
+
error = e as Error;
|
|
354
|
+
expect(error.message).toBe(
|
|
355
|
+
'Dynamic SQL Error\n' + '-SQL error code = -104\n' + '-Unexpected end of command - line 1, column 1',
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
expect(error).toBeTruthy();
|
|
360
|
+
} finally {
|
|
361
|
+
await transaction.commitAsync(status);
|
|
362
|
+
}
|
|
363
|
+
} finally {
|
|
364
|
+
await attachment.dropDatabaseAsync(status);
|
|
365
|
+
}
|
|
366
|
+
} finally {
|
|
367
|
+
status.disposeSync();
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
test('#prepareSync()', () => {
|
|
372
|
+
const status = master.getStatusSync()!;
|
|
373
|
+
try {
|
|
374
|
+
const filename = getTempFile('Attachment-prepareSync.fdb');
|
|
375
|
+
const stmt1 = 'create table t1 (n1 integer)';
|
|
376
|
+
const stmt2 = 'insert into t1 values (?)';
|
|
377
|
+
|
|
378
|
+
const attachment = dispatcher.createDatabaseSync(status, filename, 0, undefined)!;
|
|
379
|
+
try {
|
|
380
|
+
const transaction = attachment.startTransactionSync(status, 0, undefined)!;
|
|
381
|
+
try {
|
|
382
|
+
attachment.executeSync(status, transaction, 0, stmt1, 3, undefined, undefined, undefined, undefined);
|
|
383
|
+
transaction.commitRetainingSync(status);
|
|
384
|
+
|
|
385
|
+
const statement2 = attachment.prepareSync(status, transaction, 0, stmt2, 3, 0)!;
|
|
386
|
+
try {
|
|
387
|
+
const inputMetadata2 = statement2.getInputMetadataSync(status)!;
|
|
388
|
+
try {
|
|
389
|
+
expect(inputMetadata2.getCountSync(status)).toBe(1);
|
|
390
|
+
expect(inputMetadata2.getMessageLengthSync(status)).toBe(2 + 4);
|
|
391
|
+
} finally {
|
|
392
|
+
inputMetadata2.releaseSync();
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const outputMetadata2 = statement2.getOutputMetadataSync(status)!;
|
|
396
|
+
try {
|
|
397
|
+
expect(outputMetadata2.getCountSync(status)).toBe(0);
|
|
398
|
+
expect(outputMetadata2.getMessageLengthSync(status)).toBe(0);
|
|
399
|
+
} finally {
|
|
400
|
+
outputMetadata2.releaseSync();
|
|
401
|
+
}
|
|
402
|
+
} finally {
|
|
403
|
+
statement2.freeSync(status);
|
|
404
|
+
}
|
|
405
|
+
} finally {
|
|
406
|
+
transaction.commitSync(status);
|
|
407
|
+
}
|
|
408
|
+
} finally {
|
|
409
|
+
attachment.dropDatabaseSync(status);
|
|
410
|
+
}
|
|
411
|
+
} finally {
|
|
412
|
+
status.disposeSync();
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
test('#prepareAsync()', async () => {
|
|
417
|
+
const status = master.getStatusSync()!;
|
|
418
|
+
try {
|
|
419
|
+
const filename = getTempFile('Attachment-prepare.fdb');
|
|
420
|
+
const stmt1 = 'create table t1 (n1 integer)';
|
|
421
|
+
const stmt2 = 'insert into t1 values (?)';
|
|
422
|
+
|
|
423
|
+
const attachment = (await dispatcher.createDatabaseAsync(status, filename, 0, undefined))!;
|
|
424
|
+
try {
|
|
425
|
+
const transaction = (await attachment.startTransactionAsync(status, 0, undefined))!;
|
|
426
|
+
try {
|
|
427
|
+
await attachment.executeAsync(status, transaction, 0, stmt1, 3, undefined, undefined, undefined, undefined);
|
|
428
|
+
await transaction.commitRetainingAsync(status);
|
|
429
|
+
|
|
430
|
+
const statement2 = (await attachment.prepareAsync(status, transaction, 0, stmt2, 3, 0))!;
|
|
431
|
+
try {
|
|
432
|
+
const inputMetadata2 = (await statement2.getInputMetadataAsync(status))!;
|
|
433
|
+
try {
|
|
434
|
+
expect(inputMetadata2.getCountSync(status)).toBe(1);
|
|
435
|
+
expect(inputMetadata2.getMessageLengthSync(status)).toBe(2 + 4);
|
|
436
|
+
} finally {
|
|
437
|
+
inputMetadata2.releaseSync();
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const outputMetadata2 = (await statement2.getOutputMetadataAsync(status))!;
|
|
441
|
+
try {
|
|
442
|
+
expect(outputMetadata2.getCountSync(status)).toBe(0);
|
|
443
|
+
expect(outputMetadata2.getMessageLengthSync(status)).toBe(0);
|
|
444
|
+
} finally {
|
|
445
|
+
outputMetadata2.releaseSync();
|
|
446
|
+
}
|
|
447
|
+
} finally {
|
|
448
|
+
await statement2.freeAsync(status);
|
|
449
|
+
}
|
|
450
|
+
} finally {
|
|
451
|
+
await transaction.commitAsync(status);
|
|
452
|
+
}
|
|
453
|
+
} finally {
|
|
454
|
+
await attachment.dropDatabaseAsync(status);
|
|
455
|
+
}
|
|
456
|
+
} finally {
|
|
457
|
+
status.disposeSync();
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
describe('Statement', () => {
|
|
463
|
+
test('#getPlanSync()', () => {
|
|
464
|
+
const status = master.getStatusSync()!;
|
|
465
|
+
try {
|
|
466
|
+
const attachment = dispatcher.createDatabaseSync(
|
|
467
|
+
status,
|
|
468
|
+
getTempFile('Statement-getPlanSync.fdb'),
|
|
469
|
+
0,
|
|
470
|
+
undefined,
|
|
471
|
+
)!;
|
|
472
|
+
try {
|
|
473
|
+
const transaction = attachment.startTransactionSync(status, 0, undefined)!;
|
|
474
|
+
try {
|
|
475
|
+
const stmt1 = `create table t (n integer)`;
|
|
476
|
+
|
|
477
|
+
const statement1 = attachment.prepareSync(status, transaction, 0, stmt1, 3, 0)!;
|
|
478
|
+
try {
|
|
479
|
+
const plan = statement1.getPlanSync(status, false);
|
|
480
|
+
expect(plan).toBeNull();
|
|
481
|
+
} finally {
|
|
482
|
+
statement1.freeSync(status);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const stmt2 = `select rdb$relation_id from rdb$database`;
|
|
486
|
+
|
|
487
|
+
const statement2 = attachment.prepareSync(status, transaction, 0, stmt2, 3, 0)!;
|
|
488
|
+
try {
|
|
489
|
+
const plan = statement2.getPlanSync(status, false);
|
|
490
|
+
expect(plan!.trim()).toBe('PLAN (RDB$DATABASE NATURAL)');
|
|
491
|
+
} finally {
|
|
492
|
+
statement2.freeSync(status);
|
|
493
|
+
}
|
|
494
|
+
} finally {
|
|
495
|
+
transaction.commitSync(status);
|
|
496
|
+
}
|
|
497
|
+
} finally {
|
|
498
|
+
attachment.dropDatabaseSync(status);
|
|
499
|
+
}
|
|
500
|
+
} finally {
|
|
501
|
+
status.disposeSync();
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
test('#getPlanASync()', async () => {
|
|
506
|
+
const status = master.getStatusSync()!;
|
|
507
|
+
try {
|
|
508
|
+
const attachment = await dispatcher.createDatabaseAsync(
|
|
509
|
+
status,
|
|
510
|
+
getTempFile('Statement-getPlanAsync.fdb'),
|
|
511
|
+
0,
|
|
512
|
+
undefined,
|
|
513
|
+
)!;
|
|
514
|
+
try {
|
|
515
|
+
const transaction = await attachment!.startTransactionAsync(status, 0, undefined)!;
|
|
516
|
+
try {
|
|
517
|
+
const stmt1 = `create table t (n integer)`;
|
|
518
|
+
|
|
519
|
+
const statement1 = await attachment!.prepareAsync(status, transaction, 0, stmt1, 3, 0)!;
|
|
520
|
+
try {
|
|
521
|
+
const plan = await statement1!.getPlanAsync(status, false);
|
|
522
|
+
expect(plan).toBeNull();
|
|
523
|
+
} finally {
|
|
524
|
+
await statement1!.freeAsync(status);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
const stmt2 = `select rdb$relation_id from rdb$database`;
|
|
528
|
+
|
|
529
|
+
const statement2 = await attachment!.prepareAsync(status, transaction, 0, stmt2, 3, 0)!;
|
|
530
|
+
try {
|
|
531
|
+
const plan = await statement2!.getPlanAsync(status, false);
|
|
532
|
+
expect(plan!.trim()).toBe('PLAN (RDB$DATABASE NATURAL)');
|
|
533
|
+
} finally {
|
|
534
|
+
await statement2!.freeAsync(status);
|
|
535
|
+
}
|
|
536
|
+
} finally {
|
|
537
|
+
await transaction!.commitAsync(status);
|
|
538
|
+
}
|
|
539
|
+
} finally {
|
|
540
|
+
await attachment!.dropDatabaseAsync(status);
|
|
541
|
+
}
|
|
542
|
+
} finally {
|
|
543
|
+
status.disposeSync();
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
});
|
|
552
547
|
});
|