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

Functions

const char * kdbc_error (kdbc_conn *conn)
 Get the last error message for a connection.
const char * kdbc_stmt_error (kdbc_stmt *stmt)
 Get the last error message for a statement.
const char * kdbc_global_error (void)
 Get the last global (connection-less) error message.
const char * kdbc_sqlstate (kdbc_conn *conn)
 Get the SQLSTATE code for the last connection error.
int kdbc_errcode (kdbc_conn *conn)
 Get the vendor-specific error code for the last connection error.
const char * kdbc_stmt_sqlstate (kdbc_stmt *stmt)
 Get the SQLSTATE code for the last statement error.
int kdbc_stmt_errcode (kdbc_stmt *stmt)
 Get the vendor-specific error code for the last statement error.
const char * kdbc_global_sqlstate (void)
 Get the SQLSTATE code for the last connection-less (global) error.
int kdbc_global_errcode (void)
 Get the vendor-specific error code for the last connection-less error.
const char * kdbc_result_error (kdbc_result *rs)
 Get the last error message for a result set.
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.

Detailed Description

Retrieve error messages from connections, statements, or global context.

Each handle (kdbc_conn, kdbc_stmt) maintains its own error buffer (1024 bytes). The global error buffer is thread-local, used for errors that occur outside a connection context (e.g. driver not available, connection failure).

Returned pointers are valid until the next KDBC call on the same handle, or until the handle is closed. Returns "" (empty string) when no error has occurred.

Function Documentation

◆ kdbc_error()

const char * kdbc_error ( kdbc_conn * conn)

Get the last error message for a connection.

Parameters
connThe connection to query.
Returns
The error message, or "" if no error.

◆ kdbc_stmt_error()

const char * kdbc_stmt_error ( kdbc_stmt * stmt)

Get the last error message for a statement.

Parameters
stmtThe statement to query.
Returns
The error message, or "" if no error.

◆ kdbc_global_error()

const char * kdbc_global_error ( void )

Get the last global (connection-less) error message.

Used for errors that occur before a connection exists, such as driver-not-available or connection failure. Thread-local — safe to call from any thread.

Returns
The error message, or "" if no error.

◆ kdbc_sqlstate()

const char * kdbc_sqlstate ( kdbc_conn * conn)

Get the SQLSTATE code for the last connection error.

SQLSTATE is the 5-character standard code defined by SQL-92 and reported by drivers that support it (PostgreSQL, MariaDB/MySQL, Oracle). Drivers that do not surface SQLSTATE (SQLite, MS SQL Server via db-lib) leave the field empty. The pointer is owned by the connection and remains valid until the next KDBC call on it.

Parameters
connThe connection to query.
Returns
The SQLSTATE code, or "" if none.

◆ kdbc_errcode()

int kdbc_errcode ( kdbc_conn * conn)

Get the vendor-specific error code for the last connection error.

The semantics depend on the driver: SQLite returns the extended result code, MariaDB/MySQL returns mysql_errno, Oracle returns the ORA number, MS SQL Server returns the message number. PostgreSQL and other drivers that only carry SQLSTATE return 0.

Parameters
connThe connection to query.
Returns
The vendor error code, or 0 if none.

◆ kdbc_stmt_sqlstate()

const char * kdbc_stmt_sqlstate ( kdbc_stmt * stmt)

Get the SQLSTATE code for the last statement error.

Parameters
stmtThe statement to query.
Returns
The SQLSTATE code, or "" if none. See [kdbc_sqlstate] for semantics.

◆ kdbc_stmt_errcode()

int kdbc_stmt_errcode ( kdbc_stmt * stmt)

Get the vendor-specific error code for the last statement error.

Parameters
stmtThe statement to query.
Returns
The vendor error code, or 0 if none. See [kdbc_errcode] for semantics.

◆ kdbc_global_sqlstate()

const char * kdbc_global_sqlstate ( void )

Get the SQLSTATE code for the last connection-less (global) error.

Thread-local — safe to call from any thread.

Returns
The SQLSTATE code, or "" if none.

◆ kdbc_global_errcode()

int kdbc_global_errcode ( void )

Get the vendor-specific error code for the last connection-less error.

Thread-local — safe to call from any thread.

Returns
The vendor error code, or 0 if none.

◆ kdbc_result_error()

const char * kdbc_result_error ( kdbc_result * rs)

Get the last error message for a result set.

Parameters
rsThe result set to query.
Returns
The error message, or "" if no error.

◆ kdbc_result_sqlstate()

const char * kdbc_result_sqlstate ( kdbc_result * rs)

Get the SQLSTATE code for the last result-set error.

Parameters
rsThe result set to query.
Returns
The SQLSTATE code, or "" if none. See [kdbc_sqlstate] for semantics.

◆ kdbc_result_errcode()

int kdbc_result_errcode ( kdbc_result * rs)

Get the vendor-specific error code for the last result-set error.

Parameters
rsThe result set to query.
Returns
The vendor error code, or 0 if none. See [kdbc_errcode] for semantics.