fixed tsqlite_statement bugs
This commit is contained in:
61
tests/main.c
61
tests/main.c
@@ -13,29 +13,56 @@ Result(void) test_connection(){
|
||||
Return RESULT_VOID;
|
||||
}
|
||||
|
||||
Result(void) test_statement(){
|
||||
#define _create_statement(SQL, TMP_VAR){\
|
||||
try(tsqlite_statement* TMP_VAR, p, tsqlite_statement_compile(conn, STR(SQL)));\
|
||||
Defer(tsqlite_statement_free(TMP_VAR));\
|
||||
st = TMP_VAR;\
|
||||
}
|
||||
#define create_statement(SQL) _create_statement(SQL, CAT2(_st_, __LINE__))
|
||||
|
||||
#define exec_statement_no_result() \
|
||||
printf("executing SQL statement:\n%s\n", sqlite3_sql(st->st));\
|
||||
try_void(tsqlite_statement_execNext(st));\
|
||||
|
||||
Result(void) test_statements(){
|
||||
Deferral(8);
|
||||
|
||||
try(tsqlite_connection* conn, p, tsqlite_connection_open("db.sqlite"));
|
||||
Defer(if(conn != NULL) { IGNORE_RESULT tsqlite_connection_close(conn); });
|
||||
Defer(IGNORE_RESULT tsqlite_connection_close(conn));
|
||||
|
||||
try(tsqlite_statement* st, p, tsqlite_statement_compile(conn, STR("meow meow")));
|
||||
Defer(tsqlite_statement_free(st));
|
||||
tsqlite_statement* st;
|
||||
create_statement("DROP TABLE IF EXISTS Test;");
|
||||
exec_statement_no_result();
|
||||
|
||||
try_void(tsqlite_statement_bind_null(st, "nul"));
|
||||
create_statement(
|
||||
"CREATE TABLE Test (\n"
|
||||
" id INTEGER PRIMARY KEY,\n"
|
||||
" a TEXT\n"
|
||||
");");
|
||||
exec_statement_no_result();
|
||||
|
||||
bool has_next_row = false;
|
||||
do {
|
||||
try(has_next_row, i, tsqlite_statement_execNext(st));
|
||||
str cell_str = str_null;
|
||||
try_void(tsqlite_statement_getResult_str(st, &cell_str));
|
||||
printf("RESULT(%i, %i): '"FMT_str"'\n",
|
||||
st->result_row, st->result_col, str_expand(cell_str));
|
||||
} while(has_next_row);
|
||||
create_statement(
|
||||
"INSERT INTO Test(a) VALUES\n"
|
||||
" ('ooeeoo'),\n"
|
||||
" ('wiwiwi');");
|
||||
exec_statement_no_result();
|
||||
|
||||
// close manually to test tsqlite_connection_close
|
||||
try_void(tsqlite_connection_close(conn));
|
||||
conn = NULL;
|
||||
create_statement("SELECT * FROM Test WHERE id IS NOT $nul;");
|
||||
try_void(tsqlite_statement_bind_null(st, "$nul"));
|
||||
printf("executing SQL statement:\n%s\n", sqlite3_sql(st->st));
|
||||
while(true) {
|
||||
try(bool has_result, i, tsqlite_statement_execNext(st));
|
||||
if(!has_result)
|
||||
break;
|
||||
i32 column_count = sqlite3_column_count(st->st);
|
||||
str cell_str;
|
||||
printf("ROW(%i):", st->result_row);
|
||||
for(i32 i = 0; i < column_count; i++){
|
||||
try_void(tsqlite_statement_getResult_str(st, &cell_str));
|
||||
printf(" [%i]='"FMT_str"'", st->result_col, str_expand(cell_str));
|
||||
}
|
||||
printf("\n");
|
||||
};
|
||||
|
||||
Return RESULT_VOID;
|
||||
}
|
||||
@@ -49,7 +76,7 @@ int main(){
|
||||
Defer(tsqlite_deinit());
|
||||
|
||||
try_fatal_void(test_connection());
|
||||
try_fatal_void(test_statement());
|
||||
try_fatal_void(test_statements());
|
||||
|
||||
Return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user