← Back to Stormify Documentation
KDBC
Unified C Database Connectivity — SQLite, PostgreSQL, MariaDB, Oracle, MSSQL
Loading...
Searching...
No Matches
kdbc.h
Go to the documentation of this file.
1
21#ifndef KDBC_H
22#define KDBC_H
23
24#include <stddef.h>
25#include <stdint.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/* ========================================================================
32 * Types and Constants
33 * ======================================================================== */
34
39
41typedef struct kdbc_conn kdbc_conn;
42
44typedef struct kdbc_stmt kdbc_stmt;
45
47typedef struct kdbc_result kdbc_result;
48
64
83
101
103#define KDBC_OK 0
105#define KDBC_ERROR (-1)
106 /* end of types */
108
109/* ========================================================================
110 * Driver Discovery
111 * ======================================================================== */
112
117
128
134const char *kdbc_driver_name(kdbc_driver driver);
135
146
158
169 /* end of discovery */
171
172/* ========================================================================
173 * Error Handling
174 * ======================================================================== */
175
189
195const char *kdbc_error(kdbc_conn *conn);
196
202const char *kdbc_stmt_error(kdbc_stmt *stmt);
203
213const char *kdbc_global_error(void);
214
227const char *kdbc_sqlstate(kdbc_conn *conn);
228
241
247const char *kdbc_stmt_sqlstate(kdbc_stmt *stmt);
248
255
263const char *kdbc_global_sqlstate(void);
264
273
280
287
294 /* end of errors */
296
297/* ========================================================================
298 * Connection Management
299 * ======================================================================== */
300
305
326kdbc_conn *kdbc_connect(kdbc_driver driver, const char *url,
327 const char *user, const char *password);
328
337
344
373 /* end of connection */
375
376/* ========================================================================
377 * Direct SQL Execution
378 * ======================================================================== */
379
384
395int kdbc_execute_update(kdbc_conn *conn, const char *sql);
396
407kdbc_result *kdbc_execute_query(kdbc_conn *conn, const char *sql);
408 /* end of direct */
410
411/* ========================================================================
412 * Transaction Control
413 * ======================================================================== */
414
445
452int kdbc_set_autocommit(kdbc_conn *conn, int enabled);
453
465
472
479
486int kdbc_savepoint(kdbc_conn *conn, const char *name);
487
494int kdbc_rollback_to(kdbc_conn *conn, const char *name);
495
506int kdbc_release_savepoint(kdbc_conn *conn, const char *name);
507 /* end of transactions */
509
510/* ========================================================================
511 * Database Metadata
512 * ======================================================================== */
513
520
526const char *kdbc_product_name(kdbc_conn *conn);
527
534
541
548 /* end of metadata */
550
551/* ========================================================================
552 * Prepared Statements and Parameter Binding
553 * ======================================================================== */
554
574
582kdbc_stmt *kdbc_prepare(kdbc_conn *conn, const char *sql);
583
602 const char **col_names, int n_cols);
603
610int kdbc_bind_null(kdbc_stmt *stmt, int idx);
611
619int kdbc_bind_int(kdbc_stmt *stmt, int idx, int val);
620
632int kdbc_bind_bool(kdbc_stmt *stmt, int idx, int val);
633
641int kdbc_bind_long(kdbc_stmt *stmt, int idx, int64_t val);
642
650int kdbc_bind_double(kdbc_stmt *stmt, int idx, double val);
651
662int kdbc_bind_string(kdbc_stmt *stmt, int idx, const char *val);
663
675int kdbc_bind_blob(kdbc_stmt *stmt, int idx, const void *data, size_t len);
676
695 int year, int month, int day,
696 int hour, int minute, int second, int usec);
697
707int kdbc_bind_date(kdbc_stmt *stmt, int idx,
708 int year, int month, int day);
709
720int kdbc_bind_time(kdbc_stmt *stmt, int idx,
721 int hour, int minute, int second, int usec);
722 /* end of statements */
724
725/* ========================================================================
726 * Statement Execution
727 * ======================================================================== */
728
733
740
750
774
783
798
809int kdbc_set_fetch_size(kdbc_stmt *stmt, int rows);
810 /* end of execution */
812
813/* ========================================================================
814 * Batch Execution
815 * ======================================================================== */
816
831
842
849 /* end of batch */
851
852/* ========================================================================
853 * Callable Statements (Stored Procedures)
854 * ======================================================================== */
855
872
880kdbc_stmt *kdbc_prepare_call(kdbc_conn *conn, const char *sql);
881
891int kdbc_register_out(kdbc_stmt *stmt, int idx);
892
899
906int64_t kdbc_call_get_long(kdbc_stmt *stmt, int idx);
907
914const char *kdbc_call_get_string(kdbc_stmt *stmt, int idx);
915 /* end of callable */
917
918/* ========================================================================
919 * Result Set
920 * ======================================================================== */
921
940
947
954
961const char *kdbc_col_name(kdbc_result *rs, int col);
962
972const char *kdbc_col_label(kdbc_result *rs, int col);
973
991
1002int kdbc_is_null(kdbc_result *rs, int col);
1003
1014int64_t kdbc_get_long(kdbc_result *rs, int col);
1015
1025double kdbc_get_double(kdbc_result *rs, int col);
1026
1037const char *kdbc_get_string(kdbc_result *rs, int col);
1038
1050const void *kdbc_get_blob(kdbc_result *rs, int col, size_t *out_len);
1051
1067 int *year, int *month, int *day,
1068 int *hour, int *minute, int *second, int *usec);
1069
1080 int *year, int *month, int *day);
1081
1093 int *hour, int *minute, int *second, int *usec);
1094
1103 /* end of resultset */
1105
1106#ifdef __cplusplus
1107}
1108#endif
1109
1110#endif /* KDBC_H */
int kdbc_add_batch(kdbc_stmt *stmt)
Add current parameters as a batch entry.
int kdbc_execute_batch(kdbc_stmt *stmt)
Execute all batched parameter sets.
kdbc_stmt * kdbc_prepare_call(kdbc_conn *conn, const char *sql)
Prepare a stored procedure call.
int kdbc_register_out(kdbc_stmt *stmt, int idx)
Register a parameter as OUT.
int kdbc_call_execute(kdbc_stmt *stmt)
Execute a callable statement.
int64_t kdbc_call_get_long(kdbc_stmt *stmt, int idx)
Retrieve an OUT parameter as a 64-bit integer.
const char * kdbc_call_get_string(kdbc_stmt *stmt, int idx)
Retrieve an OUT parameter as a string.
kdbc_driver kdbc_conn_driver(kdbc_conn *conn)
Get the driver type of a connection.
void kdbc_close(kdbc_conn *conn)
Close a connection and free all associated resources.
int kdbc_cancel(kdbc_conn *conn)
Cancel a running statement from another thread.
kdbc_conn * kdbc_connect(kdbc_driver driver, const char *url, const char *user, const char *password)
Open a database connection.
int kdbc_execute_update(kdbc_conn *conn, const char *sql)
Execute a non-parameterized DML/DDL statement directly.
kdbc_result * kdbc_execute_query(kdbc_conn *conn, const char *sql)
Execute a non-parameterized SELECT directly.
kdbc_gk_strategy kdbc_driver_gk_strategy(kdbc_driver driver)
Get the default generated-key strategy for a driver.
int kdbc_driver_available(kdbc_driver driver)
Check if a driver's native library is available on this system.
kdbc_gk_strategy kdbc_conn_gk_strategy(kdbc_conn *conn)
Get the generated-key strategy for an open connection.
int kdbc_driver_supports_release_savepoint(kdbc_driver driver)
Check if a driver supports RELEASE SAVEPOINT.
const char * kdbc_driver_name(kdbc_driver driver)
Get the human-readable name of a driver.
int kdbc_stmt_errcode(kdbc_stmt *stmt)
Get the vendor-specific error code for the last statement error.
const char * kdbc_global_error(void)
Get the last global (connection-less) error message.
const char * kdbc_result_error(kdbc_result *rs)
Get the last error message for a result set.
const char * kdbc_stmt_sqlstate(kdbc_stmt *stmt)
Get the SQLSTATE code for the last statement error.
int kdbc_errcode(kdbc_conn *conn)
Get the vendor-specific error code for the last connection error.
const char * kdbc_result_sqlstate(kdbc_result *rs)
Get the SQLSTATE code for the last result-set error.
int kdbc_result_errcode(kdbc_result *rs)
Get the vendor-specific error code for the last result-set error.
int kdbc_global_errcode(void)
Get the vendor-specific error code for the last connection-less error.
const char * kdbc_stmt_error(kdbc_stmt *stmt)
Get the last error message for a statement.
const char * kdbc_global_sqlstate(void)
Get the SQLSTATE code for the last connection-less (global) error.
const char * kdbc_error(kdbc_conn *conn)
Get the last error message for a connection.
const char * kdbc_sqlstate(kdbc_conn *conn)
Get the SQLSTATE code for the last connection error.
int kdbc_stmt_reset(kdbc_stmt *stmt)
Reset a prepared statement for re-execution.
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_execute_query_stmt(kdbc_stmt *stmt)
Execute a prepared query (SELECT).
int kdbc_set_fetch_size(kdbc_stmt *stmt, int rows)
Set a fetch size hint for query execution.
kdbc_result * kdbc_generated_keys(kdbc_stmt *stmt)
Get generated keys after an INSERT.
int kdbc_minor_version(kdbc_conn *conn)
Get the minor version number.
const char * kdbc_product_name(kdbc_conn *conn)
Get the database product name (e.g. "SQLite", "PostgreSQL").
int kdbc_major_version(kdbc_conn *conn)
Get the major version number.
const char * kdbc_product_version(kdbc_conn *conn)
Get the full database version string.
int kdbc_get_timestamp(kdbc_result *rs, int col, int *year, int *month, int *day, int *hour, int *minute, int *second, int *usec)
Get a column value as a timestamp (date + time).
double kdbc_get_double(kdbc_result *rs, int col)
Get a column value as a double.
int kdbc_next(kdbc_result *rs)
Advance to the next row.
const char * kdbc_col_name(kdbc_result *rs, int col)
Get a column name by index.
kdbc_type kdbc_col_type(kdbc_result *rs, int col)
Get the type of a column value in the current row.
void kdbc_result_close(kdbc_result *rs)
Close a result set and free resources.
int kdbc_get_date(kdbc_result *rs, int col, int *year, int *month, int *day)
Get a column value as a date (no time component).
const char * kdbc_col_label(kdbc_result *rs, int col)
Get a column label (alias) by index.
int64_t kdbc_get_long(kdbc_result *rs, int col)
Get a column value as a 64-bit integer.
int kdbc_get_time(kdbc_result *rs, int col, int *hour, int *minute, int *second, int *usec)
Get a column value as a time (no date component).
const char * kdbc_get_string(kdbc_result *rs, int col)
Get a column value as a UTF-8 string.
int kdbc_col_count(kdbc_result *rs)
Get the number of columns in the result set.
int kdbc_is_null(kdbc_result *rs, int col)
Check if a column value is NULL.
const void * kdbc_get_blob(kdbc_result *rs, int col, size_t *out_len)
Get a column value as a binary blob.
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_bool(kdbc_stmt *stmt, int idx, int val)
Bind a boolean parameter.
int kdbc_bind_double(kdbc_stmt *stmt, int idx, double val)
Bind a double-precision float parameter.
kdbc_stmt * kdbc_prepare(kdbc_conn *conn, const char *sql)
Prepare a SQL statement.
int kdbc_bind_long(kdbc_stmt *stmt, int idx, int64_t val)
Bind a 64-bit integer parameter.
int kdbc_bind_time(kdbc_stmt *stmt, int idx, int hour, int minute, int second, int usec)
Bind a time-only parameter.
int kdbc_bind_blob(kdbc_stmt *stmt, int idx, const void *data, size_t len)
Bind a binary blob parameter.
int kdbc_bind_date(kdbc_stmt *stmt, int idx, int year, int month, int day)
Bind a date-only parameter.
int kdbc_bind_int(kdbc_stmt *stmt, int idx, int val)
Bind a 32-bit integer parameter.
int kdbc_bind_string(kdbc_stmt *stmt, int idx, const char *val)
Bind a UTF-8 string parameter.
int kdbc_bind_null(kdbc_stmt *stmt, int idx)
Bind a NULL value to a 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.
int kdbc_release_savepoint(kdbc_conn *conn, const char *name)
Release a savepoint.
int kdbc_get_autocommit(kdbc_conn *conn)
Read the current auto-commit state.
int kdbc_savepoint(kdbc_conn *conn, const char *name)
Create a savepoint.
int kdbc_set_autocommit(kdbc_conn *conn, int enabled)
Enable or disable autocommit.
int kdbc_rollback(kdbc_conn *conn)
Roll back the current transaction.
int kdbc_commit(kdbc_conn *conn)
Commit the current transaction.
int kdbc_rollback_to(kdbc_conn *conn, const char *name)
Roll back to a savepoint.
kdbc_driver
Supported database drivers.
Definition kdbc.h:56
struct kdbc_conn kdbc_conn
Opaque database connection handle.
Definition kdbc.h:41
kdbc_gk_strategy
Generated-key retrieval strategies.
Definition kdbc.h:96
struct kdbc_result kdbc_result
Opaque result set handle.
Definition kdbc.h:47
kdbc_type
Column / parameter value types.
Definition kdbc.h:70
struct kdbc_stmt kdbc_stmt
Opaque prepared statement handle.
Definition kdbc.h:44
@ KDBC_ORACLE
Definition kdbc.h:60
@ KDBC_DRIVER_COUNT
Definition kdbc.h:62
@ KDBC_POSTGRES
Definition kdbc.h:58
@ KDBC_SQLITE
Definition kdbc.h:57
@ KDBC_MSSQL
Definition kdbc.h:61
@ KDBC_MARIADB
Definition kdbc.h:59
@ KDBC_GK_NONE
Definition kdbc.h:97
@ KDBC_GK_BY_INDEX
Definition kdbc.h:98
@ KDBC_GK_BY_NAME
Definition kdbc.h:99
@ KDBC_TYPE_TIME
Definition kdbc.h:79
@ KDBC_TYPE_DATE
Definition kdbc.h:78
@ KDBC_TYPE_TIMESTAMP
Definition kdbc.h:80
@ KDBC_TYPE_DOUBLE
Definition kdbc.h:74
@ KDBC_TYPE_LONG
Definition kdbc.h:73
@ KDBC_TYPE_BOOL
Definition kdbc.h:77
@ KDBC_TYPE_BLOB
Definition kdbc.h:76
@ KDBC_TYPE_NULL
Definition kdbc.h:71
@ KDBC_TYPE_DECIMAL
Definition kdbc.h:81
@ KDBC_TYPE_INT
Definition kdbc.h:72
@ KDBC_TYPE_STRING
Definition kdbc.h:75