cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
sql.h File Reference

Database operations wrapper (SQLite3). More...

#include <sqlite3.h>
#include <cwist/err/cwist_err.h>
#include <cjson/cJSON.h>
Include dependency graph for sql.h:

Go to the source code of this file.

Classes

struct  cwist_db
 Wrapper for Database Operations. Currently uses SQLite3. More...
 

Typedefs

typedef struct cwist_db cwist_db
 

Functions

Lifecycle
cwist_error_t cwist_db_open (cwist_db **db, const char *path)
 Connect to a database (or open file).
 
void cwist_db_close (cwist_db *db)
 Close database connection.
 
Execution
cwist_error_t cwist_db_exec (cwist_db *db, const char *sql)
 Execute a command (INSERT, UPDATE, DELETE, CREATE). Does not return rows.
 
cwist_error_t cwist_db_query (cwist_db *db, const char *sql, cJSON **result)
 Execute a query and return results as a cJSON Array of Objects. Example: [{"id":1, "name":"foo"}, {"id":2, "name":"bar"}].
 

Detailed Description

Database operations wrapper (SQLite3).

Definition in file sql.h.

Typedef Documentation

◆ cwist_db

Function Documentation

◆ cwist_db_close()

void cwist_db_close ( cwist_db *  db)

Close database connection.

Close database connection.

Parameters
dbDatabase wrapper to close.

Definition at line 295 of file db.c.

◆ cwist_db_exec()

cwist_error_t cwist_db_exec ( cwist_db *  db,
const char *  sql 
)

Execute a command (INSERT, UPDATE, DELETE, CREATE). Does not return rows.

Execute a command (INSERT, UPDATE, DELETE, CREATE). Does not return rows.

Parameters
dbOpen database wrapper.
sqlSQL text to execute.
Returns
Tagged CWIST error describing success or failure.

Definition at line 312 of file db.c.

Referenced by cwist_db_insert_healed().

◆ cwist_db_open()

cwist_error_t cwist_db_open ( cwist_db **  db,
const char *  path 
)

Connect to a database (or open file).

Parameters
dbOut parameter for the database handle.
pathPath to SQLite file (or ":memory:").

Connect to a database (or open file).

Parameters
dbOutput pointer receiving the allocated database wrapper.
pathFilesystem path or SQLite URI to open.
Returns
Tagged CWIST error describing success or failure.

Definition at line 154 of file db.c.

◆ cwist_db_query()

cwist_error_t cwist_db_query ( cwist_db *  db,
const char *  sql,
cJSON **  result 
)

Execute a query and return results as a cJSON Array of Objects. Example: [{"id":1, "name":"foo"}, {"id":2, "name":"bar"}].

Execute a query and return results as a cJSON Array of Objects. Example: [{"id":1, "name":"foo"}, {"id":2, "name":"bar"}].

Parameters
dbOpen database wrapper.
sqlSQL text to execute.
resultOutput pointer receiving the cJSON row array.
Returns
Tagged CWIST error describing success or failure.

Definition at line 374 of file db.c.

Referenced by cwist_db_query_strict().