# HG changeset patch # User Olaf Wintermann # Date 1769014785 -3600 # Node ID 34c723ed7190020064b21a9e91a9c18ff03b71fe # Parent deb6c4b8cf9d0606463ba2686790e6b6935f11d6 add testSqlExecParam diff -r deb6c4b8cf9d -r 34c723ed7190 dbutils/db.c --- 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; diff -r deb6c4b8cf9d -r 34c723ed7190 test/database.c --- 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); diff -r deb6c4b8cf9d -r 34c723ed7190 test/database.h --- 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); diff -r deb6c4b8cf9d -r 34c723ed7190 test/main.c --- 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);