ECSqlStatement Class

Executes ECSQL statements.

A statement must be prepared before it can be executed, and it must be released when no longer needed. See IModelDb.withPreparedStatement or ECDb.withPreparedStatement 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.step. In case of an ECSQL SELECT statement, the current row can be retrieved with ECSqlStatement.getRow as a whole, or with ECSqlStatement.getValue when individual values are needed. Alternatively, query results of an ECSQL SELECT statement can be stepped through by using standard iteration syntax, such as for of.

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 iModel.js API.
  • Code Examples illustrate the use of the iModel.js API for executing and working with ECSQL



Name Description
__@iterator(): IterableIterator<any> The iterator that will step through the results of this statement.  
bindArray(parameter: number | string, val: any[]): void Binds an array value to the specified ECSQL parameter.  
bindBlob(parameter: number | string, blob: string | Uint8Array | ArrayBuffer | SharedArrayBuffer): void Binds a BLOB value to the specified ECSQL parameter.  
bindBoolean(parameter: number | string, val: boolean): void Binds a boolean value to the specified ECSQL parameter.  
bindDateTime(parameter: number | string, isoDateTimeString: string): void Binds a DateTime value to the specified ECSQL parameter.  
bindDouble(parameter: number | string, val: number): void Binds a double value to the specified ECSQL parameter.  
bindGuid(parameter: number | string, val: GuidString): void Binds an GUID value to the specified ECSQL parameter.  
bindId(parameter: number | string, val: Id64String): void Binds an Id value to the specified ECSQL parameter.  
bindInteger(parameter: number | string, val: number | string): void Binds an integer value to the specified ECSQL parameter.  
bindNavigation(parameter: number | string, val: NavigationBindingValue): void Binds a navigation property value to the specified ECSQL parameter.  
bindNull(parameter: number | string): void Binds null to the specified ECSQL parameter.  
bindPoint2d(parameter: number | string, val: XAndY): void Binds an Point2d value to the specified ECSQL parameter.  
bindPoint3d(parameter: number | string, val: XYAndZ): void Binds an Point3d value to the specified ECSQL parameter.  
bindRange3d(parameter: number | string, val: LowAndHighXYZ): void Binds a Range3d as a blob to the specified ECSQL parameter  
bindString(parameter: number | string, val: string): void Binds an string to the specified ECSQL parameter.  
bindStruct(parameter: number | string, val: object): void Binds a struct property value to the specified ECSQL parameter.  
bindValue(parameter: number | string, val: any): void Binds the specified value to the specified ECSQL parameter.  
bindValues(values: any[] | object): void Bind values to all parameters in the statement.  
clearBindings(): void Clear any bindings that were previously set on this statement.  
dispose(): void Call this function when finished with this statement.  
getBinder(parameter: string | number): ECSqlBinder Gets a binder to bind a value for an ECSQL parameter
> This is the most low-level API to bind a value to a specific parameter.
getColumnCount(): number Get the query result's column count (only for ECSQL SELECT statements).  
getRow(): any Get the current row.  
getValue(columnIx: number): ECSqlValue Get the value for the column at the given index in the query result.  
next(): IteratorResult<any> Calls step when called as an iterator.  
reset(): void Reset this statement so that the next call to step will return the first row, if any.  
step(): DbResult Step this statement to the next row.  
stepForInsert(): ECSqlInsertResult Step this INSERT statement and returns status and the ECInstanceId of the newly
created instance.


Name Type Description
isPrepared Accessor ReadOnly boolean Check if this statement has been prepared successfully or not  

Defined in

Last Updated: 08 January, 2020