Skip to content

Statement

[Source]

Non-sendable prepared statement wrapping SQLHSTMT. Reusable: bind, execute, fetch, close_cursor, rebind, re-execute.

class ref Statement

Public Functions

parameter_types

[Source]

SQL type tag for each parameter placeholder, as reported by SQLDescribeParam. Available after prepare() succeeds; no binding or execution required.

Some drivers (notably SQLite's ODBC driver) do not implement SQLDescribeParam and return MetadataError( DriverDoesNotSupportDescribeParam). psqlODBC supports it.

fun ref parameter_types()
: (Array[SqlTypeTag] val | MetadataError val)

Returns


column_types

[Source]

Metadata for each result column (name, type tag, nullability) as reported by SQLDescribeCol. Available after prepare() succeeds. Returns an empty array for non-result statements (INSERT, UPDATE, DELETE, DDL).

fun ref column_types()
: (Array[ColumnMeta val] val | MetadataError val)

Returns


parameter_types_p

[Source]

Partial variant of parameter_types(). Raises on error.

fun ref parameter_types_p()
: Array[SqlTypeTag] val ?

Returns


column_types_p

[Source]

Partial variant of column_types(). Raises on error.

fun ref column_types_p()
: Array[ColumnMeta val] val ?

Returns


bind

[Source]

Bind a value to a parameter slot. Each call replaces any previous binding on the slot — the prior SqlValue is released and the new one is retained for the lifetime of the binding.

fun ref bind(
  i: ParamIndex val,
  v: SqlValue val)
: (Bound val | BindError val)

Parameters

Returns


bind_null

[Source]

fun ref bind_null(
  i: ParamIndex val)
: (Bound val | BindError val)

Parameters

Returns


bind_p

[Source]

Partial variant of bind(). Raises error on failure.

fun ref bind_p(
  i: ParamIndex val,
  v: SqlValue val)
: None val ?

Parameters

Returns


bind_null_p

[Source]

Partial variant of bind_null(). Raises error on failure.

fun ref bind_null_p(
  i: ParamIndex val)
: None val ?

Parameters

Returns


execute

[Source]

Execute a prepared SELECT, opening a cursor.

fun ref execute()
: (Executed val | ExecError val)

Returns


execute_update

[Source]

Execute a prepared DML. Returns affected row count.

fun ref execute_update()
: (RowCount | ExecError val)

Returns


fetch

[Source]

Fetch the next row. Row is a val snapshot.

fun ref fetch()
: (Row val | EndOfRows val | FetchError val)

Returns


execute_p

[Source]

Partial variant of execute(). Raises error on failure.

fun ref execute_p()
: None val ?

Returns


execute_update_p

[Source]

Partial variant of execute_update(). Raises error on failure.

fun ref execute_update_p()
: RowCount ?

Returns


fetch_into

[Source]

Fetch the next row into a reusable MutableRow. Zero allocation for the row container (SqlText/SqlDecimal values still allocate strings).

fun ref fetch_into(
  row: MutableRow ref)
: (MutableRow ref | EndOfRows val | FetchError val)

Parameters

Returns


values

[Source]

Return an iterator for use with Pony's for loop. Yields (Row val | FetchError) — match on each result.

fun ref values()
: StatementIterator ref

Returns


cancel_token

[Source]

Return a sendable token that can cancel this statement's in-progress operation from another actor.

The token captures a raw copy of the SQLHSTMT pointer. It does not track whether the statement has been closed. Calling cancel() on a token after close() invokes SQLCancel on a freed handle — undefined behavior. The caller must ensure all outstanding tokens are discarded before calling close().

fun box cancel_token()
: CancelToken val

Returns


close_cursor

[Source]

Close cursor, keep statement for rebinding and re-execution. Unbinds columns so they can be rebound on next execute.

fun ref close_cursor()
: None val

Returns


last_warnings

[Source]

fun ref last_warnings()
: (Warnings val | None val)

Returns


close

[Source]

Free the SQLHSTMT. Idempotent.

Any CancelTokens obtained from cancel_token() become invalid after this call. Using a token after close() is undefined behavior — see cancel_token() for the lifetime contract.

If the connection has already been closed, the driver freed this handle transitively via SQLFreeHandle(SQL_HANDLE_DBC); in that case we only mark ourselves closed without a second SQLFreeHandle call (which would be UB on a dangling handle).

fun ref close()
: None val

Returns