add additional multi table query test default tip

Wed, 31 Dec 2025 15:41:51 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 31 Dec 2025 15:41:51 +0100
changeset 36
93753b036d9f
parent 35
16731869cc05

add additional multi table query test

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/test/database.c	Wed Dec 31 15:40:44 2025 +0100
+++ b/test/database.c	Wed Dec 31 15:41:51 2025 +0100
@@ -315,6 +315,49 @@
     cxMempoolFree(mp);
 }
 
+CX_TEST(testMultiTableQuery1) {
+    CxMempool *mp = cxMempoolCreateSimple(64);
+    
+    CX_TEST_DO {
+        const char *sql1 = "select p.*, NULL as [__address], a.* from Person p inner join Address a on p.address_id = a.address_id order by p.person_id;";
+        DBUQuery *query = dbuQueryCreate(conn, mp->allocator, sql1);
+        DBUObjectBuilder *builder = dbuObjectBuilder(person, query, mp->allocator);
+        CxList *persons = dbuObjectBuilderGetList(builder);
+        
+        CX_TEST_ASSERT(persons);
+        CX_TEST_ASSERT(cxListSize(persons) == 2);
+        
+        Person *p0 = cxListAt(persons, 0);
+        Person *p1 = cxListAt(persons, 1);
+        CX_TEST_ASSERT(p0);
+        CX_TEST_ASSERT(p1);
+        CX_TEST_ASSERT(!cx_strcmp(p0->name, "alice"));
+        CX_TEST_ASSERT(!cx_strcmp(p1->name, "bob"));
+        CX_TEST_ASSERT(!cx_strcmp(p0->email, "alice@example.com"));
+        CX_TEST_ASSERT(!cx_strcmp(p1->email, "bob@example.com"));
+        CX_TEST_ASSERT(p0->age == 30);
+        CX_TEST_ASSERT(p1->age == 25);
+        CX_TEST_ASSERT(p0->iscustomer == 0);
+        CX_TEST_ASSERT(p1->iscustomer == 1);
+        CX_TEST_ASSERT(p0->hash == 123456789);
+        CX_TEST_ASSERT(p1->hash == 987654321);
+        
+        CX_TEST_ASSERT(p0->address != NULL);
+        CX_TEST_ASSERT(p1->address != NULL);
+        
+        CX_TEST_ASSERT(!cx_strcmp(p0->address->street, "street 1"));
+        CX_TEST_ASSERT(!cx_strcmp(p1->address->street, "street 2"));
+        CX_TEST_ASSERT(!cx_strcmp(p0->address->zip, "12343"));
+        CX_TEST_ASSERT(!cx_strcmp(p1->address->zip, "23456"));
+        CX_TEST_ASSERT(!cx_strcmp(p0->address->city, "city 17"));
+        CX_TEST_ASSERT(!cx_strcmp(p1->address->city, "city 18"));
+        
+        dbuObjectBuilderDestroy(builder);
+    }
+    
+    cxMempoolFree(mp);
+}
+
 CX_TEST(testMultiTableQuery2) {
     CxMempool *mp = cxMempoolCreateSimple(64);
     
--- a/test/database.h	Wed Dec 31 15:40:44 2025 +0100
+++ b/test/database.h	Wed Dec 31 15:41:51 2025 +0100
@@ -51,6 +51,7 @@
 CX_TEST(testSqlExecParam);
 CX_TEST(testSingleTableQuery);
 CX_TEST(testMultiTableQuery);
+CX_TEST(testMultiTableQuery1);
 CX_TEST(testMultiTableQuery2);
 
 
--- a/test/main.c	Wed Dec 31 15:40:44 2025 +0100
+++ b/test/main.c	Wed Dec 31 15:41:51 2025 +0100
@@ -134,6 +134,7 @@
     cx_test_register(suite, testSqlExecParam);
     cx_test_register(suite, testSingleTableQuery);
     cx_test_register(suite, testMultiTableQuery);
+    cx_test_register(suite, testMultiTableQuery1);
     cx_test_register(suite, testMultiTableQuery2);
 #endif
     cx_test_register(suite, testObjectToJsonSimple);

mercurial