53 #define MIN(x, y) ((x) < (y) ? (x) : (y))
54 #define MAX(x, y) ((x) > (y) ? (x) : (y))
62 rc = sqlite3_step(pStmt);
64 while (rc == SQLITE_LOCKED || rc == SQLITE_BUSY) {
67 select(0, NULL, NULL, NULL, &tv);
69 rc = sqlite3_step(pStmt);
97 static int DbExecuteSqlStatement(
DB_HANDLE handle,
const char* stmt_str,
DB_RESULT* result)
101 rc = sqlite3_prepare_v2((sqlite3*) handle, stmt_str, -1, &((*result)->data), 0);
102 if( rc != SQLITE_OK )
107 return sqlite3_step((*result)->data);
138 const char* errmsg = NULL;
143 if ((!handle) || (!stmt_str) || (*stmt_str ==
'\0') || (! result)) {
152 (*result)->handle = handle;
153 (*result)->first_row = 1;
157 status = DbExecuteSqlStatement(handle, stmt_str, result);
158 if (status == SQLITE_ROW) {
163 if ((*result)->data == NULL) {
173 if (errmsg && *errmsg) {
201 (*result)->
count = sqlite3_data_count((sqlite3_stmt*) (*result)->data);
204 else if (status == SQLITE_DONE)
208 status = sqlite3_finalize((sqlite3_stmt*) (*result)->data);
246 sqlite3_finalize(result->
data);
297 (*row)->result=result;
301 status = sqlite3_step(result->
data);
302 if (status == SQLITE_DONE) {
309 else if (status == SQLITE_ROW)
313 (*row)->result=result;
398 if ((field_index >= 0) && (field_index < row->result->count)) {
402 width = sqlite3_column_bytes(row->
result->
data, field_index);
406 if (sqlite3_column_text(row->
result->
data, field_index) != NULL) {
409 memcpy(*result, sqlite3_column_text(row->
result->
data, field_index), width);
410 (*result)[width] = 0;
464 const char* sql =
"begin transaction";
480 const char* sql =
"commit transaction";
496 const char* sql =
"rollback transaction";
void DbFreeResult(DB_RESULT result)
void * MemCalloc(size_t nmemb, size_t size)
void DbgOutput(unsigned int mask, const char *format,...)
int DbFetchRow(DB_RESULT result, DB_ROW *row)
int MsgLog(int status,...)
int DbString(DB_ROW row, int field_index, char **result)
struct db_result * DB_RESULT
const char * DbErrmsg(DB_HANDLE handle)
void DbFreeRow(DB_ROW row)
int DbExecuteSql(DB_HANDLE handle, const char *stmt_str, DB_RESULT *result)
void * MemMalloc(size_t size)
int DbBeginTransaction(void)
int DbExecuteSqlNoResult(DB_HANDLE handle, const char *stmt_str)
int sqlite3_my_step(sqlite3_stmt *pStmt)
void DbStringFree(char *string)