node-firebird-driver-native 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 +18 -20
- package/dist/lib/attachment.js +4 -4
- package/dist/lib/attachment.js.map +1 -1
- package/dist/lib/blob.js +6 -4
- package/dist/lib/blob.js.map +1 -1
- package/dist/lib/client.js.map +1 -1
- package/dist/lib/events.js.map +1 -1
- package/dist/lib/fb-util.js +5 -3
- package/dist/lib/fb-util.js.map +1 -1
- package/dist/lib/resultset.d.ts +1 -1
- package/dist/lib/resultset.js +11 -5
- package/dist/lib/resultset.js.map +1 -1
- package/dist/lib/statement.d.ts +7 -5
- package/dist/lib/statement.js +21 -8
- package/dist/lib/statement.js.map +1 -1
- package/dist/lib/transaction.js +4 -4
- package/dist/lib/transaction.js.map +1 -1
- package/package.json +8 -7
- package/src/lib/attachment.ts +92 -79
- package/src/lib/blob.ts +103 -89
- package/src/lib/client.ts +41 -48
- package/src/lib/events.ts +26 -24
- package/src/lib/fb-util.ts +73 -73
- package/src/lib/resultset.ts +94 -82
- package/src/lib/statement.ts +167 -141
- package/src/lib/transaction.ts +42 -37
- package/tsconfig.json +8 -17
package/src/lib/statement.ts
CHANGED
|
@@ -2,155 +2,181 @@ import { AttachmentImpl } from './attachment';
|
|
|
2
2
|
import { ResultSetImpl } from './resultset';
|
|
3
3
|
import { TransactionImpl } from './transaction';
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
ExecuteOptions,
|
|
7
|
-
ExecuteQueryOptions,
|
|
8
|
-
PrepareOptions
|
|
9
|
-
} from 'node-firebird-driver';
|
|
5
|
+
import { ExecuteOptions, ExecuteQueryOptions, PrepareOptions, StatementType } from 'node-firebird-driver';
|
|
10
6
|
|
|
11
7
|
import { AbstractStatement, commonInfo, getPortableInteger, statementInfo } from 'node-firebird-driver/dist/lib/impl';
|
|
12
8
|
|
|
13
|
-
import {
|
|
14
|
-
createDataReader,
|
|
15
|
-
createDataWriter,
|
|
16
|
-
createDescriptors,
|
|
17
|
-
fixMetadata,
|
|
18
|
-
DataReader,
|
|
19
|
-
DataWriter
|
|
20
|
-
} from './fb-util';
|
|
9
|
+
import { createDataReader, createDataWriter, createDescriptors, DataReader, DataWriter, fixMetadata } from './fb-util';
|
|
21
10
|
|
|
22
11
|
import * as fb from 'node-firebird-native-api';
|
|
23
12
|
|
|
24
13
|
import { TextDecoder } from 'util';
|
|
25
14
|
|
|
26
|
-
|
|
27
15
|
/** Statement implementation. */
|
|
28
16
|
export class StatementImpl extends AbstractStatement {
|
|
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
|
-
|
|
17
|
+
// Override declarations.
|
|
18
|
+
override attachment: AttachmentImpl;
|
|
19
|
+
override hasResultSet: boolean;
|
|
20
|
+
|
|
21
|
+
statementHandle?: fb.Statement;
|
|
22
|
+
inMetadata?: fb.MessageMetadata;
|
|
23
|
+
outMetadata?: fb.MessageMetadata;
|
|
24
|
+
inBuffer: Uint8Array;
|
|
25
|
+
outBuffer: Uint8Array;
|
|
26
|
+
dataWriter: DataWriter;
|
|
27
|
+
dataReader: DataReader;
|
|
28
|
+
typePromise?: Promise<StatementType>;
|
|
29
|
+
|
|
30
|
+
static async prepare(
|
|
31
|
+
attachment: AttachmentImpl,
|
|
32
|
+
transaction: TransactionImpl,
|
|
33
|
+
sqlStmt: string,
|
|
34
|
+
_options?: PrepareOptions,
|
|
35
|
+
): Promise<StatementImpl> {
|
|
36
|
+
const statement = new StatementImpl(attachment);
|
|
37
|
+
|
|
38
|
+
return await attachment.client.statusAction(async (status) => {
|
|
39
|
+
//// FIXME: options/flags, dialect
|
|
40
|
+
statement.statementHandle = await attachment!.attachmentHandle!.prepareAsync(
|
|
41
|
+
status,
|
|
42
|
+
transaction?.transactionHandle,
|
|
43
|
+
0,
|
|
44
|
+
sqlStmt,
|
|
45
|
+
3,
|
|
46
|
+
fb.Statement.PREPARE_PREFETCH_ALL,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
statement.hasResultSet = (statement.statementHandle!.getFlagsSync(status) & fb.Statement.FLAG_HAS_CURSOR) != 0;
|
|
50
|
+
|
|
51
|
+
statement.inMetadata = fixMetadata(status, await statement.statementHandle!.getInputMetadataAsync(status));
|
|
52
|
+
statement.outMetadata = fixMetadata(status, await statement.statementHandle!.getOutputMetadataAsync(status));
|
|
53
|
+
|
|
54
|
+
if (statement.inMetadata) {
|
|
55
|
+
statement.inBuffer = new Uint8Array(statement.inMetadata.getMessageLengthSync(status));
|
|
56
|
+
statement.dataWriter = createDataWriter(createDescriptors(status, statement.inMetadata));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (statement.outMetadata) {
|
|
60
|
+
statement.outBuffer = new Uint8Array(statement.outMetadata.getMessageLengthSync(status));
|
|
61
|
+
statement.dataReader = createDataReader(createDescriptors(status, statement.outMetadata));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return statement;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Disposes this statement's resources. */
|
|
69
|
+
protected async internalDispose(): Promise<void> {
|
|
70
|
+
if (this.outMetadata) {
|
|
71
|
+
this.outMetadata.releaseSync();
|
|
72
|
+
this.outMetadata = undefined;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (this.inMetadata) {
|
|
76
|
+
this.inMetadata.releaseSync();
|
|
77
|
+
this.inMetadata = undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
await this.attachment.client.statusAction((status) => this.statementHandle!.freeAsync(status));
|
|
81
|
+
|
|
82
|
+
this.statementHandle = undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Executes a prepared statement that uses the SET TRANSACTION command. Returns the new transaction. */
|
|
86
|
+
protected async internalExecuteTransaction(_transaction: TransactionImpl): Promise<TransactionImpl> {
|
|
87
|
+
throw new Error('Uninplemented method: executeTransaction.');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Executes a prepared statement that has no result set. */
|
|
91
|
+
protected async internalExecute(
|
|
92
|
+
transaction: TransactionImpl,
|
|
93
|
+
parameters?: any[],
|
|
94
|
+
_options?: ExecuteOptions,
|
|
95
|
+
): Promise<any[]> {
|
|
96
|
+
return await this.attachment.client.statusAction(async (status) => {
|
|
97
|
+
await this.dataWriter(this.attachment, transaction, this.inBuffer, parameters);
|
|
98
|
+
|
|
99
|
+
const newTransaction = await this.statementHandle!.executeAsync(
|
|
100
|
+
status,
|
|
101
|
+
transaction?.transactionHandle,
|
|
102
|
+
this.inMetadata,
|
|
103
|
+
this.inBuffer,
|
|
104
|
+
this.outMetadata,
|
|
105
|
+
this.outBuffer,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
if (newTransaction && transaction?.transactionHandle != newTransaction) {
|
|
109
|
+
//// FIXME: newTransaction.releaseSync();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return this.outMetadata ? await this.dataReader(this.attachment, transaction, this.outBuffer) : [];
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Executes a prepared statement that has result set. */
|
|
117
|
+
protected async internalExecuteQuery(
|
|
118
|
+
transaction: TransactionImpl,
|
|
119
|
+
parameters?: any[],
|
|
120
|
+
options?: ExecuteQueryOptions,
|
|
121
|
+
): Promise<ResultSetImpl> {
|
|
122
|
+
return await ResultSetImpl.open(this, transaction as TransactionImpl, parameters, options);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async setCursorName(cursorName: string): Promise<void> {
|
|
126
|
+
return await this.attachment.client.statusAction(
|
|
127
|
+
async (status) => await this.statementHandle!.setCursorNameAsync(status, cursorName),
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async getExecPathText(): Promise<string | undefined> {
|
|
132
|
+
return await this.attachment.client.statusAction(async (status) => {
|
|
133
|
+
const infoReq = new Uint8Array([statementInfo.sqlExecPathBlrText]);
|
|
134
|
+
const infoRet = new Uint8Array(65535);
|
|
135
|
+
await this.statementHandle!.getInfoAsync(status, infoReq.byteLength, infoReq, infoRet.byteLength, infoRet);
|
|
136
|
+
|
|
137
|
+
if (infoRet[0] == commonInfo.end) {
|
|
138
|
+
return undefined;
|
|
139
|
+
} else {
|
|
140
|
+
if (infoRet[0] != statementInfo.sqlExecPathBlrText) {
|
|
141
|
+
throw new Error('Error retrieving statement execution path.');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const size = getPortableInteger(infoRet.subarray(1), 2);
|
|
145
|
+
return new TextDecoder().decode(infoRet.subarray(3, 3 + size));
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
get columnLabels(): Promise<string[]> {
|
|
151
|
+
const asyncFunc = async (): Promise<string[]> => {
|
|
152
|
+
if (!this.outMetadata) {
|
|
153
|
+
return [];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return await this.attachment.client.statusAction(async (status) => {
|
|
157
|
+
const metaData = this.outMetadata!;
|
|
158
|
+
const count = metaData.getCountSync(status);
|
|
159
|
+
const array: string[] = [];
|
|
160
|
+
|
|
161
|
+
for (let i = 0; i < count; ++i) {
|
|
162
|
+
array.push(metaData.getAliasSync(status, i)!);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return array;
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
return asyncFunc();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
get type(): Promise<StatementType> {
|
|
173
|
+
if (!this.typePromise) {
|
|
174
|
+
const asyncFunc = async (): Promise<StatementType> => {
|
|
175
|
+
return await this.attachment.client.statusAction((status) => this.statementHandle!.getTypeAsync(status));
|
|
176
|
+
};
|
|
177
|
+
this.typePromise = asyncFunc();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return this.typePromise;
|
|
181
|
+
}
|
|
156
182
|
}
|
package/src/lib/transaction.ts
CHANGED
|
@@ -6,43 +6,48 @@ import { AbstractTransaction } from 'node-firebird-driver/dist/lib/impl';
|
|
|
6
6
|
|
|
7
7
|
import * as fb from 'node-firebird-native-api';
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
/** Transaction implementation. */
|
|
11
10
|
export class TransactionImpl extends AbstractTransaction {
|
|
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
|
-
|
|
11
|
+
// Override declarations.
|
|
12
|
+
override attachment: AttachmentImpl;
|
|
13
|
+
|
|
14
|
+
transactionHandle?: fb.Transaction;
|
|
15
|
+
|
|
16
|
+
static async start(attachment: AttachmentImpl, options?: TransactionOptions): Promise<TransactionImpl> {
|
|
17
|
+
const transaction = new TransactionImpl(attachment);
|
|
18
|
+
|
|
19
|
+
return await attachment.client.statusAction(async (status) => {
|
|
20
|
+
const tpb = createTpb(options);
|
|
21
|
+
transaction.transactionHandle = await attachment!.attachmentHandle!.startTransactionAsync(
|
|
22
|
+
status,
|
|
23
|
+
tpb.length,
|
|
24
|
+
tpb,
|
|
25
|
+
);
|
|
26
|
+
return transaction;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Commits and release this transaction object. */
|
|
31
|
+
protected async internalCommit(): Promise<void> {
|
|
32
|
+
await this.attachment.client.statusAction((status) => this.transactionHandle!.commitAsync(status));
|
|
33
|
+
this.transactionHandle = undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Commits and maintains this transaction object for subsequent work. */
|
|
37
|
+
protected async internalCommitRetaining(): Promise<void> {
|
|
38
|
+
return await this.attachment.client.statusAction((status) => this.transactionHandle!.commitRetainingAsync(status));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Rollbacks and release this transaction object. */
|
|
42
|
+
protected async internalRollback(): Promise<void> {
|
|
43
|
+
await this.attachment.client.statusAction((status) => this.transactionHandle!.rollbackAsync(status));
|
|
44
|
+
this.transactionHandle = undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Rollbacks and maintains this transaction object for subsequent work. */
|
|
48
|
+
protected async internalRollbackRetaining(): Promise<void> {
|
|
49
|
+
return await this.attachment.client.statusAction((status) =>
|
|
50
|
+
this.transactionHandle!.rollbackRetainingAsync(status),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
48
53
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"references": [
|
|
11
|
-
{ "path": "../node-firebird-driver" },
|
|
12
|
-
{ "path": "../node-firebird-native-api" }
|
|
13
|
-
],
|
|
14
|
-
"exclude": [
|
|
15
|
-
"node_modules",
|
|
16
|
-
"dist",
|
|
17
|
-
"build"
|
|
18
|
-
]
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "./src",
|
|
5
|
+
"outDir": "./dist"
|
|
6
|
+
},
|
|
7
|
+
"include": ["./src/**/*"],
|
|
8
|
+
"references": [{ "path": "../node-firebird-driver" }, { "path": "../node-firebird-native-api" }],
|
|
9
|
+
"exclude": ["node_modules", "dist", "build"]
|
|
19
10
|
}
|