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