| 313 } |
313 } |
| 314 |
314 |
| 315 cxMempoolFree(mp); |
315 cxMempoolFree(mp); |
| 316 } |
316 } |
| 317 |
317 |
| 318 CX_TEST(testMultiTableQuery2) { |
318 CX_TEST(testMultiTableQuery1) { |
| 319 CxMempool *mp = cxMempoolCreateSimple(64); |
319 CxMempool *mp = cxMempoolCreateSimple(64); |
| 320 |
320 |
| 321 CX_TEST_DO { |
321 CX_TEST_DO { |
| 322 const char *sql2 = "select p.*, " |
322 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;"; |
| 323 "a.address_id as [__address__address_id], a.street, a.zip, a.city, " |
323 DBUQuery *query = dbuQueryCreate(conn, mp->allocator, sql1); |
| 324 "c.country_id as [__country__country_id], c.name " |
|
| 325 "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 " |
|
| 326 "order by p.person_id;"; |
|
| 327 DBUQuery *query = dbuQueryCreate(conn, mp->allocator, sql2); |
|
| 328 DBUObjectBuilder *builder = dbuObjectBuilder(person, query, mp->allocator); |
324 DBUObjectBuilder *builder = dbuObjectBuilder(person, query, mp->allocator); |
| 329 CxList *persons = dbuObjectBuilderGetList(builder); |
325 CxList *persons = dbuObjectBuilderGetList(builder); |
| 330 |
326 |
| 331 CX_TEST_ASSERT(persons); |
327 CX_TEST_ASSERT(persons); |
| 332 CX_TEST_ASSERT(cxListSize(persons) == 2); |
328 CX_TEST_ASSERT(cxListSize(persons) == 2); |
| 354 CX_TEST_ASSERT(!cx_strcmp(p0->address->zip, "12343")); |
350 CX_TEST_ASSERT(!cx_strcmp(p0->address->zip, "12343")); |
| 355 CX_TEST_ASSERT(!cx_strcmp(p1->address->zip, "23456")); |
351 CX_TEST_ASSERT(!cx_strcmp(p1->address->zip, "23456")); |
| 356 CX_TEST_ASSERT(!cx_strcmp(p0->address->city, "city 17")); |
352 CX_TEST_ASSERT(!cx_strcmp(p0->address->city, "city 17")); |
| 357 CX_TEST_ASSERT(!cx_strcmp(p1->address->city, "city 18")); |
353 CX_TEST_ASSERT(!cx_strcmp(p1->address->city, "city 18")); |
| 358 |
354 |
| |
355 dbuObjectBuilderDestroy(builder); |
| |
356 } |
| |
357 |
| |
358 cxMempoolFree(mp); |
| |
359 } |
| |
360 |
| |
361 CX_TEST(testMultiTableQuery2) { |
| |
362 CxMempool *mp = cxMempoolCreateSimple(64); |
| |
363 |
| |
364 CX_TEST_DO { |
| |
365 const char *sql2 = "select p.*, " |
| |
366 "a.address_id as [__address__address_id], a.street, a.zip, a.city, " |
| |
367 "c.country_id as [__country__country_id], c.name " |
| |
368 "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 " |
| |
369 "order by p.person_id;"; |
| |
370 DBUQuery *query = dbuQueryCreate(conn, mp->allocator, sql2); |
| |
371 DBUObjectBuilder *builder = dbuObjectBuilder(person, query, mp->allocator); |
| |
372 CxList *persons = dbuObjectBuilderGetList(builder); |
| |
373 |
| |
374 CX_TEST_ASSERT(persons); |
| |
375 CX_TEST_ASSERT(cxListSize(persons) == 2); |
| |
376 |
| |
377 Person *p0 = cxListAt(persons, 0); |
| |
378 Person *p1 = cxListAt(persons, 1); |
| |
379 CX_TEST_ASSERT(p0); |
| |
380 CX_TEST_ASSERT(p1); |
| |
381 CX_TEST_ASSERT(!cx_strcmp(p0->name, "alice")); |
| |
382 CX_TEST_ASSERT(!cx_strcmp(p1->name, "bob")); |
| |
383 CX_TEST_ASSERT(!cx_strcmp(p0->email, "alice@example.com")); |
| |
384 CX_TEST_ASSERT(!cx_strcmp(p1->email, "bob@example.com")); |
| |
385 CX_TEST_ASSERT(p0->age == 30); |
| |
386 CX_TEST_ASSERT(p1->age == 25); |
| |
387 CX_TEST_ASSERT(p0->iscustomer == 0); |
| |
388 CX_TEST_ASSERT(p1->iscustomer == 1); |
| |
389 CX_TEST_ASSERT(p0->hash == 123456789); |
| |
390 CX_TEST_ASSERT(p1->hash == 987654321); |
| |
391 |
| |
392 CX_TEST_ASSERT(p0->address != NULL); |
| |
393 CX_TEST_ASSERT(p1->address != NULL); |
| |
394 |
| |
395 CX_TEST_ASSERT(!cx_strcmp(p0->address->street, "street 1")); |
| |
396 CX_TEST_ASSERT(!cx_strcmp(p1->address->street, "street 2")); |
| |
397 CX_TEST_ASSERT(!cx_strcmp(p0->address->zip, "12343")); |
| |
398 CX_TEST_ASSERT(!cx_strcmp(p1->address->zip, "23456")); |
| |
399 CX_TEST_ASSERT(!cx_strcmp(p0->address->city, "city 17")); |
| |
400 CX_TEST_ASSERT(!cx_strcmp(p1->address->city, "city 18")); |
| |
401 |
| 359 CX_TEST_ASSERT(p0->address->country); |
402 CX_TEST_ASSERT(p0->address->country); |
| 360 CX_TEST_ASSERT(p1->address->country); |
403 CX_TEST_ASSERT(p1->address->country); |
| 361 CX_TEST_ASSERT(!cx_strcmp(p0->address->country->name, "Germany")); |
404 CX_TEST_ASSERT(!cx_strcmp(p0->address->country->name, "Germany")); |
| 362 CX_TEST_ASSERT(!cx_strcmp(p1->address->country->name, "Germany")); |
405 CX_TEST_ASSERT(!cx_strcmp(p1->address->country->name, "Germany")); |
| 363 |
406 |