diff --git a/cdr/cdr_sqlite3_custom.c b/cdr/cdr_sqlite3_custom.c index 435f4b37e3703c0d24764cfcb207a13e802d6b23..c33601e102701fb95b83df362a40d84229b8ed8b 100644 --- a/cdr/cdr_sqlite3_custom.c +++ b/cdr/cdr_sqlite3_custom.c @@ -228,7 +228,6 @@ static int write_cdr(struct ast_cdr *cdr) int res = 0; char *error = NULL; char *sql = NULL; - int count = 0; if (db == NULL) { /* Should not have loaded, but be failsafe. */ @@ -264,16 +263,7 @@ static int write_cdr(struct ast_cdr *cdr) ast_free(value_string); } - /* XXX This seems awful arbitrary... */ - for (count = 0; count < 5; count++) { - res = sqlite3_exec(db, sql, NULL, NULL, &error); - if (res != SQLITE_BUSY && res != SQLITE_LOCKED) { - break; - } - usleep(200); - } - - if (error) { + if (sqlite3_exec(db, sql, NULL, NULL, &error) != SQLITE_OK) { ast_log(LOG_ERROR, "%s. SQL: %s.\n", error, sql); sqlite3_free(error); } @@ -317,7 +307,7 @@ static int load_module(void) free_config(0); return AST_MODULE_LOAD_DECLINE; } - + sqlite3_busy_timeout(db, 1000); /* is the table there? */ sql = sqlite3_mprintf("SELECT COUNT(AcctId) FROM %q;", table); res = sqlite3_exec(db, sql, NULL, NULL, NULL); diff --git a/cel/cel_sqlite3_custom.c b/cel/cel_sqlite3_custom.c index 8ff3bd702ffe09e61fe84ffc32dd863e80b13594..110c8dc1c4d6c7f928a11498c5fc2849f47c8401 100644 --- a/cel/cel_sqlite3_custom.c +++ b/cel/cel_sqlite3_custom.c @@ -234,7 +234,6 @@ static void write_cel(struct ast_event *event) { char *error = NULL; char *sql = NULL; - int count = 0; if (db == NULL) { /* Should not have loaded, but be failsafe. */ @@ -269,18 +268,7 @@ static void write_cel(struct ast_event *event) ast_free(value_string); } - /* XXX This seems awful arbitrary... */ - for (count = 0; count < 5; count++) { - int res = sqlite3_exec(db, sql, NULL, NULL, &error); - if (res != SQLITE_BUSY && res != SQLITE_LOCKED) { - break; - } - usleep(200); - } - - ast_mutex_unlock(&lock); - - if (error) { + if (sqlite3_exec(db, sql, NULL, NULL, &error) != SQLITE_OK) { ast_log(LOG_ERROR, "%s. SQL: %s.\n", error, sql); sqlite3_free(error); } @@ -288,6 +276,7 @@ static void write_cel(struct ast_event *event) if (sql) { sqlite3_free(sql); } + ast_mutex_unlock(&lock); return; } @@ -320,7 +309,7 @@ static int load_module(void) free_config(); return AST_MODULE_LOAD_DECLINE; } - + sqlite3_busy_timeout(db, 1000); /* is the table there? */ sql = sqlite3_mprintf("SELECT COUNT(*) FROM %q;", table); res = sqlite3_exec(db, sql, NULL, NULL, NULL); diff --git a/main/db.c b/main/db.c index 94583d678b0520503f42de261e5f1ff3a2de1551..5a0f174343b18e65d9fa012d99761bf73b472006 100644 --- a/main/db.c +++ b/main/db.c @@ -257,6 +257,7 @@ static int db_open(void) ast_mutex_unlock(&dblock); return -1; } + ast_mutex_unlock(&dblock); return 0; @@ -283,9 +284,8 @@ static int db_execute_sql(const char *sql, int (*callback)(void *, int, char **, char *errmsg = NULL; int res =0; - sqlite3_exec(astdb, sql, callback, arg, &errmsg); - if (errmsg) { - ast_log(LOG_WARNING, "Error executing SQL: %s\n", errmsg); + if (sqlite3_exec(astdb, sql, callback, arg, &errmsg) != SQLITE_OK) { + ast_log(LOG_WARNING, "Error executing SQL (%s): %s\n", sql, errmsg); sqlite3_free(errmsg); res = -1; } diff --git a/res/res_config_sqlite3.c b/res/res_config_sqlite3.c index 0a4b1acacb1d08f82643a93de23a0f6d73386b71..6fa60386de7aa22c4243c0501ad1bed1e8a28782 100644 --- a/res/res_config_sqlite3.c +++ b/res/res_config_sqlite3.c @@ -324,6 +324,7 @@ static int db_open(struct realtime_sqlite3_db *db) ao2_unlock(db); return -1; } + sqlite3_busy_timeout(db->handle, 1000); if (db->debug) { sqlite3_trace(db->handle, trace_cb, db);