ECSqlWriteStatement Class
Executes ECSQL INSERT/UPDATE/DELETE statements.
A statement must be prepared before it can be executed, and it must be released when no longer needed. See ECDb.withCachedWriteStatement for a convenient and reliable way to prepare, execute, and then release a statement.
A statement may contain parameters that must be filled in before use by the bind methods.
Once prepared (and parameters are bound, if any), the statement is executed by calling ECSqlStatement.stepForInsert.
Preparing a statement can be time-consuming. The best way to reduce the effect of this overhead is to cache and reuse prepared statements. A cached prepared statement may be used in different places in an app, as long as the statement is general enough. 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.
See also
- Executing ECSQL provides more background on ECSQL and an introduction on how to execute ECSQL with the iTwin.js API.
- Code Examples illustrate the use of the iTwin.js API for executing and working with ECSQL
Methods
Name | Description | |
---|---|---|
constructor(stmt?: ECSqlStatement): ECSqlWriteStatement | ||
bindArray(parameter: string | number, val: any[]): void | Binds an array value to the specified ECSQL parameter. | |
bindBlob(parameter: string | number, blob: string | Uint8Array | ArrayBuffer | SharedArrayBuffer): void | Binds a BLOB value to the specified ECSQL parameter. | |
bindBoolean(parameter: string | number, val: boolean): void | Binds a boolean value to the specified ECSQL parameter. | |
bindDateTime(parameter: string | number, isoDateTimeString: string): void | Binds a DateTime value to the specified ECSQL parameter. | |
bindDouble(parameter: string | number, val: number): void | Binds a double value to the specified ECSQL parameter. | |
bindGuid(parameter: string | number, val: string): void | Binds an GUID value to the specified ECSQL parameter. | |
bindId(parameter: string | number, val: string): void | Binds an Id value to the specified ECSQL parameter. | |
bindIdSet(parameter: string | number, val: string[]): void | ||
bindInteger(parameter: string | number, val: string | number): void | Binds an integer value to the specified ECSQL parameter. | |
bindNavigation(parameter: string | number, val: NavigationBindingValue): void | Binds a navigation property value to the specified ECSQL parameter. | |
bindNull(parameter: string | number): void | Binds null to the specified ECSQL parameter. | |
bindPoint2d(parameter: string | number, val: Readonly<WritableXAndY>): void | Binds an Point2d value to the specified ECSQL parameter. | |
bindPoint3d(parameter: string | number, val: Readonly<WritableXYAndZ>): void | Binds an Point3d value to the specified ECSQL parameter. | |
bindRange3d(parameter: string | number, val: Readonly<WritableLowAndHighXYZ>): void | Binds a Range3d as a blob to the specified ECSQL parameter | |
bindString(parameter: string | number, val: string): void | Binds an string to the specified ECSQL parameter. | |
bindStruct(parameter: string | number, val: object): void | Binds a struct property value to the specified ECSQL parameter. | |
bindValue(parameter: string | number, val: any): void | Binds the specified value to the specified ECSQL parameter. | |
bindValues(values: object | any[]): void | Bind values to all parameters in the statement. | |
clearBindings(): void | Clear any bindings that were previously set on this statement. | |
getBinder(parameter: string | number): ECSqlBinder | Gets a binder to bind a value for an ECSQL parameter | |
getColumnCount(): number | Get the query result's column count (only for ECSQL SELECT statements). | |
reset(): void | Reset this statement so that the next call to step will return the first row, if any. | |
stepForInsert(): ECSqlInsertResult | Step this INSERT statement and returns status and the ECInstanceId of the newly |
Properties
Name | Type | Description | |
---|---|---|---|
isPrepared Accessor ReadOnly | boolean | Check if this statement has been prepared successfully or not | |
sql Accessor ReadOnly | string |
Defined in
- core/backend/src/ECSqlStatement.ts Line 445
Last Updated: 26 April, 2025