Tue, 30 Dec 2025 21:07:45 +0100
split 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 Tue Dec 30 21:05:46 2025 +0100 +++ b/test/database.c Tue Dec 30 21:07:45 2025 +0100 @@ -354,3 +354,49 @@ cxMempoolFree(mp); } +CX_TEST(testMultiTableQuery2) { + CxMempool *mp = cxMempoolCreateSimple(64); + + CX_TEST_DO { + const char *sql2 = "select p.*, " + "a.address_id as [__address__address_id], a.street, a.zip, a.city, " + "c.country_id as [__country__country_id], c.name " + "from Person p inner join Address a on p.address_id = a.address_id inner join Country c on a.country_id = c.country_id " + "order by p.person_id;"; + DBUQuery *query = dbuQueryCreate(conn, mp->allocator, sql2); + 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); +}
--- a/test/database.h Tue Dec 30 21:05:46 2025 +0100 +++ b/test/database.h Tue Dec 30 21:07:45 2025 +0100 @@ -51,6 +51,7 @@ CX_TEST(testSqlExecParam); CX_TEST(testSingleTableQuery); CX_TEST(testMultiTableQuery); +CX_TEST(testMultiTableQuery2); #ifdef __cplusplus
--- a/test/main.c Tue Dec 30 21:05:46 2025 +0100 +++ b/test/main.c Tue Dec 30 21:07:45 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, testMultiTableQuery2); #endif cx_test_register(suite, testObjectToJsonSimple); cx_test_register(suite, testObjectToJsonChildObj);