add testSqlExecParam

Wed, 21 Jan 2026 17:59:45 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 21 Jan 2026 17:59:45 +0100
changeset 49
34c723ed7190
parent 48
deb6c4b8cf9d
child 50
c160700751ec

add testSqlExecParam

dbutils/db.c file | annotate | diff | comparison | revisions
test/database.c file | annotate | diff | comparison | revisions
test/database.h file | annotate | diff | comparison | revisions
test/main.c file | annotate | diff | comparison | revisions
--- a/dbutils/db.c	Wed Jan 21 17:46:10 2026 +0100
+++ b/dbutils/db.c	Wed Jan 21 17:59:45 2026 +0100
@@ -381,13 +381,19 @@
 
 int dbuSqlExec(DBUConnection *conn, const char *sql) {
     DBUResult *result = dbuSqlExecQuery(conn, NULL, sql);
+    if(!result) {
+        return 1;
+    }
     int ret = dbuResultIsOk(result);
     dbuResultFree(result);
-    return ret;
+    return !ret;
 }
 
 int dbuSqlExecParamInt32(DBUConnection *conn, const char *sql, int32_t param) {
     DBUResult *result = dbuSqlExecQueryParam(conn, NULL, sql, param);
+    if(!result) {
+        return 1;
+    }
     int ret = dbuResultIsOk(result);
     dbuResultFree(result);
     return ret;
@@ -395,6 +401,9 @@
 
 int dbuSqlExecParamInt64(DBUConnection *conn, const char *sql, int64_t param) {
     DBUResult *result = dbuSqlExecQueryParam(conn, NULL, sql, param);
+    if(!result) {
+        return 1;
+    }
     int ret = dbuResultIsOk(result);
     dbuResultFree(result);
     return ret;
@@ -402,6 +411,9 @@
 
 int dbuSqlExecParamUInt32(DBUConnection *conn, const char *sql, uint32_t param) {
     DBUResult *result = dbuSqlExecQueryParam(conn, NULL, sql, param);
+    if(!result) {
+        return 1;
+    }
     int ret = dbuResultIsOk(result);
     dbuResultFree(result);
     return ret;
@@ -409,6 +421,9 @@
 
 int dbuSqlExecParamUInt64(DBUConnection *conn, const char *sql, uint32_t param) {
     DBUResult *result = dbuSqlExecQueryParam(conn, NULL, sql, param);
+    if(!result) {
+        return 1;
+    }
     int ret = dbuResultIsOk(result);
     dbuResultFree(result);
     return ret;
@@ -416,6 +431,9 @@
 
 int dbuSqlExecParamString(DBUConnection *conn, const char *sql, const char *param) {
     DBUResult *result = dbuSqlExecQueryParam(conn, NULL, sql, param);
+    if(!result) {
+        return 1;
+    }
     int ret = dbuResultIsOk(result);
     dbuResultFree(result);
     return ret;
@@ -423,6 +441,9 @@
 
 int dbuSqlExecParamCxString(DBUConnection *conn, const char *sql, cxstring param) {
     DBUResult *result = dbuSqlExecQueryParam(conn, NULL, sql, param);
+    if(!result) {
+        return 1;
+    }
     int ret = dbuResultIsOk(result);
     dbuResultFree(result);
     return ret;
@@ -430,6 +451,9 @@
 
 int dbuSqlExecParamCxMutStr(DBUConnection *conn, const char *sql, cxmutstr param) {
     DBUResult *result = dbuSqlExecQueryParam(conn, NULL, sql, param);
+    if(!result) {
+        return 1;
+    }
     int ret = dbuResultIsOk(result);
     dbuResultFree(result);
     return ret;
--- a/test/database.c	Wed Jan 21 17:46:10 2026 +0100
+++ b/test/database.c	Wed Jan 21 17:59:45 2026 +0100
@@ -246,6 +246,25 @@
     }
 }
 
+CX_TEST(testSqlExecParam) {
+    CX_TEST_DO {
+        CX_TEST_ASSERT(dbuSqlExec(conn, "PRAGMA foreign_keys = ON;") == 0);
+        CX_TEST_ASSERT(dbuSqlExec(conn,
+                "create table ExecTest3( "
+                "test1_id integer primary key autoincrement, "
+                "value int);") == 0);
+        CX_TEST_ASSERT(dbuSqlExec(conn,
+                "create table ExecTest4( "
+                "test2_id integer primary key autoincrement, "
+                "exectest1_id int references ExecTest3(test1_id), "
+                "value int);") == 0);
+        CX_TEST_ASSERT(dbuSqlExec(conn, "insert into ExecTest3(value) values (123);") == 0);
+        
+        // fail test
+        CX_TEST_ASSERT(dbuSqlExec(conn, "insert into ExecTest4(exectest1_id, value) values (-999, 123);") != 0);
+    }
+}
+
 CX_TEST(testSingleTableQuery) {
     CxMempool *mp = cxMempoolCreateSimple(64);
     
--- a/test/database.h	Wed Jan 21 17:46:10 2026 +0100
+++ b/test/database.h	Wed Jan 21 17:59:45 2026 +0100
@@ -49,6 +49,7 @@
 CX_TEST(testSingleValueQuery);
 CX_TEST(testSqlExecQuery);
 CX_TEST(testSqlExecQueryParam);
+CX_TEST(testSqlExecParam);
 CX_TEST(testSingleTableQuery);
 CX_TEST(testMultiTableQuery);
 CX_TEST(testMultiTableQuery1);
--- a/test/main.c	Wed Jan 21 17:46:10 2026 +0100
+++ b/test/main.c	Wed Jan 21 17:59:45 2026 +0100
@@ -132,6 +132,7 @@
     cx_test_register(suite, testSingleValueQuery);
     cx_test_register(suite, testSqlExecQuery);
     cx_test_register(suite, testSqlExecQueryParam);
+    cx_test_register(suite, testSqlExecParam);
     cx_test_register(suite, testSingleTableQuery);
     cx_test_register(suite, testMultiTableQuery);
     cx_test_register(suite, testMultiTableQuery1);

mercurial