← 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
82
100
102#define KDBC_OK 0
104#define KDBC_ERROR (-1)
105 /* end of types */
107
108/* ========================================================================
109 * Driver Discovery
110 * ======================================================================== */
111
116
127
133const char *kdbc_driver_name(kdbc_driver driver);
134
145
157
168 /* end of discovery */
170
171/* ========================================================================
172 * Error Handling
173 * ======================================================================== */
174
188
194const char *kdbc_error(kdbc_conn *conn);
195
201const char *kdbc_stmt_error(kdbc_stmt *stmt);
202
212const char *kdbc_global_error(void);
213 /* end of errors */
215
216/* ========================================================================
217 * Connection Management
218 * ======================================================================== */
219
224
245kdbc_conn *kdbc_connect(kdbc_driver driver, const char *url,
246 const char *user, const char *password);
247
256
263
292 /* end of connection */
294
295/* ========================================================================
296 * Direct SQL Execution
297 * ======================================================================== */
298
303
314int kdbc_execute_update(kdbc_conn *conn, const char *sql);
315
326kdbc_result *kdbc_execute_query(kdbc_conn *conn, const char *sql);
327 /* end of direct */
329
330/* ========================================================================
331 * Transaction Control
332 * ======================================================================== */
333
364
371int kdbc_set_autocommit(kdbc_conn *conn, int enabled);
372
379
386
393int kdbc_savepoint(kdbc_conn *conn, const char *name);
394
401int kdbc_rollback_to(kdbc_conn *conn, const char *name);
402
413int kdbc_release_savepoint(kdbc_conn *conn, const char *name);
414 /* end of transactions */
416
417/* ========================================================================
418 * Database Metadata
419 * ======================================================================== */
420
427
433const char *kdbc_product_name(kdbc_conn *conn);
434
441
448
455 /* end of metadata */
457
458/* ========================================================================
459 * Prepared Statements and Parameter Binding
460 * ======================================================================== */
461
481
489kdbc_stmt *kdbc_prepare(kdbc_conn *conn, const char *sql);
490
509 const char **col_names, int n_cols);
510
517int kdbc_bind_null(kdbc_stmt *stmt, int idx);
518
526int kdbc_bind_int(kdbc_stmt *stmt, int idx, int val);
527
539int kdbc_bind_bool(kdbc_stmt *stmt, int idx, int val);
540
548int kdbc_bind_long(kdbc_stmt *stmt, int idx, int64_t val);
549
557int kdbc_bind_double(kdbc_stmt *stmt, int idx, double val);
558
569int kdbc_bind_string(kdbc_stmt *stmt, int idx, const char *val);
570
582int kdbc_bind_blob(kdbc_stmt *stmt, int idx, const void *data, size_t len);
583
602 int year, int month, int day,
603 int hour, int minute, int second, int usec);
604
614int kdbc_bind_date(kdbc_stmt *stmt, int idx,
615 int year, int month, int day);
616
627int kdbc_bind_time(kdbc_stmt *stmt, int idx,
628 int hour, int minute, int second, int usec);
629 /* end of statements */
631
632/* ========================================================================
633 * Statement Execution
634 * ======================================================================== */
635
640
647
657
681
690
705
716int kdbc_set_fetch_size(kdbc_stmt *stmt, int rows);
717 /* end of execution */
719
720/* ========================================================================
721 * Batch Execution
722 * ======================================================================== */
723
738
749
756 /* end of batch */
758
759/* ========================================================================
760 * Callable Statements (Stored Procedures)
761 * ======================================================================== */
762
779
787kdbc_stmt *kdbc_prepare_call(kdbc_conn *conn, const char *sql);
788
798int kdbc_register_out(kdbc_stmt *stmt, int idx);
799
806
813int64_t kdbc_call_get_long(kdbc_stmt *stmt, int idx);
814
821const char *kdbc_call_get_string(kdbc_stmt *stmt, int idx);
822 /* end of callable */
824
825/* ========================================================================
826 * Result Set
827 * ======================================================================== */
828
847
854
861
868const char *kdbc_col_name(kdbc_result *rs, int col);
869
879const char *kdbc_col_label(kdbc_result *rs, int col);
880
891int kdbc_is_null(kdbc_result *rs, int col);
892
903int64_t kdbc_get_long(kdbc_result *rs, int col);
904
914double kdbc_get_double(kdbc_result *rs, int col);
915
926const char *kdbc_get_string(kdbc_result *rs, int col);
927
939const void *kdbc_get_blob(kdbc_result *rs, int col, size_t *out_len);
940
956 int *year, int *month, int *day,
957 int *hour, int *minute, int *second, int *usec);
958
968int kdbc_get_date(kdbc_result *rs, int col,
969 int *year, int *month, int *day);
970
981int kdbc_get_time(kdbc_result *rs, int col,
982 int *hour, int *minute, int *second, int *usec);
983
992 /* end of resultset */
994
995#ifdef __cplusplus
996}
997#endif
998
999#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.
const char * kdbc_global_error(void)
Get the last global (connection-less) error message.
const char * kdbc_stmt_error(kdbc_stmt *stmt)
Get the last error message for a statement.
const char * kdbc_error(kdbc_conn *conn)
Get the last error message for a connection.
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.
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_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:95
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:96
@ KDBC_GK_BY_INDEX
Definition kdbc.h:97
@ KDBC_GK_BY_NAME
Definition kdbc.h:98
@ 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_INT
Definition kdbc.h:72
@ KDBC_TYPE_STRING
Definition kdbc.h:75