test/database.c

changeset 34
0d2291e77d32
parent 33
106ff84c18ed
equal deleted inserted replaced
33:106ff84c18ed 34:0d2291e77d32
352 } 352 }
353 353
354 cxMempoolFree(mp); 354 cxMempoolFree(mp);
355 } 355 }
356 356
357 CX_TEST(testMultiTableQuery2) {
358 CxMempool *mp = cxMempoolCreateSimple(64);
359
360 CX_TEST_DO {
361 const char *sql2 = "select p.*, "
362 "a.address_id as [__address__address_id], a.street, a.zip, a.city, "
363 "c.country_id as [__country__country_id], c.name "
364 "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 "
365 "order by p.person_id;";
366 DBUQuery *query = dbuQueryCreate(conn, mp->allocator, sql2);
367 DBUObjectBuilder *builder = dbuObjectBuilder(person, query, mp->allocator);
368 CxList *persons = dbuObjectBuilderGetList(builder);
369
370 CX_TEST_ASSERT(persons);
371 CX_TEST_ASSERT(cxListSize(persons) == 2);
372
373 Person *p0 = cxListAt(persons, 0);
374 Person *p1 = cxListAt(persons, 1);
375 CX_TEST_ASSERT(p0);
376 CX_TEST_ASSERT(p1);
377 CX_TEST_ASSERT(!cx_strcmp(p0->name, "alice"));
378 CX_TEST_ASSERT(!cx_strcmp(p1->name, "bob"));
379 CX_TEST_ASSERT(!cx_strcmp(p0->email, "alice@example.com"));
380 CX_TEST_ASSERT(!cx_strcmp(p1->email, "bob@example.com"));
381 CX_TEST_ASSERT(p0->age == 30);
382 CX_TEST_ASSERT(p1->age == 25);
383 CX_TEST_ASSERT(p0->iscustomer == 0);
384 CX_TEST_ASSERT(p1->iscustomer == 1);
385 CX_TEST_ASSERT(p0->hash == 123456789);
386 CX_TEST_ASSERT(p1->hash == 987654321);
387
388 CX_TEST_ASSERT(p0->address != NULL);
389 CX_TEST_ASSERT(p1->address != NULL);
390
391 CX_TEST_ASSERT(!cx_strcmp(p0->address->street, "street 1"));
392 CX_TEST_ASSERT(!cx_strcmp(p1->address->street, "street 2"));
393 CX_TEST_ASSERT(!cx_strcmp(p0->address->zip, "12343"));
394 CX_TEST_ASSERT(!cx_strcmp(p1->address->zip, "23456"));
395 CX_TEST_ASSERT(!cx_strcmp(p0->address->city, "city 17"));
396 CX_TEST_ASSERT(!cx_strcmp(p1->address->city, "city 18"));
397
398 dbuObjectBuilderDestroy(builder);
399 }
400
401 cxMempoolFree(mp);
402 }

mercurial