Statement¶
Non-sendable prepared statement wrapping SQLHSTMT. Reusable: bind, execute, fetch, close_cursor, rebind, re-execute.
Public Functions¶
parameter_types¶
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.
Returns¶
- (Array[SqlTypeTag] val | MetadataError val)
column_types¶
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).
Returns¶
- (Array[ColumnMeta val] val | MetadataError val)
parameter_types_p¶
Partial variant of parameter_types(). Raises on error.
Returns¶
- Array[SqlTypeTag] val ?
column_types_p¶
Partial variant of column_types(). Raises on error.
Returns¶
- Array[ColumnMeta val] val ?
bind¶
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.
Parameters¶
- i: ParamIndex val
- v: SqlValue val
Returns¶
bind_null¶
Parameters¶
- i: ParamIndex val
Returns¶
bind_p¶
Partial variant of bind(). Raises error on failure.
Parameters¶
- i: ParamIndex val
- v: SqlValue val
Returns¶
- None val ?
bind_null_p¶
Partial variant of bind_null(). Raises error on failure.
Parameters¶
- i: ParamIndex val
Returns¶
- None val ?
execute¶
Execute a prepared SELECT, opening a cursor.
Returns¶
execute_update¶
Execute a prepared DML. Returns affected row count.
Returns¶
fetch¶
Fetch the next row. Row is a val snapshot.
Returns¶
- (Row val | EndOfRows val | FetchError val)
execute_p¶
Partial variant of execute(). Raises error on failure.
Returns¶
- None val ?
execute_update_p¶
Partial variant of execute_update(). Raises error on failure.
Returns¶
- RowCount ?
fetch_into¶
Fetch the next row into a reusable MutableRow. Zero allocation for the row container (SqlText/SqlDecimal values still allocate strings).
Parameters¶
- row: MutableRow ref
Returns¶
- (MutableRow ref | EndOfRows val | FetchError val)
values¶
Return an iterator for use with Pony's for loop.
Yields (Row val | FetchError) — match on each result.
Returns¶
cancel_token¶
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().
Returns¶
- CancelToken val
close_cursor¶
Close cursor, keep statement for rebinding and re-execution. Unbinds columns so they can be rebound on next execute.
Returns¶
- None val
last_warnings¶
Returns¶
close¶
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).
Returns¶
- None val