|
|
@@ -343,7 +343,8 @@ typedef struct {
|
|
|
#ifdef USE_STMTS
|
|
|
tab_stmt_t stmts[DB_TAB_MAX];
|
|
|
#endif
|
|
|
-
|
|
|
+ char *buf;
|
|
|
+ int buflen;
|
|
|
uint8_t inited;
|
|
|
}db_handle_t;
|
|
|
static db_handle_t dbHandle={0};
|
|
|
@@ -478,18 +479,17 @@ static sqlite3_stmt* get_stmt(db_handle_t *h, int tab_id, int cmd)
|
|
|
static int tab_cmd(db_handle_t *h, int tab_id, int cmd_id, handle_t list)
|
|
|
{
|
|
|
int r=-1;
|
|
|
- char sql[512];
|
|
|
sqlite3_stmt *stmt;
|
|
|
sqlite3 *db=get_db(h,tab_id);
|
|
|
|
|
|
if(cmd_id>=CMD_CREATE) {
|
|
|
- snprintf(sql, sizeof(sql), tab_info[tab_id].sql[cmd_id], tab_info[tab_id].sql[cmd_id]);
|
|
|
+ snprintf(h->buf, h->buflen, tab_info[tab_id].sql[cmd_id-CMD_CREATE], tab_info[tab_id].tab);
|
|
|
}
|
|
|
else {
|
|
|
- snprintf(sql, sizeof(sql), common_cmd[cmd_id], tab_info[tab_id].tab);
|
|
|
+ snprintf(h->buf, h->buflen, common_cmd[cmd_id], tab_info[tab_id].tab);
|
|
|
}
|
|
|
|
|
|
- r = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
|
|
|
+ r = sqlite3_prepare_v2(db, h->buf, -1, &stmt, NULL);
|
|
|
if (r == SQLITE_OK) {
|
|
|
|
|
|
if(cmd_id>=CMD_CREATE) {
|
|
|
@@ -517,7 +517,6 @@ static int tab_cmd(db_handle_t *h, int tab_id, int cmd_id, handle_t list)
|
|
|
static int stmt_init(db_handle_t *h)
|
|
|
{
|
|
|
int i,j,r;
|
|
|
- char temp[512];
|
|
|
sqlite3 *db=NULL;
|
|
|
node_t node;
|
|
|
list_cfg_t lc={0,0,10};
|
|
|
@@ -530,15 +529,15 @@ static int stmt_init(db_handle_t *h)
|
|
|
#ifdef USE_STMTS
|
|
|
for(j=0; j<CMD_MAX; j++) {
|
|
|
if(j>=CMD_CREATE) {
|
|
|
- snprintf(temp, sizeof(temp), common_cmd[j-CMD_CREATE], tab_info[i].tab);
|
|
|
+ snprintf(h->buf, h->buflen, common_cmd[j-CMD_CREATE], tab_info[i].tab);
|
|
|
}
|
|
|
else {
|
|
|
- snprintf(temp, sizeof(temp), tab_info[i].sql[j], tab_info[i].tab);
|
|
|
+ snprintf(h->buf, h->buflen, tab_info[i].sql[j], tab_info[i].tab);
|
|
|
}
|
|
|
|
|
|
- r = sqlite3_prepare_v2(db, temp, -1, &h->stmts[i].stmt[j], 0);
|
|
|
+ r = sqlite3_prepare_v2(db, h->buf, -1, &h->stmts[i].stmt[j], 0);
|
|
|
if (r != SQLITE_OK) {
|
|
|
- LOGE("sqlite3_prepare_v2 failed, sql: %s, %s\n", temp, sqlite3_errmsg(db));
|
|
|
+ LOGE("sqlite3_prepare_v2 failed, sql: %s, %s\n", h->buf, sqlite3_errmsg(db));
|
|
|
}
|
|
|
}
|
|
|
#endif
|
|
|
@@ -940,12 +939,19 @@ int db_init(void)
|
|
|
char *ext[DB_MAX]={"cfg","rec"};
|
|
|
|
|
|
memset(h, 0, sizeof(db_handle_t));
|
|
|
+ h->buflen = (1024*2);
|
|
|
+ h->buf = (char*)malloc(h->buflen);
|
|
|
+ if(!h->buf) {
|
|
|
+ LOGE("___db buf malloc failed!\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
sqlite3_initialize();
|
|
|
for(i=0; i<DB_MAX; i++) {
|
|
|
sprintf(path, "%s/%s_%s.db", DB_PATH, DB_NAME, ext[i]);
|
|
|
r = sqlite3_open(path, &h->db[i]);
|
|
|
if(r != SQLITE_OK) {
|
|
|
- LOGE("___%s open failed\n", path);
|
|
|
+ LOGE("___%s open failed, %s\n", path, sqlite3_errstr(r));
|
|
|
return -1 ;
|
|
|
}
|
|
|
sqlite3_exec(h->db[i], "PRAGMA cache_size=0;" , NULL, NULL, NULL);
|