Csilk 0.2.1
A lightweight, high-performance C HTTP web framework
Loading...
Searching...
No Matches
csilk_db_driver_t Struct Reference

Virtual function table implemented by each database driver. More...

#include <db.h>

Data Fields

const char * name
 
int(* connect )(csilk_db_pool_t *pool, const char *dsn)
 Open a connection to the database.
 
int(* disconnect )(csilk_db_pool_t *pool)
 Close the database connection.
 
int(* query )(csilk_db_pool_t *pool, const char *sql, csilk_db_result_t *result)
 Execute a SELECT query and produce a result set.
 
int(* exec )(csilk_db_pool_t *pool, const char *sql)
 Execute a statement that returns no result rows.
 
int(* transaction_begin )(csilk_db_pool_t *pool)
 Begin a database transaction.
 
int(* transaction_commit )(csilk_db_pool_t *pool)
 Commit the current transaction.
 
int(* transaction_rollback )(csilk_db_pool_t *pool)
 Roll back the current transaction.
 
void(* free_result )(csilk_db_result_t *result)
 Free a result set and all associated memory.
 

Detailed Description

Virtual function table implemented by each database driver.

Opaque database driver interface.

All function pointers must be non-NULL except where noted.

Each supported database backend implements the function table in csilk_db_driver_s and registers itself with csilk_db_register_driver.

Field Documentation

◆ connect

int(* csilk_db_driver_t::connect) (csilk_db_pool_t *pool, const char *dsn)

Open a connection to the database.

Parameters
poolPool whose connection field should be populated.
dsnDriver-specific data source name.
Returns
0 on success, -1 on failure.

◆ disconnect

int(* csilk_db_driver_t::disconnect) (csilk_db_pool_t *pool)

Close the database connection.

Parameters
poolPool whose connection should be closed and freed.
Returns
0 on success, -1 on failure.

◆ exec

int(* csilk_db_driver_t::exec) (csilk_db_pool_t *pool, const char *sql)

Execute a statement that returns no result rows.

Parameters
poolConnection pool (mutex is held by the caller).
sqlSQL statement (INSERT, UPDATE, DELETE, DDL, etc.).
Returns
0 on success, -1 on failure.

◆ free_result

void(* csilk_db_driver_t::free_result) (csilk_db_result_t *result)

Free a result set and all associated memory.

Parameters
resultResult set to free (must not be NULL).

◆ name

const char* csilk_db_driver_t::name

Driver identifier string (e.g., "sqlite", "postgres"). Matches the name passed to csilk_db_pool_new.

◆ query

int(* csilk_db_driver_t::query) (csilk_db_pool_t *pool, const char *sql, csilk_db_result_t *result)

Execute a SELECT query and produce a result set.

Parameters
poolConnection pool (mutex is held by the caller).
sqlSQL query string.
[out]resultCaller-allocated csilk_db_result_t to populate. Set to zero-initialised (the driver allocates rows + strings internally).
Returns
0 on success, -1 on failure.

◆ transaction_begin

int(* csilk_db_driver_t::transaction_begin) (csilk_db_pool_t *pool)

Begin a database transaction.

Parameters
poolConnection pool (mutex is held by the caller).
Returns
0 on success, -1 on failure.

◆ transaction_commit

int(* csilk_db_driver_t::transaction_commit) (csilk_db_pool_t *pool)

Commit the current transaction.

Parameters
poolConnection pool (mutex is held by the caller).
Returns
0 on success, -1 on failure.

◆ transaction_rollback

int(* csilk_db_driver_t::transaction_rollback) (csilk_db_pool_t *pool)

Roll back the current transaction.

Parameters
poolConnection pool (mutex is held by the caller).
Returns
0 on success, -1 on failure.

The documentation for this struct was generated from the following file: