55 #define MIN(x, y) ((x) < (y) ? (x) : (y))
56 #define MAX(x, y) ((x) > (y) ? (x) : (y))
64 rc = sqlite3_step(pStmt);
66 while (rc == SQLITE_LOCKED || rc == SQLITE_BUSY) {
69 select(0, NULL, NULL, NULL, &tv);
71 rc = sqlite3_step(pStmt);
99 static int DbExecuteSqlStatement(
DB_HANDLE handle,
const char* stmt_str,
DB_RESULT* result)
103 rc = sqlite3_prepare_v2((sqlite3*) handle, stmt_str, -1, &((*result)->data), 0);
104 if( rc != SQLITE_OK )
109 return sqlite3_step((*result)->data);
140 const char* errmsg = NULL;
145 if ((!handle) || (!stmt_str) || (*stmt_str ==
'\0') || (! result)) {
154 (*result)->handle = handle;
155 (*result)->first_row = 1;
159 status = DbExecuteSqlStatement(handle, stmt_str, result);
160 if (status == SQLITE_ROW) {
165 if ((*result)->data == NULL) {
175 if (errmsg && *errmsg) {
203 (*result)->
count = sqlite3_data_count((sqlite3_stmt*) (*result)->data);
206 else if (status == SQLITE_DONE)
210 status = sqlite3_finalize((sqlite3_stmt*) (*result)->data);
248 sqlite3_finalize(result->
data);
299 (*row)->result=result;
303 status = sqlite3_step(result->
data);
304 if (status == SQLITE_DONE) {
311 else if (status == SQLITE_ROW)
315 (*row)->result=result;
400 if ((field_index >= 0) && (field_index < row->result->count)) {
404 width = sqlite3_column_bytes(row->
result->
data, field_index);
408 if (sqlite3_column_text(row->
result->
data, field_index) != NULL) {
411 memcpy(*result, sqlite3_column_text(row->
result->
data, field_index), width);
412 (*result)[width] = 0;
466 const char* sql =
"begin transaction";
482 const char* sql =
"commit transaction";
498 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)