@itwin/core-backend 3.5.0-dev.18 → 3.5.0-dev.19
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/CHANGELOG.md +8 -1
- package/lib/cjs/CloudSqlite.d.ts +1 -0
- package/lib/cjs/CloudSqlite.d.ts.map +1 -1
- package/lib/cjs/CloudSqlite.js +1 -0
- package/lib/cjs/CloudSqlite.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +6 -1
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/SqliteStatement.d.ts +81 -4
- package/lib/cjs/SqliteStatement.d.ts.map +1 -1
- package/lib/cjs/SqliteStatement.js +163 -25
- package/lib/cjs/SqliteStatement.js.map +1 -1
- package/lib/cjs/workspace/Workspace.js +1 -1
- package/lib/cjs/workspace/Workspace.js.map +1 -1
- package/package.json +11 -11
|
@@ -88,22 +88,58 @@ export declare class SqliteStatement implements IterableIterator<any>, IDisposab
|
|
|
88
88
|
* case of other binding errors.
|
|
89
89
|
*/
|
|
90
90
|
bindValue(parameter: BindParameter, value: any): void;
|
|
91
|
-
private checkBind;
|
|
92
91
|
/** Bind an integer parameter
|
|
93
|
-
*
|
|
94
|
-
*
|
|
92
|
+
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
93
|
+
* @param val integer to bind.
|
|
95
94
|
*/
|
|
96
95
|
bindInteger(parameter: BindParameter, val: number): void;
|
|
96
|
+
/** Bind an integer parameter if it is defined. Otherwise do nothing.
|
|
97
|
+
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
98
|
+
* @param val integer to bind.
|
|
99
|
+
*/
|
|
100
|
+
maybeBindInteger(parameter: BindParameter, val?: number): void;
|
|
101
|
+
/** Bind a boolean parameter.
|
|
102
|
+
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
103
|
+
* @param val boolean to bind.
|
|
104
|
+
*/
|
|
105
|
+
bindBoolean(parameter: BindParameter, val: boolean): void;
|
|
106
|
+
/** Bind a boolean parameter if it is defined. Otherwise do nothing.
|
|
107
|
+
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
108
|
+
* @param val boolean to bind.
|
|
109
|
+
*/
|
|
110
|
+
maybeBindBoolean(parameter: BindParameter, val?: boolean): void;
|
|
111
|
+
/** JSON.stringify a property value and bind the JSON string.
|
|
112
|
+
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
113
|
+
* @param val object to bind.
|
|
114
|
+
* @internal
|
|
115
|
+
*/
|
|
116
|
+
bindProps<T>(colIndex: number, val: T): void;
|
|
117
|
+
/** JSON.stringify a property value if it is defined, and bind the JSON string. Otherwise do nothing.
|
|
118
|
+
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
119
|
+
* @param val object to bind.
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
maybeBindProps<T>(colIndex: number, val?: T): void;
|
|
97
123
|
/** Bind a double parameter
|
|
98
124
|
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
99
125
|
* @param val double to bind.
|
|
100
126
|
*/
|
|
101
127
|
bindDouble(parameter: BindParameter, val: number): void;
|
|
128
|
+
/** Bind a double parameter if it is defined. Otherwise do nothing.
|
|
129
|
+
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
130
|
+
* @param val double to bind.
|
|
131
|
+
*/
|
|
132
|
+
maybeBindDouble(parameter: BindParameter, val?: number): void;
|
|
102
133
|
/** Bind a string parameter
|
|
103
134
|
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
104
135
|
* @param val string to bind.
|
|
105
136
|
*/
|
|
106
137
|
bindString(parameter: BindParameter, val: string): void;
|
|
138
|
+
/** Bind a string parameter if it is defined. Otherwise do nothing.
|
|
139
|
+
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
140
|
+
* @param val string to bind.
|
|
141
|
+
*/
|
|
142
|
+
maybeBindString(parameter: BindParameter, val?: string): void;
|
|
107
143
|
/** Bind an Id64String parameter as a 64-bit integer
|
|
108
144
|
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
109
145
|
* @param val Id to bind.
|
|
@@ -119,6 +155,11 @@ export declare class SqliteStatement implements IterableIterator<any>, IDisposab
|
|
|
119
155
|
* @param val blob to bind.
|
|
120
156
|
*/
|
|
121
157
|
bindBlob(parameter: BindParameter, blob: Uint8Array): void;
|
|
158
|
+
/** Bind a blob parameter if it is defined. Otherwise do nothing.
|
|
159
|
+
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
160
|
+
* @param val blob to bind.
|
|
161
|
+
*/
|
|
162
|
+
maybeBindBlob(parameter: BindParameter, val?: Uint8Array): void;
|
|
122
163
|
/** Bind null to a parameter
|
|
123
164
|
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
124
165
|
*/
|
|
@@ -165,18 +206,34 @@ export declare class SqliteStatement implements IterableIterator<any>, IDisposab
|
|
|
165
206
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
166
207
|
*/
|
|
167
208
|
getValueBlob(colIndex: number): Uint8Array;
|
|
209
|
+
/** Get the value as a blob, or undefined if it is null.
|
|
210
|
+
* @param colIndex Index of SQL column in query result (0-based)
|
|
211
|
+
*/
|
|
212
|
+
getValueBlobMaybe(colIndex: number): Uint8Array | undefined;
|
|
168
213
|
/** Get a value as a double
|
|
169
214
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
170
215
|
*/
|
|
171
216
|
getValueDouble(colIndex: number): number;
|
|
217
|
+
/** Get the value as an double, or undefined if it is null.
|
|
218
|
+
* @param colIndex Index of SQL column in query result (0-based)
|
|
219
|
+
*/
|
|
220
|
+
getValueDoubleMaybe(colIndex: number): number | undefined;
|
|
172
221
|
/** Get a value as a integer
|
|
173
222
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
174
223
|
*/
|
|
175
224
|
getValueInteger(colIndex: number): number;
|
|
225
|
+
/** Get the value as an integer, or undefined if it is null.
|
|
226
|
+
* @param colIndex Index of SQL column in query result (0-based)
|
|
227
|
+
*/
|
|
228
|
+
getValueIntegerMaybe(colIndex: number): number | undefined;
|
|
176
229
|
/** Get a value as a string
|
|
177
230
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
178
231
|
*/
|
|
179
232
|
getValueString(colIndex: number): string;
|
|
233
|
+
/** Get the value as a string, or undefined if it is null.
|
|
234
|
+
* @param colIndex Index of SQL column in query result (0-based)
|
|
235
|
+
*/
|
|
236
|
+
getValueStringMaybe(colIndex: number): string | undefined;
|
|
180
237
|
/** Get a value as an Id
|
|
181
238
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
182
239
|
*/
|
|
@@ -185,6 +242,26 @@ export declare class SqliteStatement implements IterableIterator<any>, IDisposab
|
|
|
185
242
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
186
243
|
*/
|
|
187
244
|
getValueGuid(colIndex: number): GuidString;
|
|
245
|
+
/** Get the value as a boolean. Returns `false` if the column is null.
|
|
246
|
+
* @param colIndex Index of SQL column in query result (0-based)
|
|
247
|
+
*/
|
|
248
|
+
getValueBoolean(colIndex: number): boolean;
|
|
249
|
+
/** Get the value of a [julianday](https://www.sqlite.org/lang_datefunc.html) column as a JavaScript `Date`.
|
|
250
|
+
* @param colIndex Index of SQL column in query result (0-based)
|
|
251
|
+
* @beta
|
|
252
|
+
*/
|
|
253
|
+
getValueDate(colIndex: number): Date;
|
|
254
|
+
/** Get the value as a "props" JSON string, then parse it and return the object
|
|
255
|
+
* @param colIndex Index of SQL column in query result (0-based)
|
|
256
|
+
* @internal
|
|
257
|
+
*/
|
|
258
|
+
getProps<T>(colIndex: number): T;
|
|
259
|
+
/** Get the value as a "props" JSON string, then parse it and return the object.
|
|
260
|
+
* If the column is null, return undefined.
|
|
261
|
+
* @param colIndex Index of SQL column in query result (0-based)
|
|
262
|
+
* @internal
|
|
263
|
+
*/
|
|
264
|
+
getPropsMaybe<T>(colIndex: number): T | undefined;
|
|
188
265
|
/** Get the current row.
|
|
189
266
|
* The returned row is formatted as JavaScript object where every SELECT clause item becomes a property in the JavaScript object.
|
|
190
267
|
*
|
|
@@ -247,7 +324,7 @@ export declare class SqliteValue {
|
|
|
247
324
|
* [SqliteValueType.Blob]($backend) | Uint8Array
|
|
248
325
|
*/
|
|
249
326
|
get value(): any;
|
|
250
|
-
/** Get the value as
|
|
327
|
+
/** Get the value as Blob */
|
|
251
328
|
getBlob(): Uint8Array;
|
|
252
329
|
/** Get the value as a double value */
|
|
253
330
|
getDouble(): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteStatement.d.ts","sourceRoot":"","sources":["../../src/SqliteStatement.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAwB,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAU,MAAM,qBAAqB,CAAC;AAElH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"SqliteStatement.d.ts","sourceRoot":"","sources":["../../src/SqliteStatement.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAwB,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAU,MAAM,qBAAqB,CAAC;AAElH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAO1D;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED;;GAEG;AACH,oBAAY,aAAa,GAAG,MAAM,GAAG,MAAM,CAAC;AAO5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,eAAgB,YAAW,gBAAgB,CAAC,GAAG,CAAC,EAAE,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IAClD,IAAW,MAAM,IAAI,OAAO,CAAmD;IAE/E,uCAAuC;IACvC,IAAW,IAAI,IAAI,eAAe,CAAqD;IAEvF,gDAAgD;IAChD,IAAW,UAAU,IAAI,MAAM,CAAqD;IAEpF;;;;;;;;;OASG;IACH,IAAW,KAAK,IAAI,GAAG,CAetB;IAED,4BAA4B;IACrB,OAAO,IAAI,UAAU;IAC5B,sCAAsC;IAC/B,SAAS,IAAI,MAAM;IAC1B,uCAAuC;IAChC,UAAU,IAAI,MAAM;IAC3B,sCAAsC;IAC/B,SAAS,IAAI,MAAM;IAC1B,mCAAmC;IAC5B,KAAK,IAAI,UAAU;IAC1B,oCAAoC;IAC7B,OAAO,IAAI,UAAU;CAC7B;AAED,UAAU,SAAS;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,IAAI,IAAI,CAAC;IAChB,KAAK,IAAI,IAAI,CAAC;IACd,aAAa,IAAI,IAAI,CAAC;CACvB;AAED;;;;GAIG;AACH,qBAAa,cAAc,CAAC,IAAI,SAAS,SAAS;IAChD,OAAO,CAAC,MAAM,CAAuB;gBAElB,QAAQ,SAAK;IAIhC,IAAW,IAAI,WAA+B;IACvC,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAiB9B,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAI5C,KAAK;CAIb"}
|
|
@@ -11,6 +11,10 @@ exports.StatementCache = exports.SqliteValue = exports.SqliteValueType = exports
|
|
|
11
11
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
12
|
const core_common_1 = require("@itwin/core-common");
|
|
13
13
|
const IModelHost_1 = require("./IModelHost");
|
|
14
|
+
function checkBind(stat) {
|
|
15
|
+
if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
|
|
16
|
+
throw new core_common_1.IModelError(stat, "SQLite Bind error");
|
|
17
|
+
}
|
|
14
18
|
/** Executes SQLite SQL statements.
|
|
15
19
|
*
|
|
16
20
|
* A statement must be prepared before it can be executed, and it must be released when no longer needed.
|
|
@@ -137,57 +141,117 @@ class SqliteStatement {
|
|
|
137
141
|
if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
|
|
138
142
|
throw new core_common_1.IModelError(stat, "Error in bindValue");
|
|
139
143
|
}
|
|
140
|
-
checkBind(stat) {
|
|
141
|
-
if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
|
|
142
|
-
throw new core_common_1.IModelError(stat, "SQLite Bind error");
|
|
143
|
-
}
|
|
144
144
|
/** Bind an integer parameter
|
|
145
|
-
*
|
|
146
|
-
*
|
|
145
|
+
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
146
|
+
* @param val integer to bind.
|
|
147
147
|
*/
|
|
148
148
|
bindInteger(parameter, val) {
|
|
149
|
-
|
|
149
|
+
checkBind(this.stmt.bindInteger(parameter, val));
|
|
150
|
+
}
|
|
151
|
+
/** Bind an integer parameter if it is defined. Otherwise do nothing.
|
|
152
|
+
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
153
|
+
* @param val integer to bind.
|
|
154
|
+
*/
|
|
155
|
+
maybeBindInteger(parameter, val) {
|
|
156
|
+
if (val !== undefined)
|
|
157
|
+
this.bindInteger(parameter, val);
|
|
158
|
+
}
|
|
159
|
+
/** Bind a boolean parameter.
|
|
160
|
+
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
161
|
+
* @param val boolean to bind.
|
|
162
|
+
*/
|
|
163
|
+
bindBoolean(parameter, val) {
|
|
164
|
+
this.bindInteger(parameter, val ? 1 : 0);
|
|
165
|
+
}
|
|
166
|
+
/** Bind a boolean parameter if it is defined. Otherwise do nothing.
|
|
167
|
+
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
168
|
+
* @param val boolean to bind.
|
|
169
|
+
*/
|
|
170
|
+
maybeBindBoolean(parameter, val) {
|
|
171
|
+
if (val !== undefined)
|
|
172
|
+
this.bindBoolean(parameter, val);
|
|
173
|
+
}
|
|
174
|
+
/** JSON.stringify a property value and bind the JSON string.
|
|
175
|
+
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
176
|
+
* @param val object to bind.
|
|
177
|
+
* @internal
|
|
178
|
+
*/
|
|
179
|
+
bindProps(colIndex, val) {
|
|
180
|
+
this.bindString(colIndex, JSON.stringify(val));
|
|
181
|
+
}
|
|
182
|
+
/** JSON.stringify a property value if it is defined, and bind the JSON string. Otherwise do nothing.
|
|
183
|
+
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
184
|
+
* @param val object to bind.
|
|
185
|
+
* @internal
|
|
186
|
+
*/
|
|
187
|
+
maybeBindProps(colIndex, val) {
|
|
188
|
+
if (val !== undefined)
|
|
189
|
+
this.bindProps(colIndex, val);
|
|
150
190
|
}
|
|
151
191
|
/** Bind a double parameter
|
|
152
192
|
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
153
193
|
* @param val double to bind.
|
|
154
194
|
*/
|
|
155
195
|
bindDouble(parameter, val) {
|
|
156
|
-
|
|
196
|
+
checkBind(this.stmt.bindDouble(parameter, val));
|
|
197
|
+
}
|
|
198
|
+
/** Bind a double parameter if it is defined. Otherwise do nothing.
|
|
199
|
+
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
200
|
+
* @param val double to bind.
|
|
201
|
+
*/
|
|
202
|
+
maybeBindDouble(parameter, val) {
|
|
203
|
+
if (val !== undefined)
|
|
204
|
+
this.bindDouble(parameter, val);
|
|
157
205
|
}
|
|
158
206
|
/** Bind a string parameter
|
|
159
207
|
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
160
208
|
* @param val string to bind.
|
|
161
209
|
*/
|
|
162
210
|
bindString(parameter, val) {
|
|
163
|
-
|
|
211
|
+
checkBind(this.stmt.bindString(parameter, val));
|
|
212
|
+
}
|
|
213
|
+
/** Bind a string parameter if it is defined. Otherwise do nothing.
|
|
214
|
+
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
215
|
+
* @param val string to bind.
|
|
216
|
+
*/
|
|
217
|
+
maybeBindString(parameter, val) {
|
|
218
|
+
if (val !== undefined)
|
|
219
|
+
this.bindString(parameter, val);
|
|
164
220
|
}
|
|
165
221
|
/** Bind an Id64String parameter as a 64-bit integer
|
|
166
222
|
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
167
223
|
* @param val Id to bind.
|
|
168
224
|
*/
|
|
169
225
|
bindId(parameter, id) {
|
|
170
|
-
|
|
226
|
+
checkBind(this.stmt.bindId(parameter, id));
|
|
171
227
|
}
|
|
172
228
|
/** Bind a Guid parameter
|
|
173
229
|
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
174
230
|
* @param val Guid to bind.
|
|
175
231
|
*/
|
|
176
232
|
bindGuid(parameter, guid) {
|
|
177
|
-
|
|
233
|
+
checkBind(this.stmt.bindGuid(parameter, guid));
|
|
178
234
|
}
|
|
179
235
|
/** Bind a blob parameter
|
|
180
236
|
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
181
237
|
* @param val blob to bind.
|
|
182
238
|
*/
|
|
183
239
|
bindBlob(parameter, blob) {
|
|
184
|
-
|
|
240
|
+
checkBind(this.stmt.bindBlob(parameter, blob));
|
|
241
|
+
}
|
|
242
|
+
/** Bind a blob parameter if it is defined. Otherwise do nothing.
|
|
243
|
+
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
244
|
+
* @param val blob to bind.
|
|
245
|
+
*/
|
|
246
|
+
maybeBindBlob(parameter, val) {
|
|
247
|
+
if (val !== undefined)
|
|
248
|
+
this.bindBlob(parameter, val);
|
|
185
249
|
}
|
|
186
250
|
/** Bind null to a parameter
|
|
187
251
|
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
188
252
|
*/
|
|
189
253
|
bindNull(parameter) {
|
|
190
|
-
|
|
254
|
+
checkBind(this.stmt.bindNull(parameter));
|
|
191
255
|
}
|
|
192
256
|
/** Bind values to all parameters in the statement.
|
|
193
257
|
* @param values The values to bind to the parameters.
|
|
@@ -234,45 +298,119 @@ class SqliteStatement {
|
|
|
234
298
|
* - [DbResult.BE_SQLITE_DONE]($core-bentley) if the statement has been executed successfully.
|
|
235
299
|
* - Error status in case of errors.
|
|
236
300
|
*/
|
|
237
|
-
step() {
|
|
301
|
+
step() {
|
|
302
|
+
return this.stmt.step();
|
|
303
|
+
}
|
|
238
304
|
/** Get the query result's column count (only for SQL SELECT statements). */
|
|
239
|
-
getColumnCount() {
|
|
305
|
+
getColumnCount() {
|
|
306
|
+
return this.stmt.getColumnCount();
|
|
307
|
+
}
|
|
240
308
|
/** Get the value for the column at the given index in the query result.
|
|
241
309
|
* @param columnIx Index of SQL column in query result (0-based)
|
|
242
310
|
*/
|
|
243
|
-
getValue(columnIx) {
|
|
311
|
+
getValue(columnIx) {
|
|
312
|
+
return new SqliteValue(this.stmt, columnIx);
|
|
313
|
+
}
|
|
244
314
|
/** Determine whether the value of the specified column is null
|
|
245
315
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
246
316
|
*/
|
|
247
|
-
isValueNull(colIndex) {
|
|
317
|
+
isValueNull(colIndex) {
|
|
318
|
+
return this.stmt.isValueNull(colIndex);
|
|
319
|
+
}
|
|
248
320
|
/** Get a size in bytes of a blob or text column
|
|
249
321
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
250
322
|
*/
|
|
251
|
-
getColumnBytes(colIndex) {
|
|
323
|
+
getColumnBytes(colIndex) {
|
|
324
|
+
return this.stmt.getColumnBytes(colIndex);
|
|
325
|
+
}
|
|
252
326
|
/** Get a value as a blob
|
|
253
327
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
254
328
|
*/
|
|
255
|
-
getValueBlob(colIndex) {
|
|
329
|
+
getValueBlob(colIndex) {
|
|
330
|
+
return this.stmt.getValueBlob(colIndex);
|
|
331
|
+
}
|
|
332
|
+
/** Get the value as a blob, or undefined if it is null.
|
|
333
|
+
* @param colIndex Index of SQL column in query result (0-based)
|
|
334
|
+
*/
|
|
335
|
+
getValueBlobMaybe(colIndex) {
|
|
336
|
+
return this.isValueNull(colIndex) ? undefined : this.getValueBlob(colIndex);
|
|
337
|
+
}
|
|
256
338
|
/** Get a value as a double
|
|
257
339
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
258
340
|
*/
|
|
259
|
-
getValueDouble(colIndex) {
|
|
341
|
+
getValueDouble(colIndex) {
|
|
342
|
+
return this.stmt.getValueDouble(colIndex);
|
|
343
|
+
}
|
|
344
|
+
/** Get the value as an double, or undefined if it is null.
|
|
345
|
+
* @param colIndex Index of SQL column in query result (0-based)
|
|
346
|
+
*/
|
|
347
|
+
getValueDoubleMaybe(colIndex) {
|
|
348
|
+
return this.isValueNull(colIndex) ? undefined : this.getValueDouble(colIndex);
|
|
349
|
+
}
|
|
260
350
|
/** Get a value as a integer
|
|
261
351
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
262
352
|
*/
|
|
263
|
-
getValueInteger(colIndex) {
|
|
353
|
+
getValueInteger(colIndex) {
|
|
354
|
+
return this.stmt.getValueInteger(colIndex);
|
|
355
|
+
}
|
|
356
|
+
/** Get the value as an integer, or undefined if it is null.
|
|
357
|
+
* @param colIndex Index of SQL column in query result (0-based)
|
|
358
|
+
*/
|
|
359
|
+
getValueIntegerMaybe(colIndex) {
|
|
360
|
+
return this.isValueNull(colIndex) ? undefined : this.getValueInteger(colIndex);
|
|
361
|
+
}
|
|
264
362
|
/** Get a value as a string
|
|
265
363
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
266
364
|
*/
|
|
267
|
-
getValueString(colIndex) {
|
|
365
|
+
getValueString(colIndex) {
|
|
366
|
+
return this.stmt.getValueString(colIndex);
|
|
367
|
+
}
|
|
368
|
+
/** Get the value as a string, or undefined if it is null.
|
|
369
|
+
* @param colIndex Index of SQL column in query result (0-based)
|
|
370
|
+
*/
|
|
371
|
+
getValueStringMaybe(colIndex) {
|
|
372
|
+
return this.isValueNull(colIndex) ? undefined : this.getValueString(colIndex);
|
|
373
|
+
}
|
|
268
374
|
/** Get a value as an Id
|
|
269
375
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
270
376
|
*/
|
|
271
|
-
getValueId(colIndex) {
|
|
377
|
+
getValueId(colIndex) {
|
|
378
|
+
return this.stmt.getValueId(colIndex);
|
|
379
|
+
}
|
|
272
380
|
/** Get a value as a Guid
|
|
273
381
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
274
382
|
*/
|
|
275
|
-
getValueGuid(colIndex) {
|
|
383
|
+
getValueGuid(colIndex) {
|
|
384
|
+
return this.stmt.getValueGuid(colIndex);
|
|
385
|
+
}
|
|
386
|
+
/** Get the value as a boolean. Returns `false` if the column is null.
|
|
387
|
+
* @param colIndex Index of SQL column in query result (0-based)
|
|
388
|
+
*/
|
|
389
|
+
getValueBoolean(colIndex) {
|
|
390
|
+
return this.isValueNull(colIndex) ? false : 0 !== this.getValueInteger(colIndex);
|
|
391
|
+
}
|
|
392
|
+
/** Get the value of a [julianday](https://www.sqlite.org/lang_datefunc.html) column as a JavaScript `Date`.
|
|
393
|
+
* @param colIndex Index of SQL column in query result (0-based)
|
|
394
|
+
* @beta
|
|
395
|
+
*/
|
|
396
|
+
getValueDate(colIndex) {
|
|
397
|
+
return new Date((this.stmt.getValueDouble(colIndex) - 2440587.5) * 86400000); // conversion from julian day ms to unix epoch ms
|
|
398
|
+
}
|
|
399
|
+
/** Get the value as a "props" JSON string, then parse it and return the object
|
|
400
|
+
* @param colIndex Index of SQL column in query result (0-based)
|
|
401
|
+
* @internal
|
|
402
|
+
*/
|
|
403
|
+
getProps(colIndex) {
|
|
404
|
+
return JSON.parse(this.getValueString(colIndex));
|
|
405
|
+
}
|
|
406
|
+
/** Get the value as a "props" JSON string, then parse it and return the object.
|
|
407
|
+
* If the column is null, return undefined.
|
|
408
|
+
* @param colIndex Index of SQL column in query result (0-based)
|
|
409
|
+
* @internal
|
|
410
|
+
*/
|
|
411
|
+
getPropsMaybe(colIndex) {
|
|
412
|
+
return this.isValueNull(colIndex) ? undefined : this.getProps(colIndex);
|
|
413
|
+
}
|
|
276
414
|
/** Get the current row.
|
|
277
415
|
* The returned row is formatted as JavaScript object where every SELECT clause item becomes a property in the JavaScript object.
|
|
278
416
|
*
|
|
@@ -398,7 +536,7 @@ class SqliteValue {
|
|
|
398
536
|
throw new Error("Unhandled SqliteValueType");
|
|
399
537
|
}
|
|
400
538
|
}
|
|
401
|
-
/** Get the value as
|
|
539
|
+
/** Get the value as Blob */
|
|
402
540
|
getBlob() { return this._stmt.getValueBlob(this._colIndex); }
|
|
403
541
|
/** Get the value as a double value */
|
|
404
542
|
getDouble() { return this._stmt.getValueDouble(this._colIndex); }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteStatement.js","sourceRoot":"","sources":["../../src/SqliteStatement.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAkH;AAClH,oDAA4D;AAE5D,6CAA0C;AAmB1C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,eAAe;IAI1B,YAA2B,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAI,CAAC;IAC5C,IAAW,IAAI,KAAqC,OAAO,IAAI,CAAC,KAAM,CAAC,CAAC,CAAC;IACzE,IAAW,GAAG,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAEtC,oEAAoE;IACpE,IAAW,UAAU,KAAc,OAAO,SAAS,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAErE;;;;;;OAMG;IACI,OAAO,CAAC,EAAwB,EAAE,SAAS,GAAG,IAAI;QACvD,IAAI,IAAI,CAAC,UAAU;YACjB,MAAM,IAAI,KAAK,CAAC,q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AI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF;AAjCD,wCAiCC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module SQLite\n */\n\nimport { assert, BentleyError, DbResult, GuidString, Id64String, IDisposable, LRUMap } from \"@itwin/core-bentley\";\nimport { ECJsNames, IModelError } from \"@itwin/core-common\";\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\nimport { IModelHost } from \"./IModelHost\";\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\n/** Marks a string as either an [Id64String]($core-bentley) or [GuidString]($core-bentley), so\n * that it can be passed to the [bindValue]($backend.SqliteStatement) or [bindValues]($backend.SqliteStatement)\n * methods of [SqliteStatement]($backend).\n * @internal\n */\nexport interface StringParam {\n id?: Id64String;\n guid?: GuidString;\n}\n\n/** parameter Index (1-based), or name of the parameter (including the initial ':', '@' or '$')\n * @public\n */\nexport type BindParameter = number | string;\n\n/** Executes SQLite SQL statements.\n *\n * A statement must be prepared before it can be executed, and it must be released when no longer needed.\n * See [IModelDb.withPreparedSqliteStatement]($backend) or\n * [ECDb.withPreparedSqliteStatement]($backend) for a convenient and\n * reliable way to prepare, execute, and then release a statement.\n *\n * A statement may contain parameters that must be filled in before use by calling [SqliteStatement.bindValue]($backend)\n * or [SqliteStatement.bindValues]($backend).\n *\n * Once prepared (and parameters are bound, if any), the statement is executed by calling [SqliteStatement.step]($backend).\n * In case of an **SQL SELECT** statement, the current row can be retrieved with [SqliteStatement.getRow]($backend) as\n * a whole, or with [SqliteStatement.getValue]($backend) when individual values are needed.\n * Alternatively, query results of an **SQL SELECT** statement can be stepped through by using\n * standard iteration syntax, such as `for of`.\n *\n * > Preparing a statement can be time-consuming. The best way to reduce the effect of this overhead is to cache and reuse prepared\n * > statements. A cached prepared statement may be used in different places in an app, as long as the statement is general enough.\n * > The key to making this strategy work is to phrase a statement in a general way and use placeholders to represent parameters that will vary on each use.\n * @public\n */\nexport class SqliteStatement implements IterableIterator<any>, IDisposable {\n private _stmt: IModelJsNative.SqliteStatement | undefined;\n private _db: IModelJsNative.AnyDb | undefined;\n\n public constructor(private _sql: string) { }\n public get stmt(): IModelJsNative.SqliteStatement { return this._stmt!; }\n public get sql() { return this._sql; }\n\n /** Check if this statement has been prepared successfully or not */\n public get isPrepared(): boolean { return undefined !== this._stmt; }\n\n /** Prepare this statement prior to first use.\n * @param db The DgnDb or ECDb to prepare the statement against\n * @param sql The SQL statement string to prepare\n * @param logErrors Determine if errors are logged or not\n * @throws if the SQL statement cannot be prepared. Normally, prepare fails due to SQL syntax errors or references to tables or properties that do not exist.\n * The error.message property will provide details.\n */\n public prepare(db: IModelJsNative.AnyDb, logErrors = true): void {\n if (this.isPrepared)\n throw new Error(\"SqliteStatement is already prepared\");\n this._db = db;\n this._stmt = new IModelHost.platform.SqliteStatement();\n this._stmt.prepare(db, this._sql, logErrors);\n }\n\n /** Indicates whether the prepared statement makes no **direct* changes to the content of the file\n * or not. See [SQLite docs](https://www.sqlite.org/c3ref/stmt_readonly.html) for details.\n */\n public get isReadonly(): boolean {\n return this.stmt.isReadonly();\n }\n\n /** Reset this statement so that the next call to step will return the first row, if any.\n */\n public reset(): void {\n this.stmt.reset();\n }\n\n /** Call this function when finished with this statement. This releases the native resources held by the statement. */\n public dispose(): void {\n if (this._stmt) {\n this._stmt.dispose(); // free native statement\n this._stmt = undefined;\n this._db = undefined;\n }\n }\n\n /**\n * Call `step` on this statement and determine whether a new row is available.\n * Use this method only when this statement has been prepared with a SELECT statement.\n * @return true if a new row is available, false otherwise.\n * @throws if `step` returns anything other than BE_SQLITE_ROW or BE_SQLITE_DONE.\n */\n public nextRow(): boolean {\n const rc = this.step();\n switch (rc) {\n case DbResult.BE_SQLITE_ROW:\n return true;\n case DbResult.BE_SQLITE_DONE:\n return false;\n }\n\n throw new BentleyError(rc, this._db!.getLastError());\n }\n\n /** Binds a value to the specified SQL parameter.\n * The value must be of one of these types:\n * JavaScript Type | SQLite Type\n * --- | ---\n * undefined | NULL\n * boolean | INTEGER with true being bound as 1 and false as 0\n * number | INTEGER if number is integral or REAL if number is not integral\n * string | TEXT\n * Uint8Array or ArrayBuffer | BLOB\n * [StringParam]($backend) where member **id** is set | INTEGER\n * [StringParam]($backend) where member **guid** is set | BLOB\n *\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param value Value to bind.\n * @throws [IModelError]($common) if the value is of an unsupported type or in\n * case of other binding errors.\n */\n public bindValue(parameter: BindParameter, value: any): void {\n let stat: DbResult;\n if (value === undefined || value === null) {\n stat = this.stmt.bindNull(parameter);\n } else if (typeof (value) === \"number\") {\n if (Number.isInteger(value))\n stat = this.stmt.bindInteger(parameter, value);\n else\n stat = this.stmt.bindDouble(parameter, value);\n } else if (typeof (value) === \"boolean\") {\n stat = this.stmt.bindInteger(parameter, value ? 1 : 0);\n } else if (typeof (value) === \"string\") {\n stat = this.stmt.bindString(parameter, value);\n } else if (!!value.id) {\n stat = this.stmt.bindId(parameter, value.id);\n } else if (!!value.guid) {\n stat = this.stmt.bindGuid(parameter, value.guid);\n } else if (value instanceof Uint8Array) {\n stat = this.stmt.bindBlob(parameter, value);\n } else\n throw new IModelError(DbResult.BE_SQLITE_ERROR, `Parameter value ${value} is of an unsupported data type.`);\n\n if (stat !== DbResult.BE_SQLITE_OK)\n throw new IModelError(stat, \"Error in bindValue\");\n }\n\n private checkBind(stat: DbResult) {\n if (stat !== DbResult.BE_SQLITE_OK)\n throw new IModelError(stat, \"SQLite Bind error\");\n }\n /** Bind an integer parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val integer to bind.\n */\n public bindInteger(parameter: BindParameter, val: number) {\n this.checkBind(this.stmt.bindInteger(parameter, val));\n }\n /** Bind a double parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val double to bind.\n */\n public bindDouble(parameter: BindParameter, val: number) {\n this.checkBind(this.stmt.bindDouble(parameter, val));\n }\n /** Bind a string parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val string to bind.\n */\n public bindString(parameter: BindParameter, val: string) {\n this.checkBind(this.stmt.bindString(parameter, val));\n }\n /** Bind an Id64String parameter as a 64-bit integer\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val Id to bind.\n */\n public bindId(parameter: BindParameter, id: Id64String) {\n this.checkBind(this.stmt.bindId(parameter, id));\n }\n /** Bind a Guid parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val Guid to bind.\n */\n public bindGuid(parameter: BindParameter, guid: GuidString) {\n this.checkBind(this.stmt.bindGuid(parameter, guid));\n }\n /** Bind a blob parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val blob to bind.\n */\n public bindBlob(parameter: BindParameter, blob: Uint8Array) {\n this.checkBind(this.stmt.bindBlob(parameter, blob));\n }\n /** Bind null to a parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n */\n public bindNull(parameter: BindParameter) {\n this.checkBind(this.stmt.bindNull(parameter));\n }\n\n /** Bind values to all parameters in the statement.\n * @param values The values to bind to the parameters.\n * Pass an *array* of values if the parameters are *positional*.\n * Pass an *object of the values keyed on the parameter name* for *named parameters*.\n * The values in either the array or object must match the respective types of the parameter.\n * See [[SqliteStatement.bindValue]] for details on the supported types.\n */\n public bindValues(values: any[] | object): void {\n if (Array.isArray(values)) {\n for (let i = 0; i < values.length; i++) {\n const paramIndex: number = i + 1;\n const paramValue: any = values[i];\n if (paramValue === undefined || paramValue === null)\n continue;\n\n this.bindValue(paramIndex, paramValue);\n }\n return;\n }\n\n for (const entry of Object.entries(values)) {\n const paramName: string = entry[0];\n const paramValue: any = entry[1];\n if (paramValue === undefined || paramValue === null)\n continue;\n\n this.bindValue(paramName, paramValue);\n }\n }\n\n /** Clear any bindings that were previously set on this statement.\n * @throws [IModelError]($common) in case of errors\n */\n public clearBindings(): void {\n const stat = this.stmt.clearBindings();\n if (stat !== DbResult.BE_SQLITE_OK)\n throw new IModelError(stat, \"Error in clearBindings\");\n }\n\n /** Step this statement to the next row.\n *\n * For **SQL SELECT** statements the method returns\n * - [DbResult.BE_SQLITE_ROW]($core-bentley) if the statement now points successfully to the next row.\n * - [DbResult.BE_SQLITE_DONE]($core-bentley) if the statement has no more rows.\n * - Error status in case of errors.\n *\n * For **SQL INSERT, UPDATE, DELETE** statements the method returns\n * - [DbResult.BE_SQLITE_DONE]($core-bentley) if the statement has been executed successfully.\n * - Error status in case of errors.\n */\n public step(): DbResult { return this.stmt.step(); }\n\n /** Get the query result's column count (only for SQL SELECT statements). */\n public getColumnCount(): number { return this.stmt.getColumnCount(); }\n\n /** Get the value for the column at the given index in the query result.\n * @param columnIx Index of SQL column in query result (0-based)\n */\n public getValue(columnIx: number): SqliteValue { return new SqliteValue(this.stmt, columnIx); }\n\n /** Determine whether the value of the specified column is null\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public isValueNull(colIndex: number): boolean { return this.stmt.isValueNull(colIndex); }\n\n /** Get a size in bytes of a blob or text column\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getColumnBytes(colIndex: number): number { return this.stmt.getColumnBytes(colIndex); }\n\n /** Get a value as a blob\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueBlob(colIndex: number): Uint8Array { return this.stmt.getValueBlob(colIndex); }\n /** Get a value as a double\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueDouble(colIndex: number): number { return this.stmt.getValueDouble(colIndex); }\n /** Get a value as a integer\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueInteger(colIndex: number): number { return this.stmt.getValueInteger(colIndex); }\n /** Get a value as a string\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueString(colIndex: number): string { return this.stmt.getValueString(colIndex); }\n /** Get a value as an Id\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueId(colIndex: number): Id64String { return this.stmt.getValueId(colIndex); }\n /** Get a value as a Guid\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueGuid(colIndex: number): GuidString { return this.stmt.getValueGuid(colIndex); }\n\n /** Get the current row.\n * The returned row is formatted as JavaScript object where every SELECT clause item becomes a property in the JavaScript object.\n *\n * The SQL select clause item's name becomes the member name of the JavaScript object, **with the first character lowered**.\n *\n * SQLite Type | JavaScript Type\n * --- | ---\n * [SqliteValueType.Null]($backend) | undefined\n * [SqliteValueType.Integer]($backend) | number\n * [SqliteValueType.Double]($backend) | number\n * [SqliteValueType.String]($backend) | string\n * [SqliteValueType.Blob]($backend) | Uint8Array\n */\n public getRow(): any {\n const colCount = this.getColumnCount();\n const row: object = {};\n const duplicatePropNames = new Map<string, number>();\n for (let i = 0; i < colCount; i++) {\n const sqliteValue = this.getValue(i);\n if (!sqliteValue.isNull) {\n const propName: string = SqliteStatement.determineResultRowPropertyName(duplicatePropNames, sqliteValue);\n let val: any;\n switch (sqliteValue.type) {\n case SqliteValueType.Blob:\n val = sqliteValue.getBlob();\n break;\n case SqliteValueType.Double:\n val = sqliteValue.getDouble();\n break;\n case SqliteValueType.Integer:\n val = sqliteValue.getInteger();\n break;\n case SqliteValueType.String:\n val = sqliteValue.getString();\n break;\n\n default:\n throw new Error(\"Unsupported SqliteValueType\");\n }\n\n Object.defineProperty(row, propName, { enumerable: true, configurable: true, writable: true, value: val });\n }\n }\n return row;\n }\n\n private static determineResultRowPropertyName(duplicatePropNames: Map<string, number>, sqliteValue: SqliteValue): string {\n let jsName = ECJsNames.toJsName(sqliteValue.columnName);\n\n // now check duplicates. If there are, append a numeric suffix to the duplicates\n let suffix = duplicatePropNames.get(jsName);\n if (suffix === undefined)\n duplicatePropNames.set(jsName, 0);\n else {\n suffix++;\n duplicatePropNames.set(jsName, suffix);\n jsName += `_${suffix}`;\n }\n\n return jsName;\n }\n\n /** Calls step when called as an iterator.\n */\n public next(): IteratorResult<any> {\n return DbResult.BE_SQLITE_ROW === this.step() ? { done: false, value: this.getRow() } : { done: true, value: undefined };\n }\n\n /** The iterator that will step through the results of this statement. */\n public [Symbol.iterator](): IterableIterator<any> { return this; }\n}\n\n/** Data type of a value in in an SQLite SQL query result.\n * See also:\n * - [SqliteValue]($backend)\n * - [SqliteStatement]($backend)\n * - [SqliteStatement.getValue]($backend)\n * @public\n */\nexport enum SqliteValueType {\n // do not change the values of that enum. It must correspond to the respective\n // enum DbValueType in the native BeSQLite API.\n Integer = 1,\n Double = 2,\n String = 3,\n Blob = 4,\n Null = 5,\n}\n\n/** Value of a column in a row of an SQLite SQL query result.\n * See also:\n * - [SqliteStatement]($backend)\n * - [SqliteStatement.getValue]($backend)\n * @public\n */\nexport class SqliteValue {\n private readonly _stmt: IModelJsNative.SqliteStatement;\n private readonly _colIndex: number;\n\n public constructor(stmt: IModelJsNative.SqliteStatement, colIndex: number) {\n this._stmt = stmt;\n this._colIndex = colIndex;\n }\n\n /** Indicates whether the value is NULL or not. */\n public get isNull(): boolean { return this._stmt.isValueNull(this._colIndex); }\n\n /** Gets the data type of the value. */\n public get type(): SqliteValueType { return this._stmt.getColumnType(this._colIndex); }\n\n /** Gets the name of the column of the value. */\n public get columnName(): string { return this._stmt.getColumnName(this._colIndex); }\n\n /** Gets the SqlValue as JavaScript value.\n *\n * SQLite Type | JavaScript Type\n * --- | ---\n * [SqliteValueType.Null]($backend) | undefined\n * [SqliteValueType.Integer]($backend) | number\n * [SqliteValueType.Double]($backend) | number\n * [SqliteValueType.String]($backend) | string\n * [SqliteValueType.Blob]($backend) | Uint8Array\n */\n public get value(): any {\n switch (this.type) {\n case SqliteValueType.Null:\n return undefined;\n case SqliteValueType.Blob:\n return this.getBlob();\n case SqliteValueType.Double:\n return this.getDouble();\n case SqliteValueType.Integer:\n return this.getInteger();\n case SqliteValueType.String:\n return this.getString();\n default:\n throw new Error(\"Unhandled SqliteValueType\");\n }\n }\n\n /** Get the value as BLOB */\n public getBlob(): Uint8Array { return this._stmt.getValueBlob(this._colIndex); }\n /** Get the value as a double value */\n public getDouble(): number { return this._stmt.getValueDouble(this._colIndex); }\n /** Get the value as a integer value */\n public getInteger(): number { return this._stmt.getValueInteger(this._colIndex); }\n /** Get the value as a string value */\n public getString(): string { return this._stmt.getValueString(this._colIndex); }\n /** Get the value as an Id value */\n public getId(): Id64String { return this._stmt.getValueId(this._colIndex); }\n /** Get the value as a Guid value */\n public getGuid(): GuidString { return this._stmt.getValueGuid(this._colIndex); }\n}\n\ninterface Statement {\n isPrepared: boolean;\n sql: string;\n dispose(): void;\n reset(): void;\n clearBindings(): void;\n}\n\n/** A cache for previously prepared SqliteStatements.\n * It only holds Statements after they are no longer in use, resetting and clearing their bindings before saving them.\n * When a request to use a statement from the cache is made, it is first removed from the cache.\n * @internal\n */\nexport class StatementCache<Stmt extends Statement> {\n private _cache: LRUMap<string, Stmt>;\n\n public constructor(maxCount = 40) {\n this._cache = new LRUMap<string, Stmt>(maxCount);\n }\n\n public get size() { return this._cache.size; }\n public addOrDispose(stmt: Stmt): void {\n assert(stmt.isPrepared);\n\n const existing = this._cache.get(stmt.sql);\n if (existing !== undefined) {\n stmt.dispose(); // we already have a statement with this sql cached, we can't save another one so just dispose it\n return;\n }\n if (this._cache.size >= this._cache.limit) {\n const oldest = this._cache.shift()!;\n oldest[1].dispose();\n }\n stmt.reset();\n stmt.clearBindings();\n this._cache.set(stmt.sql, stmt);\n }\n\n public findAndRemove(sql: string): Stmt | undefined {\n return this._cache.delete(sql);\n }\n\n public clear() {\n this._cache.forEach((stmt) => stmt.dispose());\n this._cache.clear();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SqliteStatement.js","sourceRoot":"","sources":["../../src/SqliteStatement.ts"],"names":[],"mappings":";AAAA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CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC3C,IAAI,QAAQ,KAAK,SAAS,EAAE;YAC1B,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,iGAAiG;YACjH,OAAO;SACR;QACD,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;YACzC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAG,CAAC;YACpC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;SACrB;QACD,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;IAEM,aAAa,CAAC,GAAW;QAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF;AAjCD,wCAiCC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module SQLite\n */\n\nimport { assert, BentleyError, DbResult, GuidString, Id64String, IDisposable, LRUMap } from \"@itwin/core-bentley\";\nimport { ECJsNames, IModelError } from \"@itwin/core-common\";\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\nimport { IModelHost } from \"./IModelHost\";\n\n// spell:ignore julianday\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\n/** Marks a string as either an [Id64String]($core-bentley) or [GuidString]($core-bentley), so\n * that it can be passed to the [bindValue]($backend.SqliteStatement) or [bindValues]($backend.SqliteStatement)\n * methods of [SqliteStatement]($backend).\n * @internal\n */\nexport interface StringParam {\n id?: Id64String;\n guid?: GuidString;\n}\n\n/** parameter Index (1-based), or name of the parameter (including the initial ':', '@' or '$')\n * @public\n */\nexport type BindParameter = number | string;\n\nfunction checkBind(stat: DbResult) {\n if (stat !== DbResult.BE_SQLITE_OK)\n throw new IModelError(stat, \"SQLite Bind error\");\n}\n\n/** Executes SQLite SQL statements.\n *\n * A statement must be prepared before it can be executed, and it must be released when no longer needed.\n * See [IModelDb.withPreparedSqliteStatement]($backend) or\n * [ECDb.withPreparedSqliteStatement]($backend) for a convenient and\n * reliable way to prepare, execute, and then release a statement.\n *\n * A statement may contain parameters that must be filled in before use by calling [SqliteStatement.bindValue]($backend)\n * or [SqliteStatement.bindValues]($backend).\n *\n * Once prepared (and parameters are bound, if any), the statement is executed by calling [SqliteStatement.step]($backend).\n * In case of an **SQL SELECT** statement, the current row can be retrieved with [SqliteStatement.getRow]($backend) as\n * a whole, or with [SqliteStatement.getValue]($backend) when individual values are needed.\n * Alternatively, query results of an **SQL SELECT** statement can be stepped through by using\n * standard iteration syntax, such as `for of`.\n *\n * > Preparing a statement can be time-consuming. The best way to reduce the effect of this overhead is to cache and reuse prepared\n * > statements. A cached prepared statement may be used in different places in an app, as long as the statement is general enough.\n * > The key to making this strategy work is to phrase a statement in a general way and use placeholders to represent parameters that will vary on each use.\n * @public\n */\nexport class SqliteStatement implements IterableIterator<any>, IDisposable {\n private _stmt: IModelJsNative.SqliteStatement | undefined;\n private _db: IModelJsNative.AnyDb | undefined;\n\n public constructor(private _sql: string) { }\n public get stmt(): IModelJsNative.SqliteStatement { return this._stmt!; }\n public get sql() { return this._sql; }\n\n /** Check if this statement has been prepared successfully or not */\n public get isPrepared(): boolean { return undefined !== this._stmt; }\n\n /** Prepare this statement prior to first use.\n * @param db The DgnDb or ECDb to prepare the statement against\n * @param sql The SQL statement string to prepare\n * @param logErrors Determine if errors are logged or not\n * @throws if the SQL statement cannot be prepared. Normally, prepare fails due to SQL syntax errors or references to tables or properties that do not exist.\n * The error.message property will provide details.\n */\n public prepare(db: IModelJsNative.AnyDb, logErrors = true): void {\n if (this.isPrepared)\n throw new Error(\"SqliteStatement is already prepared\");\n this._db = db;\n this._stmt = new IModelHost.platform.SqliteStatement();\n this._stmt.prepare(db, this._sql, logErrors);\n }\n\n /** Indicates whether the prepared statement makes no **direct* changes to the content of the file\n * or not. See [SQLite docs](https://www.sqlite.org/c3ref/stmt_readonly.html) for details.\n */\n public get isReadonly(): boolean {\n return this.stmt.isReadonly();\n }\n\n /** Reset this statement so that the next call to step will return the first row, if any.\n */\n public reset(): void {\n this.stmt.reset();\n }\n\n /** Call this function when finished with this statement. This releases the native resources held by the statement. */\n public dispose(): void {\n if (this._stmt) {\n this._stmt.dispose(); // free native statement\n this._stmt = undefined;\n this._db = undefined;\n }\n }\n\n /**\n * Call `step` on this statement and determine whether a new row is available.\n * Use this method only when this statement has been prepared with a SELECT statement.\n * @return true if a new row is available, false otherwise.\n * @throws if `step` returns anything other than BE_SQLITE_ROW or BE_SQLITE_DONE.\n */\n public nextRow(): boolean {\n const rc = this.step();\n switch (rc) {\n case DbResult.BE_SQLITE_ROW:\n return true;\n case DbResult.BE_SQLITE_DONE:\n return false;\n }\n\n throw new BentleyError(rc, this._db!.getLastError());\n }\n\n /** Binds a value to the specified SQL parameter.\n * The value must be of one of these types:\n * JavaScript Type | SQLite Type\n * --- | ---\n * undefined | NULL\n * boolean | INTEGER with true being bound as 1 and false as 0\n * number | INTEGER if number is integral or REAL if number is not integral\n * string | TEXT\n * Uint8Array or ArrayBuffer | BLOB\n * [StringParam]($backend) where member **id** is set | INTEGER\n * [StringParam]($backend) where member **guid** is set | BLOB\n *\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param value Value to bind.\n * @throws [IModelError]($common) if the value is of an unsupported type or in\n * case of other binding errors.\n */\n public bindValue(parameter: BindParameter, value: any): void {\n let stat: DbResult;\n if (value === undefined || value === null) {\n stat = this.stmt.bindNull(parameter);\n } else if (typeof (value) === \"number\") {\n if (Number.isInteger(value))\n stat = this.stmt.bindInteger(parameter, value);\n else\n stat = this.stmt.bindDouble(parameter, value);\n } else if (typeof (value) === \"boolean\") {\n stat = this.stmt.bindInteger(parameter, value ? 1 : 0);\n } else if (typeof (value) === \"string\") {\n stat = this.stmt.bindString(parameter, value);\n } else if (!!value.id) {\n stat = this.stmt.bindId(parameter, value.id);\n } else if (!!value.guid) {\n stat = this.stmt.bindGuid(parameter, value.guid);\n } else if (value instanceof Uint8Array) {\n stat = this.stmt.bindBlob(parameter, value);\n } else\n throw new IModelError(DbResult.BE_SQLITE_ERROR, `Parameter value ${value} is of an unsupported data type.`);\n\n if (stat !== DbResult.BE_SQLITE_OK)\n throw new IModelError(stat, \"Error in bindValue\");\n }\n\n /** Bind an integer parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val integer to bind.\n */\n public bindInteger(parameter: BindParameter, val: number) {\n checkBind(this.stmt.bindInteger(parameter, val));\n }\n /** Bind an integer parameter if it is defined. Otherwise do nothing.\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val integer to bind.\n */\n public maybeBindInteger(parameter: BindParameter, val?: number) {\n if (val !== undefined)\n this.bindInteger(parameter, val);\n }\n /** Bind a boolean parameter.\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val boolean to bind.\n */\n public bindBoolean(parameter: BindParameter, val: boolean) {\n this.bindInteger(parameter, val ? 1 : 0);\n }\n /** Bind a boolean parameter if it is defined. Otherwise do nothing.\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val boolean to bind.\n */\n public maybeBindBoolean(parameter: BindParameter, val?: boolean) {\n if (val !== undefined)\n this.bindBoolean(parameter, val);\n }\n /** JSON.stringify a property value and bind the JSON string.\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val object to bind.\n * @internal\n */\n public bindProps<T>(colIndex: number, val: T) {\n this.bindString(colIndex, JSON.stringify(val));\n }\n /** JSON.stringify a property value if it is defined, and bind the JSON string. Otherwise do nothing.\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val object to bind.\n * @internal\n */\n public maybeBindProps<T>(colIndex: number, val?: T) {\n if (val !== undefined)\n this.bindProps(colIndex, val);\n }\n /** Bind a double parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val double to bind.\n */\n public bindDouble(parameter: BindParameter, val: number) {\n checkBind(this.stmt.bindDouble(parameter, val));\n }\n /** Bind a double parameter if it is defined. Otherwise do nothing.\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val double to bind.\n */\n public maybeBindDouble(parameter: BindParameter, val?: number) {\n if (val !== undefined)\n this.bindDouble(parameter, val);\n }\n /** Bind a string parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val string to bind.\n */\n public bindString(parameter: BindParameter, val: string) {\n checkBind(this.stmt.bindString(parameter, val));\n }\n /** Bind a string parameter if it is defined. Otherwise do nothing.\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val string to bind.\n */\n public maybeBindString(parameter: BindParameter, val?: string) {\n if (val !== undefined)\n this.bindString(parameter, val);\n }\n /** Bind an Id64String parameter as a 64-bit integer\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val Id to bind.\n */\n public bindId(parameter: BindParameter, id: Id64String) {\n checkBind(this.stmt.bindId(parameter, id));\n }\n /** Bind a Guid parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val Guid to bind.\n */\n public bindGuid(parameter: BindParameter, guid: GuidString) {\n checkBind(this.stmt.bindGuid(parameter, guid));\n }\n /** Bind a blob parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val blob to bind.\n */\n public bindBlob(parameter: BindParameter, blob: Uint8Array) {\n checkBind(this.stmt.bindBlob(parameter, blob));\n }\n /** Bind a blob parameter if it is defined. Otherwise do nothing.\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val blob to bind.\n */\n public maybeBindBlob(parameter: BindParameter, val?: Uint8Array) {\n if (val !== undefined)\n this.bindBlob(parameter, val);\n }\n /** Bind null to a parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n */\n public bindNull(parameter: BindParameter) {\n checkBind(this.stmt.bindNull(parameter));\n }\n\n /** Bind values to all parameters in the statement.\n * @param values The values to bind to the parameters.\n * Pass an *array* of values if the parameters are *positional*.\n * Pass an *object of the values keyed on the parameter name* for *named parameters*.\n * The values in either the array or object must match the respective types of the parameter.\n * See [[SqliteStatement.bindValue]] for details on the supported types.\n */\n public bindValues(values: any[] | object): void {\n if (Array.isArray(values)) {\n for (let i = 0; i < values.length; i++) {\n const paramIndex: number = i + 1;\n const paramValue: any = values[i];\n if (paramValue === undefined || paramValue === null)\n continue;\n\n this.bindValue(paramIndex, paramValue);\n }\n return;\n }\n\n for (const entry of Object.entries(values)) {\n const paramName: string = entry[0];\n const paramValue: any = entry[1];\n if (paramValue === undefined || paramValue === null)\n continue;\n\n this.bindValue(paramName, paramValue);\n }\n }\n\n /** Clear any bindings that were previously set on this statement.\n * @throws [IModelError]($common) in case of errors\n */\n public clearBindings(): void {\n const stat = this.stmt.clearBindings();\n if (stat !== DbResult.BE_SQLITE_OK)\n throw new IModelError(stat, \"Error in clearBindings\");\n }\n\n /** Step this statement to the next row.\n *\n * For **SQL SELECT** statements the method returns\n * - [DbResult.BE_SQLITE_ROW]($core-bentley) if the statement now points successfully to the next row.\n * - [DbResult.BE_SQLITE_DONE]($core-bentley) if the statement has no more rows.\n * - Error status in case of errors.\n *\n * For **SQL INSERT, UPDATE, DELETE** statements the method returns\n * - [DbResult.BE_SQLITE_DONE]($core-bentley) if the statement has been executed successfully.\n * - Error status in case of errors.\n */\n public step(): DbResult {\n return this.stmt.step();\n }\n /** Get the query result's column count (only for SQL SELECT statements). */\n public getColumnCount(): number {\n return this.stmt.getColumnCount();\n }\n /** Get the value for the column at the given index in the query result.\n * @param columnIx Index of SQL column in query result (0-based)\n */\n public getValue(columnIx: number): SqliteValue {\n return new SqliteValue(this.stmt, columnIx);\n }\n /** Determine whether the value of the specified column is null\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public isValueNull(colIndex: number): boolean {\n return this.stmt.isValueNull(colIndex);\n }\n /** Get a size in bytes of a blob or text column\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getColumnBytes(colIndex: number): number {\n return this.stmt.getColumnBytes(colIndex);\n }\n /** Get a value as a blob\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueBlob(colIndex: number): Uint8Array {\n return this.stmt.getValueBlob(colIndex);\n }\n /** Get the value as a blob, or undefined if it is null.\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueBlobMaybe(colIndex: number): Uint8Array | undefined {\n return this.isValueNull(colIndex) ? undefined : this.getValueBlob(colIndex);\n }\n /** Get a value as a double\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueDouble(colIndex: number): number {\n return this.stmt.getValueDouble(colIndex);\n }\n /** Get the value as an double, or undefined if it is null.\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueDoubleMaybe(colIndex: number): number | undefined {\n return this.isValueNull(colIndex) ? undefined : this.getValueDouble(colIndex);\n }\n /** Get a value as a integer\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueInteger(colIndex: number): number {\n return this.stmt.getValueInteger(colIndex);\n }\n /** Get the value as an integer, or undefined if it is null.\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueIntegerMaybe(colIndex: number): number | undefined {\n return this.isValueNull(colIndex) ? undefined : this.getValueInteger(colIndex);\n }\n /** Get a value as a string\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueString(colIndex: number): string {\n return this.stmt.getValueString(colIndex);\n }\n /** Get the value as a string, or undefined if it is null.\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueStringMaybe(colIndex: number): string | undefined {\n return this.isValueNull(colIndex) ? undefined : this.getValueString(colIndex);\n }\n /** Get a value as an Id\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueId(colIndex: number): Id64String {\n return this.stmt.getValueId(colIndex);\n }\n /** Get a value as a Guid\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueGuid(colIndex: number): GuidString {\n return this.stmt.getValueGuid(colIndex);\n }\n /** Get the value as a boolean. Returns `false` if the column is null.\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueBoolean(colIndex: number) {\n return this.isValueNull(colIndex) ? false : 0 !== this.getValueInteger(colIndex);\n }\n /** Get the value of a [julianday](https://www.sqlite.org/lang_datefunc.html) column as a JavaScript `Date`.\n * @param colIndex Index of SQL column in query result (0-based)\n * @beta\n */\n public getValueDate(colIndex: number) {\n return new Date((this.stmt.getValueDouble(colIndex) - 2440587.5) * 86400000); // conversion from julian day ms to unix epoch ms\n }\n /** Get the value as a \"props\" JSON string, then parse it and return the object\n * @param colIndex Index of SQL column in query result (0-based)\n * @internal\n */\n public getProps<T>(colIndex: number): T {\n return JSON.parse(this.getValueString(colIndex));\n }\n /** Get the value as a \"props\" JSON string, then parse it and return the object.\n * If the column is null, return undefined.\n * @param colIndex Index of SQL column in query result (0-based)\n * @internal\n */\n public getPropsMaybe<T>(colIndex: number): T | undefined {\n return this.isValueNull(colIndex) ? undefined : this.getProps(colIndex);\n }\n\n /** Get the current row.\n * The returned row is formatted as JavaScript object where every SELECT clause item becomes a property in the JavaScript object.\n *\n * The SQL select clause item's name becomes the member name of the JavaScript object, **with the first character lowered**.\n *\n * SQLite Type | JavaScript Type\n * --- | ---\n * [SqliteValueType.Null]($backend) | undefined\n * [SqliteValueType.Integer]($backend) | number\n * [SqliteValueType.Double]($backend) | number\n * [SqliteValueType.String]($backend) | string\n * [SqliteValueType.Blob]($backend) | Uint8Array\n */\n public getRow(): any {\n const colCount = this.getColumnCount();\n const row: object = {};\n const duplicatePropNames = new Map<string, number>();\n for (let i = 0; i < colCount; i++) {\n const sqliteValue = this.getValue(i);\n if (!sqliteValue.isNull) {\n const propName: string = SqliteStatement.determineResultRowPropertyName(duplicatePropNames, sqliteValue);\n let val: any;\n switch (sqliteValue.type) {\n case SqliteValueType.Blob:\n val = sqliteValue.getBlob();\n break;\n case SqliteValueType.Double:\n val = sqliteValue.getDouble();\n break;\n case SqliteValueType.Integer:\n val = sqliteValue.getInteger();\n break;\n case SqliteValueType.String:\n val = sqliteValue.getString();\n break;\n\n default:\n throw new Error(\"Unsupported SqliteValueType\");\n }\n\n Object.defineProperty(row, propName, { enumerable: true, configurable: true, writable: true, value: val });\n }\n }\n return row;\n }\n\n private static determineResultRowPropertyName(duplicatePropNames: Map<string, number>, sqliteValue: SqliteValue): string {\n let jsName = ECJsNames.toJsName(sqliteValue.columnName);\n\n // now check duplicates. If there are, append a numeric suffix to the duplicates\n let suffix = duplicatePropNames.get(jsName);\n if (suffix === undefined)\n duplicatePropNames.set(jsName, 0);\n else {\n suffix++;\n duplicatePropNames.set(jsName, suffix);\n jsName += `_${suffix}`;\n }\n\n return jsName;\n }\n\n /** Calls step when called as an iterator.\n */\n public next(): IteratorResult<any> {\n return DbResult.BE_SQLITE_ROW === this.step() ? { done: false, value: this.getRow() } : { done: true, value: undefined };\n }\n\n /** The iterator that will step through the results of this statement. */\n public [Symbol.iterator](): IterableIterator<any> { return this; }\n}\n\n/** Data type of a value in in an SQLite SQL query result.\n * See also:\n * - [SqliteValue]($backend)\n * - [SqliteStatement]($backend)\n * - [SqliteStatement.getValue]($backend)\n * @public\n */\nexport enum SqliteValueType {\n // do not change the values of that enum. It must correspond to the respective\n // enum DbValueType in the native BeSQLite API.\n Integer = 1,\n Double = 2,\n String = 3,\n Blob = 4,\n Null = 5,\n}\n\n/** Value of a column in a row of an SQLite SQL query result.\n * See also:\n * - [SqliteStatement]($backend)\n * - [SqliteStatement.getValue]($backend)\n * @public\n */\nexport class SqliteValue {\n private readonly _stmt: IModelJsNative.SqliteStatement;\n private readonly _colIndex: number;\n\n public constructor(stmt: IModelJsNative.SqliteStatement, colIndex: number) {\n this._stmt = stmt;\n this._colIndex = colIndex;\n }\n\n /** Indicates whether the value is NULL or not. */\n public get isNull(): boolean { return this._stmt.isValueNull(this._colIndex); }\n\n /** Gets the data type of the value. */\n public get type(): SqliteValueType { return this._stmt.getColumnType(this._colIndex); }\n\n /** Gets the name of the column of the value. */\n public get columnName(): string { return this._stmt.getColumnName(this._colIndex); }\n\n /** Gets the SqlValue as JavaScript value.\n *\n * SQLite Type | JavaScript Type\n * --- | ---\n * [SqliteValueType.Null]($backend) | undefined\n * [SqliteValueType.Integer]($backend) | number\n * [SqliteValueType.Double]($backend) | number\n * [SqliteValueType.String]($backend) | string\n * [SqliteValueType.Blob]($backend) | Uint8Array\n */\n public get value(): any {\n switch (this.type) {\n case SqliteValueType.Null:\n return undefined;\n case SqliteValueType.Blob:\n return this.getBlob();\n case SqliteValueType.Double:\n return this.getDouble();\n case SqliteValueType.Integer:\n return this.getInteger();\n case SqliteValueType.String:\n return this.getString();\n default:\n throw new Error(\"Unhandled SqliteValueType\");\n }\n }\n\n /** Get the value as Blob */\n public getBlob(): Uint8Array { return this._stmt.getValueBlob(this._colIndex); }\n /** Get the value as a double value */\n public getDouble(): number { return this._stmt.getValueDouble(this._colIndex); }\n /** Get the value as a integer value */\n public getInteger(): number { return this._stmt.getValueInteger(this._colIndex); }\n /** Get the value as a string value */\n public getString(): string { return this._stmt.getValueString(this._colIndex); }\n /** Get the value as an Id value */\n public getId(): Id64String { return this._stmt.getValueId(this._colIndex); }\n /** Get the value as a Guid value */\n public getGuid(): GuidString { return this._stmt.getValueGuid(this._colIndex); }\n}\n\ninterface Statement {\n isPrepared: boolean;\n sql: string;\n dispose(): void;\n reset(): void;\n clearBindings(): void;\n}\n\n/** A cache for previously prepared SqliteStatements.\n * It only holds Statements after they are no longer in use, resetting and clearing their bindings before saving them.\n * When a request to use a statement from the cache is made, it is first removed from the cache.\n * @internal\n */\nexport class StatementCache<Stmt extends Statement> {\n private _cache: LRUMap<string, Stmt>;\n\n public constructor(maxCount = 40) {\n this._cache = new LRUMap<string, Stmt>(maxCount);\n }\n\n public get size() { return this._cache.size; }\n public addOrDispose(stmt: Stmt): void {\n assert(stmt.isPrepared);\n\n const existing = this._cache.get(stmt.sql);\n if (existing !== undefined) {\n stmt.dispose(); // we already have a statement with this sql cached, we can't save another one so just dispose it\n return;\n }\n if (this._cache.size >= this._cache.limit) {\n const oldest = this._cache.shift()!;\n oldest[1].dispose();\n }\n stmt.reset();\n stmt.clearBindings();\n this._cache.set(stmt.sql, stmt);\n }\n\n public findAndRemove(sql: string): Stmt | undefined {\n return this._cache.delete(sql);\n }\n\n public clear() {\n this._cache.forEach((stmt) => stmt.dispose());\n this._cache.clear();\n }\n}\n"]}
|
|
@@ -21,7 +21,7 @@ const SQLiteDb_1 = require("../SQLiteDb");
|
|
|
21
21
|
const Settings_1 = require("./Settings");
|
|
22
22
|
const SettingsSchemas_1 = require("./SettingsSchemas");
|
|
23
23
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
24
|
-
// cspell:ignore rowid primarykey
|
|
24
|
+
// cspell:ignore rowid primarykey julianday
|
|
25
25
|
/** The Settings used by Workspace api
|
|
26
26
|
* @beta
|
|
27
27
|
*/
|