|
Csilk 0.2.1
A lightweight, high-performance C HTTP web framework
|
SQLite3 database driver for csilk. More...
#include <sqlite3.h>#include <stdlib.h>#include <string.h>#include "csilk/csilk.h"#include "csilk/drivers/db.h"
Data Structures | |
| struct | sqlite_conn_t |
| Per-connection data for the SQLite driver. More... | |
Functions | |
| static int | sqlite_connect (csilk_db_pool_t *pool, const char *dsn) |
| Open a connection to a SQLite database file. | |
| static int | sqlite_disconnect (csilk_db_pool_t *pool) |
| Close a SQLite connection and free the pool's connection data. | |
| static void | sqlite_free_result (csilk_db_result_t *result) |
| Free all memory associated with a query result set. | |
| static int | sqlite_query (csilk_db_pool_t *pool, const char *sql, csilk_db_result_t *result) |
| Execute a SQL query and return the full result set. | |
| static int | sqlite_exec (csilk_db_pool_t *pool, const char *sql) |
| Execute a SQL statement that returns no result rows. | |
| static int | sqlite_transaction_begin (csilk_db_pool_t *pool) |
| Begin a SQLite transaction (delegates to sqlite_exec). | |
| static int | sqlite_transaction_commit (csilk_db_pool_t *pool) |
| Commit the current SQLite transaction. | |
| static int | sqlite_transaction_rollback (csilk_db_pool_t *pool) |
| Rollback the current SQLite transaction. | |
| void | csilk_db_sqlite_init (void) |
| Initialize and register the SQLite database driver with csilk. | |
Variables | |
| csilk_db_driver_t | csilk_db_sqlite_driver |
| Pre-built driver vtable for the SQLite3 database backend. | |
SQLite3 database driver for csilk.
Implements the csilk_db_driver_t vtable using the native sqlite3 C API. Key design points:
| void csilk_db_sqlite_init | ( | void | ) |
Initialize and register the SQLite database driver with csilk.
Internal: Register the built-in SQLite3 driver.
Call this at startup (e.g., in the app init callback) to make the "sqlite" driver available for csilk_db_create() calls.
|
static |
Open a connection to a SQLite database file.
Uses sqlite3_open_v2 with read/write+create flags. Stores the connection handle in the pool. On failure, frees the allocated connection and returns an error.
| pool | The database pool to initialize. |
| dsn | Filesystem path to the SQLite database file. |
|
static |
Close a SQLite connection and free the pool's connection data.
Calls sqlite3_close() on the underlying handle, frees the connection struct, and sets pool->connection to NULL.
| pool | The database pool to shut down. |
|
static |
Execute a SQL statement that returns no result rows.
Uses sqlite3_exec() for DDL/INSERT/UPDATE/DELETE statements.
| pool | The database pool (must be connected). |
| sql | SQL statement string. |
Execute a SQL statement that returns no result rows.
Uses sqlite3_exec with no callback for DDL/INSERT/UPDATE/DELETE. The callback-free invocation discards any output rows silently. On error, the error message from sqlite3_errmsg is freed after logging.
|
static |
Free all memory associated with a query result set.
Iterates rows, column names, and the top-level arrays, freeing each allocation. Resets row_count and column_count to 0 after cleanup.
| result | The result set to free (may be NULL). |
|
static |
Execute a SQL query and return the full result set.
Prepares the statement, retrieves column names, then steps through all rows, allocating each row's values array. On any allocation failure, partial results are freed and -1 is returned.
| pool | The database pool (must be connected). |
| sql | SQL query string. |
| result | [out] Populated result set (must be freed with sqlite_free_result). |
Execute a SELECT query and buffer the full result set.
Flow:
|
static |
Begin a SQLite transaction (delegates to sqlite_exec).
| pool | The database pool. |
|
static |
Commit the current SQLite transaction.
| pool | The database pool. |
|
static |
Rollback the current SQLite transaction.
| pool | The database pool. |
| csilk_db_driver_t csilk_db_sqlite_driver |
Pre-built driver vtable for the SQLite3 database backend.
Registered automatically when csilk_db_sqlite_init() is called. Users can also reference this struct directly to register manually.