static sqlite3_stmt* run(private_sqlite_database_t *this, char *sql,
va_list *args)
{
- sqlite3_stmt *stmt;
+ sqlite3_stmt *stmt = NULL;
int params, i, res = SQLITE_OK;
if (sqlite3_prepare_v2(this->db, sql, -1, &stmt, NULL) == SQLITE_OK)
}
}
}
+ else
+ {
+ DBG1("preparing sqlite statement failed: %s", sqlite3_errmsg(this->db));
+ }
if (res != SQLITE_OK)
{
+ DBG1("binding sqlite statement failed: %s", sqlite3_errmsg(this->db));
sqlite3_finalize(stmt);
return NULL;
}
int count;
/** column types */
db_type_t *columns;
+ /** reference to db connection */
+ sqlite3 *db;
} sqlite_enumerator_t;
/**
int i;
va_list args;
- if (sqlite3_step(this->stmt) != SQLITE_ROW)
+ switch (sqlite3_step(this->stmt))
{
- return FALSE;
+ case SQLITE_ROW:
+ break;
+ default:
+ DBG1("stepping sqlite statement failed: %s", sqlite3_errmsg(this->db));
+ /* fall */
+ case SQLITE_DONE:
+ return FALSE;
}
va_start(args, this);
for (i = 0; i < this->count; i++)
break;
}
default:
+ DBG1("invalid result type supplied");
return FALSE;
}
}
enumerator->stmt = stmt;
enumerator->count = sqlite3_column_count(stmt);
enumerator->columns = malloc(sizeof(db_type_t) * enumerator->count);
+ enumerator->db = this->db;
for (i = 0; i < enumerator->count; i++)
{
enumerator->columns[i] = va_arg(args, db_type_t);
}
affected = sqlite3_changes(this->db);
}
+ else
+ {
+ DBG1("sqlite execute failed: %s", sqlite3_errmsg(this->db));
+ }
sqlite3_finalize(stmt);
}
this->mutex->unlock(this->mutex);
if (sqlite3_open(file, &this->db) != SQLITE_OK)
{
- DBG1("opening SQLite database '%s' failed", file);
+ DBG1("opening SQLite database '%s' failed: %s",
+ file, sqlite3_errmsg(this->db));
destroy(this);
return NULL;
}