#ifndef SQL_API_H
#define SQL_API_H
struct timespec;
/* 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 */
/* Set if database wants to use connection pooling */
/* Prepared statements are supported by the database. If they aren't,
the functions can still be used, but they're just internally
convered into regular statements. */
};
enum sql_field_type {
};
struct sql_field_def {
const char *name;
};
enum sql_result_error_type {
/* It's unknown whether write succeeded or not. This could be due to
a timeout or a disconnection from server. */
};
enum sql_result_next {
/* Row was returned */
/* There are no more rows */
SQL_RESULT_NEXT_LAST = 0,
/* Error occurred - see sql_result_get_error*() */
/* There are more results - call sql_result_more() */
};
struct sql_db;
struct sql_result;
struct sql_commit_result {
const char *error;
};
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. */
/* Explicitly disconnect from database and abort pending auth requests. */
/* Escape the given string if needed and return it. */
/* Escape the given data as a string. */
/* Execute SQL query without waiting for results. */
/* Execute SQL query and return result in callback. If fields list is given,
the returned fields are validated to be of correct type, and you can use
sql_result_next_row_get() */
CALLBACK_TYPECHECK(callback, void (*)( \
/* Execute blocking SQL query and return result. */
struct sql_prepared_statement *
struct sql_statement *
struct sql_statement *
unsigned int column_idx, const char *value);
unsigned int column_idx, const void *value,
CALLBACK_TYPECHECK(callback, void (*)( \
const struct sql_field_def *fields,
/* Go to next row. See enum sql_result_next. */
/* If sql_result_next_row() returned SQL_RESULT_NEXT_MORE, this can be called
to continue returning more results. The result is freed with this call, so
it must not be accesed anymore until the callback is finished. */
CALLBACK_TYPECHECK(callback, void (*)( \
/* Synchronous version of sql_result_more(). The result will be replaced with
the new result. */
/* Needs to be called only with sql_query_s() or when result has been
explicitly referenced. */
/* 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. Note that it can be NULL. */
unsigned int idx);
/* Returns a binary value. Note that a NULL is returned as NULL with size=0,
while empty string returns non-NULL with size=0. */
const unsigned char *
/* Find the field and return its value. NULL return value can mean that either
the field didn't exist or that its value is NULL. */
const char *field_name);
/* Return all values of current row. Note that this array is not
NULL-terminated - you must use sql_result_get_fields_count() to find out
the array's length. It's also possible that some of the values inside the
array are NULL. */
/* Return last error message in result. */
/* Begin a new transaction. Currently you're limited to only one open
transaction at a time. */
/* Commit transaction. */
CALLBACK_TYPECHECK(callback, void (*)( \
/* Synchronous commit. Returns 0 if ok, -1 if error. */
const char **error_r);
/* Execute query in given transaction. */
struct sql_statement **stmt);
/* Save the number of rows updated by this query. The value is set before
commit callback is called. */
unsigned int *affected_rows);
struct sql_statement **stmt,
unsigned int *affected_rows);
#endif