42 strncpy(buf, dbname, size);
50 return sqlite3_open(filename, ppDb);
55 return sqlite3_close(db);
60 const unsigned char *txt = sqlite3_column_text(stmt, iCol);
62 if (!strcasecmp((
char *) stmt,
"(null)")) {
73 return sqlite3_column_name(stmt, N);
78 return sqlite3_column_count(pStmt);
83 return sqlite3_errmsg(db);
93 ret = sqlite3_exec(db, sql, callback, data, &err);
94 if (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) {
118 return sqlite3_finalize(pStmt);
123 return sqlite3_prepare(db, zSql, nBytes, ppStmt, pzTail);
128 return sqlite3_step(stmt);
133 return sqlite3_reset(pStmt);
138 return sqlite3_bind_int(pStmt, i, iValue);
143 return sqlite3_bind_int64(pStmt, i, iValue);
148 return sqlite3_bind_text(pStmt, i, zData, nData, xDel);
153 return sqlite3_bind_double(pStmt, i, dValue);
158 return sqlite3_last_insert_rowid(db);
163 return sqlite3_get_table(db, sql, resultp, nrow, ncolumn, errmsg);
168 sqlite3_free_table(result);
178 return sqlite3_changes(db);
186 sqlite3_enable_load_extension(db, 1);
187 ret = sqlite3_load_extension(db, extension, 0, &err);
188 sqlite3_enable_load_extension(db, 0);
208 if ((db_ret =
switch_core_db_exec(db,
"PRAGMA synchronous=OFF;", NULL, NULL, NULL) != SQLITE_OK)) {
211 if ((db_ret =
switch_core_db_exec(db,
"PRAGMA count_changes=OFF;", NULL, NULL, NULL) != SQLITE_OK)) {
214 if ((db_ret =
switch_core_db_exec(db,
"PRAGMA cache_size=8000;", NULL, NULL, NULL) != SQLITE_OK)) {
217 if ((db_ret =
switch_core_db_exec(db,
"PRAGMA temp_store=MEMORY;", NULL, NULL, NULL) != SQLITE_OK)) {
222 if (db_ret != SQLITE_OK) {
278 unsigned begin_retries = 100;
288 while (begin_retries > 0) {
295 if (strstr(errmsg,
"cannot start a transaction within a transaction")) {
310 if (begin_retries == 0) {
319 while (retries > 0) {
327 if (retries == 0 && forever) {
355 while (retries > 0) {
362 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)
const char * switch_core_db_column_name(switch_core_db_stmt_t *stmt, int N)
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_core_db_callback_func_t)(void *pArg, int argc, char **argv, char **columnNames)
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_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
int switch_core_db_bind_double(switch_core_db_stmt_t *pStmt, int i, double dValue)
switch_status_t
Common return values.
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)
void(* switch_core_db_destructor_type_t)(void *)