PreparedStatement

Description

sealed class Tinman.AddOns.SQLite.PreparedStatement

Derived from

Disposable abstract
INativeHandle

Full source code is included in the Tinman 3D SDK download.

The PreparedStatement is a wrapper for a native sqlite3_stmt* pointer to a prepared statement.

Executing a prepared statement takes the following steps:

  1. Obtain a PreparedStatement object, either by calling DatabaseFile.Prepare to create a new one or StatementCollection.Reset to get a cached one in fresh state.

  2. Use the Parameter* methods to fill in the parameter values.

  3. Use the Step* methods to move through the result rows. For each result row, use the Column* methods to fetch column data.

  4. Call Reset when done, to avoid SQLite3.LOCKED errors.

  5. Use RowChanges and RowIdentifier to fetch information about the most recently executed statement.

Public / Methods

Column­Bytes


[Constant]
public method ColumnBytes → (1)

index in : int32

The zero-based column index.

returns → ByteBuffer

The value.

Returns a result row column as a byte sequence.

The contents of the returned ByteBuffer is valid until ColumnBytes, Step or Reset is called.

Column­Float64


[Pure]
public method ColumnFloat64 → (1)

index in : int32

The zero-based column index.

returns → float64

The value.

Returns a result row column as a 64-bit floating-point value.

Column­Index


[Pure]
public method ColumnIndex → (1)

name in : string

The column name.

returns → int32

The zero-based column index or -1 if not found.

Returns the index of the given column.

Column­Int32


[Pure]
public method ColumnInt32 → (1)

index in : int32

The zero-based column index.

returns → int32

The value.

Returns a result row column as a 32-bit integer value.

Column­Int64


[Pure]
public method ColumnInt64 → (1)

index in : int32

The zero-based column index.

returns → int64

The value.

Returns a result row column as a 64-bit integer value.

Column­Name


[Pure]
public method ColumnName → (1)

index in : int32

The zero-based column index.

returns → string

The column name or null if not found.

Returns the name of the index in-th result row column.

Column­String


[Pure]
public method ColumnString → (1)

index in : int32

The zero-based column index.

returns → string

The value.

Returns a result row column as string value.

Parameter

6 overloads


public method Parameter1 → (1)

index in : int32

The one-based parameter index.

returns → PreparedStatement

this

Binds NULL to the given parameter.

IOException

If an I/O error has occurred.

See also

SQLite3.BindNull


public method Parameter2 → (2)

index in : int32

The one-based parameter index.

value in : int32

The parameter value.

returns → PreparedStatement

this

Binds the given value in to a parameter.

IOException

If an I/O error has occurred.

See also

SQLite3.BindInt


public method Parameter3 → (2)

index in : int32

The one-based parameter index.

value in : int64

The parameter value.

returns → PreparedStatement

this

Binds the given value in to a parameter.

IOException

If an I/O error has occurred.


public method Parameter4 → (2)

index in : int32

The one-based parameter index.

value in : float64

The parameter value.

returns → PreparedStatement

this

Binds the given value in to a parameter.

If value in is not a number (see Maths.IsNumber), this method delegates to Parameter1.

IOException

If an I/O error has occurred.


public method Parameter5 → (2)

index in : int32

The one-based parameter index.

value in : string

The parameter value.

returns → PreparedStatement

this

Binds the given value in to a parameter.

If value in is null, this method delegates to Parameter1.

IOException

If an I/O error has occurred.

See also

SQLite3.BindText


public method Parameter6 → (2)

index in : int32

The one-based parameter index.

value in : ByteBuffer

The parameter value.

returns → PreparedStatement

this

Binds the given value in to a parameter.

If value in is null, this method delegates to Parameter1. The parameter binding is set to ByteBuffer.RawPosition and ByteBuffer.Remaining of value in, assuming that the ByteBuffer object is not modified until the statement finishes.

IOException

If an I/O error has occurred.

Parameter­Clear


public method ParameterClear → ()

returns → PreparedStatement

this

Clears all parameter bindings.

IOException

If an I/O error has occurred.

Parameter­Index


[Pure]
public method ParameterIndex → (1)

name in : string

The statement parameter name.

returns → int32

The parameter index or 0 if not found.

Returns the index of a statement parameter.

Parameter­Name


[Pure]
public method ParameterName → (1)

index in : int32

The statement parameter index.

returns → string

The parameter name or null if not found.

Returns the name of a statement parameter.

Reset


public method Reset → (1)

throwOnError opt : bool = true

Throw an IOException if SQLite3.Reset returns a value other than SQLite3.OK?

returns → PreparedStatement

this

Resets the prepared statement for being executed again later.

A prepared statement should be reset after each execution, to avoid SQLite3.LOCKED errors. The Step method automatically resets the prepared statement.

IOException

If an I/O error has occurred.

See also

SQLite3.Reset

Row­Changes


public method RowChanges → ()

returns → int64

The number of affected rows.

Returns the number of affected rows.

Row­Identifier


[Pure]
public method RowIdentifier → ()

returns → int64

The row identifier.

Returns the identifier of the inserted row.

Step


public method Step → (1)

success opt : int32 = 7

Bitflag to decide which result codes mean success:
1 : treat SQLite3.ROW as success,
2 : treat SQLite3.DONE as success,
4 : treat SQLite3.CONSTRAINT as success.

returns → int32

> 0 if a result row is available (see SQLite3.ROW),
= 0 if there are no more result rows (see SQLite3.DONE),
< 0 if a constraint has been violated (see SQLite3.CONSTRAINT).

Steps through the result rows of the statement, evaluating it upon the first call.

Reset must be called on this statement only if this method has returned a value greater than zero. In all other cases, the statement is reset automatically before the method returns or throws.

IOException

If an I/O error has occurred.

See also

SQLite3.Step

Step­Done


public method StepDone → ()

Steps through the result rows of the statement, expecting SQLite3.DONE.

This method delegates to Step passing 2.

IOException

If an I/O error has occurred.

See also

SQLite3.Step

Step­Row


public method StepRow → ()

returns → bool

true if a result row is available,
false if there are no more result rows

Steps through the result rows of the statement, expecting SQLite3.ROW or SQLite3.DONE.

This method delegates to Step passing 3 and returns true if a value greater than zero is returned.

IOException

If an I/O error has occurred.

See also

SQLite3.Step

Public / Attributes

Column­Count


public attribute ColumnCount → (get)

value : int32

[>=0]
The column count.

Returns the number of result row columns.

Parameter­Count


public attribute ParameterCount → (get)

value : int32

[>=0]
The parameter count.

Returns the number of parameters.

Sql


[Constant]
public attribute Sql → (get)

value : string

The SQL code, as passed to DatabaseFile.Prepare or null iff the SQL code has not been kept.

The SQL code of this prepared statement.