42 strncpy(buf, dbname, size-1);
50 return sqlite3_open(filename, ppDb);
55 return sqlite3_open_v2(filename, ppDb, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_URI, NULL);
60 return sqlite3_close(db);
65 return sqlite3_column_text(stmt, iCol);
70 return sqlite3_column_name(stmt, N);
75 return sqlite3_column_count(pStmt);
80 return sqlite3_errmsg(db);
90 ret = sqlite3_exec(db, sql, callback, data, &err);
91 if (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) {
116 return sqlite3_finalize(pStmt);
121 return sqlite3_prepare(db, zSql, nBytes, ppStmt, pzTail);
126 return sqlite3_step(stmt);
131 return sqlite3_reset(pStmt);
136 return sqlite3_bind_int(pStmt, i, iValue);
141 return sqlite3_bind_int64(pStmt, i, iValue);
146 return sqlite3_bind_text(pStmt, i, zData, nData, xDel);
151 return sqlite3_bind_double(pStmt, i, dValue);
156 return sqlite3_last_insert_rowid(db);
161 return sqlite3_get_table(db, sql, resultp, nrow, ncolumn, errmsg);
166 sqlite3_free_table(result);
176 return sqlite3_changes(db);
184 #ifdef SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 185 sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, 0);
186 ret = sqlite3_load_extension(db, extension, 0, &err);
188 sqlite3_enable_load_extension(db, 1);
189 ret = sqlite3_load_extension(db, extension, 0, &err);
190 sqlite3_enable_load_extension(db, 0);
204 if ((db_ret =
switch_core_db_exec(db,
"PRAGMA synchronous=OFF;", NULL, NULL, NULL)) != SQLITE_OK) {
207 if ((db_ret =
switch_core_db_exec(db,
"PRAGMA count_changes=OFF;", NULL, NULL, NULL)) != SQLITE_OK) {
210 if ((db_ret =
switch_core_db_exec(db,
"PRAGMA temp_store=MEMORY;", NULL, NULL, NULL)) != SQLITE_OK) {
214 if ((db_ret =
switch_core_db_exec(db,
"PRAGMA cache_size=8000;", NULL, NULL, NULL)) != SQLITE_OK) {
218 if ((db_ret =
switch_core_db_exec(db,
"PRAGMA cache_size=-8192;", NULL, NULL, NULL)) != SQLITE_OK) {
221 if ((db_ret =
switch_core_db_exec(db,
"PRAGMA journal_mode=OFF;", NULL, NULL, NULL)) != SQLITE_OK) {
245 if (db_ret != SQLITE_OK) {
266 if (db_ret != SQLITE_OK) {
322 unsigned begin_retries = 100;
332 while (begin_retries > 0) {
339 if (strstr(errmsg,
"cannot start a transaction within a transaction")) {
354 if (begin_retries == 0) {
363 while (retries > 0) {
371 if (retries == 0 && forever) {
399 while (retries > 0) {
406 if (retries == 0 && forever) {
void switch_core_db_free_table(char **result)
#define SWITCH_CHANNEL_LOG
const char * switch_core_db_errmsg(switch_core_db_t *db)
int switch_core_db_get_table(switch_core_db_t *db, const char *sql, char ***resultp, int *nrow, int *ncolumn, char **errmsg)
void(* switch_core_db_destructor_type_t)(void *)
const char * switch_core_db_column_name(switch_core_db_stmt_t *stmt, int N)
switch_core_db_t * switch_core_db_open_in_memory(const char *uri)
Open a core db (SQLite) in-memory.
int switch_core_db_close(switch_core_db_t *db)
switch_status_t switch_core_db_persistant_execute(switch_core_db_t *db, char *sql, uint32_t retries)
Execute a sql stmt until it is accepted.
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
int switch_core_db_finalize(switch_core_db_stmt_t *pStmt)
struct switch_runtime runtime
int switch_core_db_step(switch_core_db_stmt_t *stmt)
int switch_core_db_exec(switch_core_db_t *db, const char *sql, switch_core_db_callback_func_t callback, void *data, char **errmsg)
int switch_core_db_bind_text(switch_core_db_stmt_t *pStmt, int i, const char *zData, int nData, switch_core_db_destructor_type_t xDel)
#define SWITCH_PATH_SEPARATOR
switch_byte_t switch_byte_t * buf
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
int switch_core_db_load_extension(switch_core_db_t *db, const char *extension)
void switch_core_db_test_reactive(switch_core_db_t *db, char *test_sql, char *drop_sql, char *reactive_sql)
perform a test query then perform a reactive query if the first one fails
int switch_core_db_open_v2(const char *filename, switch_core_db_t **ppDb)
int(* switch_core_db_callback_func_t)(void *pArg, int argc, char **argv, char **columnNames)
int switch_core_db_reset(switch_core_db_stmt_t *pStmt)
switch_status_t switch_core_db_persistant_execute_trans(switch_core_db_t *db, char *sql, uint32_t retries)
switch_directories SWITCH_GLOBAL_dirs
static int switch_core_db_connection_setup(switch_core_db_t *db, switch_bool_t in_memory)
int switch_core_db_bind_double(switch_core_db_stmt_t *pStmt, int i, double dValue)
switch_status_t
Common return values.
const char *const const char *const path
int64_t switch_core_db_last_insert_rowid(switch_core_db_t *db)
struct sqlite3 switch_core_db_t
int switch_core_db_open(const char *filename, switch_core_db_t **ppDb)
static switch_bool_t switch_is_file_path(const char *file)
void switch_core_db_free(char *z)
struct sqlite3_stmt switch_core_db_stmt_t
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
int switch_core_db_changes(switch_core_db_t *db)
int switch_core_db_column_count(switch_core_db_stmt_t *pStmt)
const unsigned char * switch_core_db_column_text(switch_core_db_stmt_t *stmt, int iCol)
int switch_core_db_bind_int64(switch_core_db_stmt_t *pStmt, int i, int64_t iValue)
switch_core_db_t * switch_core_db_open_file(const char *filename)
Open a core db (SQLite) file.
static void db_pick_path(const char *dbname, char *buf, switch_size_t size)
int switch_core_db_prepare(switch_core_db_t *db, const char *zSql, int nBytes, switch_core_db_stmt_t **ppStmt, const char **pzTail)
int switch_core_db_bind_int(switch_core_db_stmt_t *pStmt, int i, int iValue)