simplified tsqlite_connection_close
This commit is contained in:
@@ -30,8 +30,8 @@ typedef sqlite3 tsqlite_connection;
|
||||
/// @return new sqlite connection
|
||||
Result(tsqlite_connection*) tsqlite_connection_open(cstr file_path);
|
||||
|
||||
/// all statements and blobs must be destroyed before calling this
|
||||
Result(void) tsqlite_connection_close(tsqlite_connection* db);
|
||||
/// all statements and blobs should be destroyed before calling this
|
||||
void tsqlite_connection_close(tsqlite_connection* db);
|
||||
|
||||
|
||||
typedef struct tsqlite_statement {
|
||||
|
||||
@@ -7,9 +7,8 @@ Result(tsqlite_connection*) tsqlite_connection_open(cstr file_path)
|
||||
return RESULT_VALUE(p, self);
|
||||
}
|
||||
|
||||
Result(void) tsqlite_connection_close(tsqlite_connection* self){
|
||||
void tsqlite_connection_close(tsqlite_connection* self){
|
||||
if(!self)
|
||||
return RESULT_VOID;
|
||||
try_sqlite3(self, sqlite3_close(self));
|
||||
return RESULT_VOID;
|
||||
return;
|
||||
sqlite3_close_v2(self);
|
||||
}
|
||||
|
||||
18
tests/main.c
18
tests/main.c
@@ -1,18 +1,5 @@
|
||||
#include "tsqlite.h"
|
||||
|
||||
Result(void) test_connection(){
|
||||
Deferral(8);
|
||||
|
||||
try(tsqlite_connection* conn, p, tsqlite_connection_open("db.sqlite"));
|
||||
Defer(if(conn != NULL) { IGNORE_RESULT tsqlite_connection_close(conn); });
|
||||
|
||||
// close manually to test tsqlite_connection_close
|
||||
try_void(tsqlite_connection_close(conn));
|
||||
conn = NULL;
|
||||
|
||||
Return RESULT_VOID;
|
||||
}
|
||||
|
||||
#define _create_statement(SQL, TMP_VAR){\
|
||||
try(tsqlite_statement* TMP_VAR, p, tsqlite_statement_compile(conn, STR(SQL)));\
|
||||
Defer(tsqlite_statement_free(TMP_VAR));\
|
||||
@@ -24,11 +11,11 @@ Result(void) test_connection(){
|
||||
printf("executing SQL statement:\n%s\n", sqlite3_sql(st->st));\
|
||||
try_void(tsqlite_statement_execNext(st));\
|
||||
|
||||
Result(void) test_statements(){
|
||||
Result(void) test_connection(){
|
||||
Deferral(8);
|
||||
|
||||
try(tsqlite_connection* conn, p, tsqlite_connection_open("db.sqlite"));
|
||||
Defer(IGNORE_RESULT tsqlite_connection_close(conn));
|
||||
Defer(tsqlite_connection_close(conn));
|
||||
|
||||
tsqlite_statement* st;
|
||||
create_statement("DROP TABLE IF EXISTS Test;");
|
||||
@@ -76,7 +63,6 @@ int main(){
|
||||
Defer(tsqlite_deinit());
|
||||
|
||||
try_fatal_void(test_connection());
|
||||
try_fatal_void(test_statements());
|
||||
|
||||
Return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user