sql-api.h revision 2cfe9983ce7a6280636ee12beccc2e865111967b
#ifndef __SQL_API_H
#define __SQL_API_H
/* This SQL API is designed to work asynchronously. The underlying drivers
however may not. */
enum sql_db_flags {
/* Set if queries are not executed asynchronously */
SQL_DB_FLAG_BLOCKING = 0x01
};
struct sql_db;
struct sql_result;
void sql_drivers_init(void);
void sql_drivers_deinit(void);
/* register all built-in SQL drivers */
void sql_drivers_register_all(void);
/* Initialize database connections. db_driver is the database driver name,
eg. "mysql" or "pgsql". connect_string is driver-specific. */
/* Returns SQL database state flags. */
/* Explicitly connect to the database. It's not required to call this function
though. Returns -1 if we're not connected, 0 if we started connecting or
1 if we are fully connected now. */
/* Escape the given string if needed and return it. */
/* Execute SQL query without waiting for results. */
/* Execute SQL query and return result in callback. */
#ifdef CONTEXT_TYPE_SAFETY
#else
#endif
/* Execute blocking SQL query and return result. */
/* Go to next row, returns 1 if ok, 0 if this was the last row or -1 if error
occurred. This needs to be the first call for result. */
/* Needs to be called only with sql_query_s(). */
/* Return number of fields in result. */
/* Return name of the given field index. */
unsigned int idx);
/* Return field index for given name, or -1 if not found. */
/* Returns value of given field as string. */
unsigned int idx);
const char *field_name);
/* Return all values of current row. */
/* Return last error message in result. */
/* Begin a new transaction. Currently you're limited to only one open
transaction at a time. */
/* Commit transaction. */
#ifdef CONTEXT_TYPE_SAFETY
#else
#endif
/* Synchronous commit. Returns 0 if ok, -1 if error. */
const char **error_r);
/* Execute query in given transaction. */
#endif