← 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
226const char *kdbc_sqlstate(kdbc_conn *conn);
227
240
246const char *kdbc_stmt_sqlstate(kdbc_stmt *stmt);
247
254
262const char *kdbc_global_sqlstate(void);
263
272
279
286
293 /* end of errors */
295
296/* ========================================================================
297 * Connection Management
298 * ======================================================================== */
299
304
325kdbc_conn *kdbc_connect(kdbc_driver driver, const char *url,
326 const char *user, const char *password);
327
336
343
372 /* end of connection */
374
375/* ========================================================================
376 * Direct SQL Execution
377 * ======================================================================== */
378
383
394int kdbc_execute_update(kdbc_conn *conn, const char *sql);
395
406kdbc_result *kdbc_execute_query(kdbc_conn *conn, const char *sql);
407 /* end of direct */
409
410/* ========================================================================
411 * Transaction Control
412 * ======================================================================== */
413
444
451int kdbc_set_autocommit(kdbc_conn *conn, int enabled);
452
464
471
478
485int kdbc_savepoint(kdbc_conn *conn, const char *name);
486
493int kdbc_rollback_to(kdbc_conn *conn, const char *name);
494
505int kdbc_release_savepoint(kdbc_conn *conn, const char *name);
506 /* end of transactions */
508
509/* ========================================================================
510 * Database Metadata
511 * ======================================================================== */
512
519
525const char *kdbc_product_name(kdbc_conn *conn);
526
533
540
547 /* end of metadata */
549
550/* ========================================================================
551 * Prepared Statements and Parameter Binding
552 * ======================================================================== */
553
573
581kdbc_stmt *kdbc_prepare(kdbc_conn *conn, const char *sql);
582
601 const char **col_names, int n_cols);
602
609int kdbc_bind_null(kdbc_stmt *stmt, int idx);
610
618int kdbc_bind_int(kdbc_stmt *stmt, int idx, int val);
619
631int kdbc_bind_bool(kdbc_stmt *stmt, int idx, int val);
632
640int kdbc_bind_long(kdbc_stmt *stmt, int idx, int64_t val);
641
649int kdbc_bind_double(kdbc_stmt *stmt, int idx, double val);
650
661int kdbc_bind_string(kdbc_stmt *stmt, int idx, const char *val);
662
674int kdbc_bind_blob(kdbc_stmt *stmt, int idx, const void *data, size_t len);
675
694 int year, int month, int day,
695 int hour, int minute, int second, int usec);
696
706int kdbc_bind_date(kdbc_stmt *stmt, int idx,
707 int year, int month, int day);
708
719int kdbc_bind_time(kdbc_stmt *stmt, int idx,
720 int hour, int minute, int second, int usec);
721 /* end of statements */
723
724/* ========================================================================
725 * Statement Execution
726 * ======================================================================== */
727
732
739
749
773
782
797
808int kdbc_set_fetch_size(kdbc_stmt *stmt, int rows);
809 /* end of execution */
811
812/* ========================================================================
813 * Batch Execution
814 * ======================================================================== */
815
830
841
848 /* end of batch */
850
851/* ========================================================================
852 * Callable Statements (Stored Procedures)
853 * ======================================================================== */
854
871
879kdbc_stmt *kdbc_prepare_call(kdbc_conn *conn, const char *sql);
880
890int kdbc_register_out(kdbc_stmt *stmt, int idx);
891
898
905int64_t kdbc_call_get_long(kdbc_stmt *stmt, int idx);
906
913const char *kdbc_call_get_string(kdbc_stmt *stmt, int idx);
914 /* end of callable */
916
917/* ========================================================================
918 * Result Set
919 * ======================================================================== */
920
939
946
953
960const char *kdbc_col_name(kdbc_result *rs, int col);
961
971const char *kdbc_col_label(kdbc_result *rs, int col);
972
983int kdbc_is_null(kdbc_result *rs, int col);
984
995int64_t kdbc_get_long(kdbc_result *rs, int col);
996
1006double kdbc_get_double(kdbc_result *rs, int col);
1007
1018const char *kdbc_get_string(kdbc_result *rs, int col);
1019
1031const void *kdbc_get_blob(kdbc_result *rs, int col, size_t *out_len);
1032
1048 int *year, int *month, int *day,
1049 int *hour, int *minute, int *second, int *usec);
1050
1061 int *year, int *month, int *day);
1062
1074 int *hour, int *minute, int *second, int *usec);
1075
1084 /* end of resultset */
1086
1087#ifdef __cplusplus
1088}
1089#endif
1090
1091#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.
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: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