|
KDBC
Unified C Database Connectivity — SQLite, PostgreSQL, MariaDB, Oracle, MSSQL
|
Functions | |
| kdbc_stmt * | kdbc_prepare (kdbc_conn *conn, const char *sql) |
| Prepare a SQL statement. | |
| 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. | |
| int | kdbc_bind_null (kdbc_stmt *stmt, int idx) |
| Bind a NULL value to a parameter. | |
| int | kdbc_bind_int (kdbc_stmt *stmt, int idx, int val) |
| Bind a 32-bit integer parameter. | |
| int | kdbc_bind_bool (kdbc_stmt *stmt, int idx, int val) |
| Bind a boolean parameter. | |
| int | kdbc_bind_long (kdbc_stmt *stmt, int idx, int64_t val) |
| Bind a 64-bit integer parameter. | |
| int | kdbc_bind_double (kdbc_stmt *stmt, int idx, double val) |
| Bind a double-precision float parameter. | |
| int | kdbc_bind_string (kdbc_stmt *stmt, int idx, const char *val) |
| Bind a UTF-8 string parameter. | |
| int | kdbc_bind_blob (kdbc_stmt *stmt, int idx, const void *data, size_t len) |
| Bind a binary blob parameter. | |
| int | kdbc_bind_timestamp (kdbc_stmt *stmt, int idx, int year, int month, int day, int hour, int minute, int second, int usec) |
| Bind a timestamp (date + time) parameter. | |
| int | kdbc_bind_date (kdbc_stmt *stmt, int idx, int year, int month, int day) |
| Bind a date-only parameter. | |
| int | kdbc_bind_time (kdbc_stmt *stmt, int idx, int hour, int minute, int second, int usec) |
| Bind a time-only parameter. | |
Prepare SQL, bind parameters, and manage statement lifecycle.
Use ? as parameter placeholders — KDBC translates them automatically:
All parameter indices are 1-indexed.
Prepare a SQL statement.
| conn | An open connection. |
| sql | SQL with ? parameter placeholders. |
| 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.
Used for INSERT statements when you need to retrieve auto-generated primary keys. The mechanism varies by database:
| conn | An open connection. |
| sql | SQL with ? parameter placeholders. |
| col_names | Array of column names to return (may be NULL for index-based drivers). |
| n_cols | Number of entries in col_names (0 if NULL). |
| int kdbc_bind_null | ( | kdbc_stmt * | stmt, |
| int | idx ) |
Bind a NULL value to a parameter.
| stmt | A prepared statement. |
| idx | Parameter index (1-indexed). |
| int kdbc_bind_int | ( | kdbc_stmt * | stmt, |
| int | idx, | ||
| int | val ) |
Bind a 32-bit integer parameter.
| stmt | A prepared statement. |
| idx | Parameter index (1-indexed). |
| val | The integer value. |
| int kdbc_bind_bool | ( | kdbc_stmt * | stmt, |
| int | idx, | ||
| int | val ) |
Bind a boolean parameter.
On databases with native BOOLEAN support (e.g. PostgreSQL), this binds as a true boolean. On all others, it binds as an integer (0 or 1).
| stmt | A prepared statement. |
| idx | Parameter index (1-indexed). |
| val | The boolean value (0 = false, non-zero = true). |
| int kdbc_bind_long | ( | kdbc_stmt * | stmt, |
| int | idx, | ||
| int64_t | val ) |
Bind a 64-bit integer parameter.
| stmt | A prepared statement. |
| idx | Parameter index (1-indexed). |
| val | The int64 value. |
| int kdbc_bind_double | ( | kdbc_stmt * | stmt, |
| int | idx, | ||
| double | val ) |
Bind a double-precision float parameter.
| stmt | A prepared statement. |
| idx | Parameter index (1-indexed). |
| val | The double value. |
| int kdbc_bind_string | ( | kdbc_stmt * | stmt, |
| int | idx, | ||
| const char * | val ) |
Bind a UTF-8 string parameter.
The string is copied internally — the caller may free val immediately.
| stmt | A prepared statement. |
| idx | Parameter index (1-indexed). |
| val | The null-terminated UTF-8 string. |
| int kdbc_bind_blob | ( | kdbc_stmt * | stmt, |
| int | idx, | ||
| const void * | data, | ||
| size_t | len ) |
Bind a binary blob parameter.
The data is copied internally — the caller may free data immediately.
| stmt | A prepared statement. |
| idx | Parameter index (1-indexed). |
| data | Pointer to the binary data. |
| len | Length of data in bytes. |
| int kdbc_bind_timestamp | ( | kdbc_stmt * | stmt, |
| int | idx, | ||
| int | year, | ||
| int | month, | ||
| int | day, | ||
| int | hour, | ||
| int | minute, | ||
| int | second, | ||
| int | usec ) |
Bind a timestamp (date + time) parameter.
No timezone — treated as local time. Each driver converts to its native temporal format internally.
| stmt | A prepared statement. |
| idx | Parameter index (1-indexed). |
| year | Year (e.g. 2024). |
| month | Month (1–12). |
| day | Day (1–31). |
| hour | Hour (0–23). |
| minute | Minute (0–59). |
| second | Second (0–59). |
| usec | Microseconds (0–999999). |
| int kdbc_bind_date | ( | kdbc_stmt * | stmt, |
| int | idx, | ||
| int | year, | ||
| int | month, | ||
| int | day ) |
Bind a date-only parameter.
| stmt | A prepared statement. |
| idx | Parameter index (1-indexed). |
| year | Year. |
| month | Month (1–12). |
| day | Day (1–31). |
| int kdbc_bind_time | ( | kdbc_stmt * | stmt, |
| int | idx, | ||
| int | hour, | ||
| int | minute, | ||
| int | second, | ||
| int | usec ) |
Bind a time-only parameter.
| stmt | A prepared statement. |
| idx | Parameter index (1-indexed). |
| hour | Hour (0–23). |
| minute | Minute (0–59). |
| second | Second (0–59). |
| usec | Microseconds (0–999999). |