Skip to content

Instantly share code, notes, and snippets.

@ionutrazvanionita
Created April 8, 2015 15:44
Show Gist options
  • Save ionutrazvanionita/bc16114c5bd950431131 to your computer and use it in GitHub Desktop.
Save ionutrazvanionita/bc16114c5bd950431131 to your computer and use it in GitHub Desktop.
diff --git a/modules/db_sqlite/dbase.c b/modules/db_sqlite/dbase.c
index ddc1c34..858e254 100644
--- a/modules/db_sqlite/dbase.c
+++ b/modules/db_sqlite/dbase.c
@@ -41,12 +41,13 @@
#include "dbase.h"
#define COUNT_QUERY "select count(*)"
+#define COUNT_BUF_SIZE 2048
static str query_holder = {NULL,0};
extern int db_sqlite_alloc_limit;
/* TODO set this value somehow(200) */
-char count_buf[200]="select count(*)";
+char count_buf[COUNT_BUF_SIZE]="select count(*)";
str count_str = {count_buf, sizeof(COUNT_QUERY)-1};
static int db_sqlite_prepare_query(const db_con_t* conn, const str *query,
@@ -203,7 +204,15 @@ static inline int db_sqlite_get_query_rows(const db_con_t* _h,
int ret;
sqlite3_stmt* stmt;
- sqlite3_prepare_v2(CON_CONNECTION(_h), query->s, query->len, &stmt, NULL);
+again:
+ ret=sqlite3_prepare_v2(CON_CONNECTION(_h), query->s, query->len, &stmt, NULL);
+ if (ret == SQLITE_BUSY)
+ goto again;
+
+ if (ret != SQLITE_OK) {
+ LM_ERR("failed to prepare query\n");
+ return -1;
+ }
if (_n && _v) {
ret=db_sqlite_bind_values(stmt, _v, _n);
@@ -214,10 +223,10 @@ static inline int db_sqlite_get_query_rows(const db_con_t* _h,
}
-again:
+again2:
ret=sqlite3_step(stmt);
if (ret == SQLITE_BUSY)
- goto again;
+ goto again2;
if (ret != SQLITE_ROW) {
LM_ERR("failed to fetch query size\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment