← Back to Stormify Documentation
KDBC
Unified C Database Connectivity — SQLite, PostgreSQL, MariaDB, Oracle, MSSQL
Loading...
Searching...
No Matches
Statement Execution

Functions

int kdbc_execute_update_stmt (kdbc_stmt *stmt)
 Execute a prepared DML statement (INSERT/UPDATE/DELETE).
kdbc_resultkdbc_execute_query_stmt (kdbc_stmt *stmt)
 Execute a prepared query (SELECT).
kdbc_resultkdbc_generated_keys (kdbc_stmt *stmt)
 Get generated keys after an INSERT.
void kdbc_stmt_close (kdbc_stmt *stmt)
 Close a prepared statement and free resources.
int kdbc_stmt_reset (kdbc_stmt *stmt)
 Reset a prepared statement for re-execution.
int kdbc_set_fetch_size (kdbc_stmt *stmt, int rows)
 Set a fetch size hint for query execution.

Detailed Description

Execute prepared statements and retrieve generated keys.

Function Documentation

◆ kdbc_execute_update_stmt()

int kdbc_execute_update_stmt ( kdbc_stmt * stmt)

Execute a prepared DML statement (INSERT/UPDATE/DELETE).

Parameters
stmtA prepared statement with all parameters bound.
Returns
Number of affected rows, or KDBC_ERROR on failure.

◆ kdbc_execute_query_stmt()

kdbc_result * kdbc_execute_query_stmt ( kdbc_stmt * stmt)

Execute a prepared query (SELECT).

The returned result set must be closed with kdbc_result_close().

Parameters
stmtA prepared statement with all parameters bound.
Returns
A result set handle, or NULL on failure.

◆ kdbc_generated_keys()

kdbc_result * kdbc_generated_keys ( kdbc_stmt * stmt)

Get generated keys after an INSERT.

Returns a synthetic result set with one row containing the generated key(s). The statement must have been prepared with kdbc_prepare_returning().

"INSERT INTO users (name) VALUES (?)", (const char*[]){"id"}, 1);
kdbc_bind_string(stmt, 1, "Bob");
if (keys && kdbc_next(keys))
printf("Generated ID: %lld\n", (long long)kdbc_get_long(keys, 1));
int kdbc_execute_update_stmt(kdbc_stmt *stmt)
Execute a prepared DML statement (INSERT/UPDATE/DELETE).
void kdbc_stmt_close(kdbc_stmt *stmt)
Close a prepared statement and free resources.
kdbc_result * kdbc_generated_keys(kdbc_stmt *stmt)
Get generated keys after an INSERT.
int kdbc_next(kdbc_result *rs)
Advance to the next row.
void kdbc_result_close(kdbc_result *rs)
Close a result set and free resources.
int64_t kdbc_get_long(kdbc_result *rs, int col)
Get a column value as a 64-bit integer.
int kdbc_bind_string(kdbc_stmt *stmt, int idx, const char *val)
Bind a UTF-8 string parameter.
kdbc_stmt * kdbc_prepare_returning(kdbc_conn *conn, const char *sql, const char **col_names, int n_cols)
Prepare a SQL statement that returns generated keys.
struct kdbc_result kdbc_result
Opaque result set handle.
Definition kdbc.h:47
struct kdbc_stmt kdbc_stmt
Opaque prepared statement handle.
Definition kdbc.h:44
Parameters
stmtA prepared statement after execution.
Returns
A result set with generated keys, or NULL if none.

◆ kdbc_stmt_close()

void kdbc_stmt_close ( kdbc_stmt * stmt)

Close a prepared statement and free resources.

Safe to call with NULL (no-op).

Parameters
stmtThe statement to close, or NULL.

◆ kdbc_stmt_reset()

int kdbc_stmt_reset ( kdbc_stmt * stmt)

Reset a prepared statement for re-execution.

Clears all bound parameters, pending batch entries, generated key state, cached OUT-parameter values, and the error buffer so the statement can be reused with new values. Any batches accumulated via kdbc_add_batch() are discarded — call kdbc_execute_batch() first if they should run. OUT-parameter registrations are preserved; only their cached result values are cleared.

Parameters
stmtA prepared statement.
Returns
KDBC_OK or KDBC_ERROR.

◆ kdbc_set_fetch_size()

int kdbc_set_fetch_size ( kdbc_stmt * stmt,
int rows )

Set a fetch size hint for query execution.

Suggests how many rows the driver should fetch per round-trip. This is a hint — drivers may ignore it.

Parameters
stmtA prepared statement.
rowsNumber of rows to fetch at a time (0 = driver default).
Returns
KDBC_OK or KDBC_ERROR.