From ac4f33be1bbbed68d88332c23447cd167d6b36ae Mon Sep 17 00:00:00 2001 From: Timerix Date: Mon, 15 Dec 2025 15:31:11 +0500 Subject: [PATCH] simplified tsqlite_connection_close --- include/tsqlite.h | 4 ++-- src/connection.c | 7 +++---- tests/main.c | 18 ++---------------- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/include/tsqlite.h b/include/tsqlite.h index b52907e..b230054 100644 --- a/include/tsqlite.h +++ b/include/tsqlite.h @@ -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 { diff --git a/src/connection.c b/src/connection.c index d283937..43ee644 100644 --- a/src/connection.c +++ b/src/connection.c @@ -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); } diff --git a/tests/main.c b/tests/main.c index f67dc4d..96ddf70 100644 --- a/tests/main.c +++ b/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; }