Wed, 21 Jan 2026 18:19:31 +0100
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
| 23 | 1 | /* |
| 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
| 3 | * | |
| 4 | * Copyright 2025 Olaf Wintermann. All rights reserved. | |
| 5 | * | |
| 6 | * Redistribution and use in source and binary forms, with or without | |
| 7 | * modification, are permitted provided that the following conditions are met: | |
| 8 | * | |
| 9 | * 1. Redistributions of source code must retain the above copyright | |
| 10 | * notice, this list of conditions and the following disclaimer. | |
| 11 | * | |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
| 13 | * notice, this list of conditions and the following disclaimer in the | |
| 14 | * documentation and/or other materials provided with the distribution. | |
| 15 | * | |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 26 | * POSSIBLIITY OF SUCH DAMAGE. | |
| 27 | */ | |
| 28 | ||
| 29 | #include "database.h" | |
| 30 | ||
| 31 | #include <stdio.h> | |
| 32 | #include <stdlib.h> | |
| 33 | #include <errno.h> | |
| 34 | #include <unistd.h> | |
| 35 | ||
| 36 | #include <cx/buffer.h> | |
| 37 | #include <cx/streams.h> | |
|
25
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
38 | #include <cx/mempool.h> |
| 23 | 39 | |
| 40 | #define TEST_DB "test.db" | |
| 41 | #define TEST_DATA_FILE "testdata.sql" | |
| 42 | ||
| 43 | ||
| 44 | // create test.db and execute testdata script | |
| 45 | int init_test_db(void) { | |
| 46 | sqlite3 *db; | |
| 47 | char *err_msg = NULL; | |
| 48 | ||
| 49 | FILE *f = fopen(TEST_DATA_FILE, "r"); | |
| 50 | if(!f) { | |
| 51 | fprintf(stderr, "Cannot open test data file %s: %s\n", TEST_DATA_FILE, strerror(errno)); | |
| 52 | } | |
| 53 | ||
| 54 | if(unlink(TEST_DB)) { | |
| 55 | if(errno != ENOENT) { | |
| 56 | fprintf(stderr, "Cannot unlink %s: %s\n", TEST_DB, strerror(errno)); | |
| 57 | fclose(f); | |
| 58 | return 1; | |
| 59 | } | |
| 60 | } | |
| 61 | if(sqlite3_open(TEST_DB, &db) != SQLITE_OK) { | |
| 62 | fprintf(stderr, "Cannot open database %s: %s\n", TEST_DB, sqlite3_errmsg(db)); | |
| 63 | fclose(f); | |
| 64 | return 1; | |
| 65 | } | |
| 66 | ||
| 31 | 67 | CxBuffer *buf = cxBufferCreate(cxDefaultAllocator, NULL, 2048, CX_BUFFER_AUTO_EXTEND | CX_BUFFER_FREE_CONTENTS); |
| 23 | 68 | cx_stream_copy(f, buf, (cx_read_func)fread, (cx_write_func)cxBufferWrite); |
| 69 | int err = 0; | |
| 70 | if(buf->size > 0) { | |
| 71 | cxBufferTerminate(buf); | |
| 72 | ||
| 73 | if(sqlite3_exec(db, buf->space, 0, 0, &err_msg) != SQLITE_OK) { | |
| 74 | fprintf(stderr, "SQL error: %s\n", err_msg); | |
| 75 | sqlite3_free(err_msg); | |
| 76 | err = 1; | |
| 77 | } | |
| 78 | } else { | |
| 79 | fprintf(stderr, "Error: no file content\n"); | |
| 80 | err = 1; | |
| 81 | } | |
| 82 | cxBufferFree(buf); | |
| 83 | sqlite3_close(db); | |
| 84 | ||
| 85 | return err; | |
| 86 | } | |
| 87 | ||
| 88 | ||
| 89 | ||
| 90 | static DBUContext *ctx; | |
| 91 | static DBUConnection *conn; | |
| 92 | ||
|
33
106ff84c18ed
extend multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
93 | static DBUClass *country; |
|
25
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
94 | static DBUClass *address; |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
95 | static DBUClass *person; |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
96 | static DBUClass *role; |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
97 | |
|
33
106ff84c18ed
extend multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
98 | typedef struct Country { |
|
106ff84c18ed
extend multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
99 | int64_t country_id; |
|
106ff84c18ed
extend multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
100 | cxmutstr name; |
|
106ff84c18ed
extend multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
101 | } Country; |
|
106ff84c18ed
extend multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
102 | |
| 23 | 103 | typedef struct Address { |
| 104 | int64_t address_id; | |
| 105 | ||
| 106 | cxmutstr street; | |
| 107 | cxmutstr zip; | |
| 108 | cxmutstr city; | |
|
33
106ff84c18ed
extend multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
109 | |
|
106ff84c18ed
extend multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
110 | Country *country; |
| 23 | 111 | } Address; |
| 112 | ||
| 113 | typedef struct Person { | |
| 114 | int64_t person_id; | |
| 115 | ||
| 116 | cxmutstr name; | |
| 117 | cxmutstr email; | |
| 118 | int age; | |
| 119 | bool iscustomer; | |
| 120 | uint64_t hash; | |
| 121 | ||
| 122 | Address *address; | |
| 123 | ||
| 124 | CxList *roles; | |
| 125 | } Person; | |
| 126 | ||
| 127 | typedef struct Role { | |
| 128 | int64_t role_id; | |
| 129 | int64_t person_id; | |
| 130 | cxmutstr name; | |
| 131 | } Role; | |
| 132 | ||
| 133 | int init_db_tests(void) { | |
| 134 | ctx = dbuContextCreate(); | |
| 135 | ||
|
33
106ff84c18ed
extend multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
136 | country = dbuRegisterClass(ctx, "country", Country, country_id); |
|
106ff84c18ed
extend multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
137 | dbuClassAdd(country, Country, name); |
|
106ff84c18ed
extend multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
138 | |
|
25
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
139 | address = dbuRegisterClass(ctx, "address", Address, address_id); |
| 23 | 140 | dbuClassAdd(address, Address, street); |
| 141 | dbuClassAdd(address, Address, zip); | |
| 142 | dbuClassAdd(address, Address, city); | |
|
33
106ff84c18ed
extend multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
143 | dbuClassAddObj(address, "country_id", offsetof(Address, country), country); |
| 23 | 144 | |
|
25
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
145 | role = dbuRegisterClass(ctx, "role", Role, role_id); |
|
39
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
146 | dbuClassAdd(role, Role, person_id); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
147 | dbuClassAdd(role, Role, name); |
| 23 | 148 | |
|
25
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
149 | person = dbuRegisterClass(ctx, "person", Person, person_id); |
| 23 | 150 | dbuClassAdd(person, Person, name); |
| 151 | dbuClassAdd(person, Person, email); | |
| 152 | dbuClassAdd(person, Person, age); | |
| 153 | dbuClassAdd(person, Person, iscustomer); | |
| 154 | dbuClassAdd(person, Person, hash); | |
| 155 | dbuClassAddObj(person, "address_id", offsetof(Person, address), address); | |
| 156 | dbuClassAddCxLinkedList(person, "person_id", offsetof(Person, roles), role); | |
| 157 | ||
| 158 | dbuClassAddForeignKey(role, Role, person_id, person); | |
| 159 | dbuClassAdd(role, Role, name); | |
| 160 | ||
| 161 | return 0; | |
| 162 | } | |
| 163 | ||
| 164 | void cleanup_db_tests(void) { | |
| 165 | if(conn) { | |
| 166 | dbuConnectionFree(conn); | |
| 167 | } | |
| 168 | dbuContextFree(ctx); | |
| 169 | } | |
| 170 | ||
| 171 | CX_TEST(testSqliteConnection) { | |
| 172 | CX_TEST_DO { | |
| 173 | conn = dbuSQLiteConnection(TEST_DB); | |
| 174 | CX_TEST_ASSERT(conn); | |
| 175 | CX_TEST_ASSERT(dbuConnectionIsActive(conn)); | |
| 176 | } | |
| 177 | } | |
| 178 | ||
| 179 | CX_TEST(testSingleValueQuery) { | |
| 180 | CX_TEST_DO { | |
| 181 | CX_TEST_ASSERT(conn); | |
| 182 | ||
| 183 | DBUQuery *q = dbuConnectionQuery(conn, NULL); | |
| 184 | CX_TEST_ASSERT(q); | |
| 185 | CX_TEST_ASSERT(dbuQuerySetSQL(q, "select 12;") == 0); | |
| 186 | CX_TEST_ASSERT(dbuQueryExec(q) == 0); | |
| 187 | ||
| 188 | DBUResult *r = dbuQueryGetResult(q); | |
| 189 | CX_TEST_ASSERT(r); | |
| 190 | int value; | |
| 191 | CX_TEST_ASSERT(dbuResultAsValue(r, &value) == 0); | |
| 192 | CX_TEST_ASSERT(value == 12); | |
| 193 | ||
| 194 | dbuQueryFree(q); | |
| 195 | ||
| 196 | } | |
| 197 | } | |
|
24
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
198 | |
|
48
deb6c4b8cf9d
rename dbuSqlExec to dbuSqlExecQuery, add new dbuSqlExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
199 | CX_TEST(testSqlExecQuery) { |
|
24
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
200 | CX_TEST_DO { |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
201 | CX_TEST_ASSERT(conn); |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
202 | |
|
48
deb6c4b8cf9d
rename dbuSqlExec to dbuSqlExecQuery, add new dbuSqlExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
203 | DBUResult *r = dbuSqlExecQuery(conn, NULL, "select email from person where name = 'alice';"); |
|
24
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
204 | CX_TEST_ASSERT(r); |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
205 | cxmutstr value; |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
206 | CX_TEST_ASSERT(dbuResultAsValue(r, &value) == 0); |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
207 | CX_TEST_ASSERT(!cx_strcmp(value, "alice@example.com")); |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
208 | free(value.ptr); |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
209 | } |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
210 | } |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
211 | |
|
48
deb6c4b8cf9d
rename dbuSqlExec to dbuSqlExecQuery, add new dbuSqlExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
212 | CX_TEST(testSqlExecQueryParam) { |
|
24
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
213 | CX_TEST_DO { |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
214 | CX_TEST_ASSERT(conn); |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
215 | |
|
48
deb6c4b8cf9d
rename dbuSqlExec to dbuSqlExecQuery, add new dbuSqlExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
216 | DBUResult *r = dbuSqlExecQueryParam(conn, NULL, "select email from person where name = ?;", "alice"); |
|
24
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
217 | CX_TEST_ASSERT(r); |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
218 | cxmutstr value; |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
219 | CX_TEST_ASSERT(dbuResultAsValue(r, &value) == 0); |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
220 | CX_TEST_ASSERT(!cx_strcmp(value, "alice@example.com")); |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
221 | free(value.ptr); |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
222 | |
|
48
deb6c4b8cf9d
rename dbuSqlExec to dbuSqlExecQuery, add new dbuSqlExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
223 | r = dbuSqlExecQueryParam(conn, NULL, "select name from person where hash = ?;", 987654321); |
|
24
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
224 | CX_TEST_ASSERT(r); |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
225 | CX_TEST_ASSERT(dbuResultAsValue(r, &value) == 0); |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
226 | CX_TEST_ASSERT(!cx_strcmp(value, "bob")); |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
227 | free(value.ptr); |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
228 | } |
|
df671b62538e
add dbuSqlExec API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
229 | } |
|
25
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
230 | |
|
51
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
231 | CX_TEST(testSqlExec) { |
|
49
34c723ed7190
add testSqlExecParam
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
232 | CX_TEST_DO { |
|
51
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
233 | CX_TEST_ASSERT(conn); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
234 | |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
235 | int t1 = dbuSqlExec(conn, "create table ExecTest1(a int);"); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
236 | CX_TEST_ASSERT(t1 == 0); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
237 | |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
238 | int t2 = dbuSqlExec(conn, "insert into ExecTest1(a) values (1);"); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
239 | CX_TEST_ASSERT(t2 == 0); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
240 | |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
241 | int t3 = dbuSqlExec(conn, "drop table ExecTest1;"); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
242 | CX_TEST_ASSERT(t3 == 0); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
243 | |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
244 | int fail = dbuSqlExec(conn, "select * from Fail;"); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
245 | CX_TEST_ASSERT(fail != 0); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
246 | |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
247 | |
|
49
34c723ed7190
add testSqlExecParam
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
248 | CX_TEST_ASSERT(dbuSqlExec(conn, "PRAGMA foreign_keys = ON;") == 0); |
|
34c723ed7190
add testSqlExecParam
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
249 | CX_TEST_ASSERT(dbuSqlExec(conn, |
|
34c723ed7190
add testSqlExecParam
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
250 | "create table ExecTest3( " |
|
34c723ed7190
add testSqlExecParam
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
251 | "test1_id integer primary key autoincrement, " |
|
51
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
252 | "value int, " |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
253 | "str text);") == 0); |
|
49
34c723ed7190
add testSqlExecParam
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
254 | CX_TEST_ASSERT(dbuSqlExec(conn, |
|
34c723ed7190
add testSqlExecParam
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
255 | "create table ExecTest4( " |
|
34c723ed7190
add testSqlExecParam
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
256 | "test2_id integer primary key autoincrement, " |
|
34c723ed7190
add testSqlExecParam
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
257 | "exectest1_id int references ExecTest3(test1_id), " |
|
34c723ed7190
add testSqlExecParam
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
258 | "value int);") == 0); |
|
34c723ed7190
add testSqlExecParam
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
259 | CX_TEST_ASSERT(dbuSqlExec(conn, "insert into ExecTest3(value) values (123);") == 0); |
|
34c723ed7190
add testSqlExecParam
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
260 | |
|
34c723ed7190
add testSqlExecParam
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
261 | // fail test |
|
34c723ed7190
add testSqlExecParam
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
262 | CX_TEST_ASSERT(dbuSqlExec(conn, "insert into ExecTest4(exectest1_id, value) values (-999, 123);") != 0); |
|
51
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
263 | |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
264 | // param tests |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
265 | CX_TEST_ASSERT(dbuSqlExecParamInt32(conn, "insert into ExecTest3(value) values (?);", 11) == 0); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
266 | CX_TEST_ASSERT(dbuSqlExecParamUInt32(conn, "insert into ExecTest3(value) values (?);", 12) == 0); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
267 | CX_TEST_ASSERT(dbuSqlExecParamInt64(conn, "insert into ExecTest3(value) values (?);", 4000000000L) == 0); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
268 | CX_TEST_ASSERT(dbuSqlExecParamUInt64(conn, "insert into ExecTest3(value) values (?);", 5000000000L) == 0); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
269 | CX_TEST_ASSERT(dbuSqlExecParamString(conn, "insert into ExecTest3(str) values (?);", "str1") == 0); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
270 | CX_TEST_ASSERT(dbuSqlExecParamCxString(conn, "insert into ExecTest3(str) values (?);", cx_str("str2")) == 0); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
271 | CX_TEST_ASSERT(dbuSqlExecParamCxMutStr(conn, "insert into ExecTest3(str) values (?);", cx_mutstr("str3")) == 0); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
272 | |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
273 | // param macro test |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
274 | CX_TEST_ASSERT(dbuSqlExecParam(conn, "insert into ExecTest3(value) values (?);", 111) == 0); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
275 | CX_TEST_ASSERT(dbuSqlExecParam(conn, "insert into ExecTest3(str) values (?);", "str4") == 0); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
276 | CX_TEST_ASSERT(dbuSqlExecParam(conn, "insert into ExecTest3(str) values (?);", cx_str("str5")) == 0); |
|
e3163dc41a80
fix param type in dbuSqlExecParamUInt64/dbuSqlExecQueryParamUInt64, remove dbuConnectionExec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
277 | CX_TEST_ASSERT(dbuSqlExecParam(conn, "insert into ExecTest3(str) values (?);", cx_mutstr("str6")) == 0); |
|
49
34c723ed7190
add testSqlExecParam
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
278 | } |
|
34c723ed7190
add testSqlExecParam
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
279 | } |
|
34c723ed7190
add testSqlExecParam
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
280 | |
|
25
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
281 | CX_TEST(testSingleTableQuery) { |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
282 | CxMempool *mp = cxMempoolCreateSimple(64); |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
283 | |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
284 | CX_TEST_DO { |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
285 | DBUQuery *query = dbuQueryCreate(conn, mp->allocator, "select * from address order by street;"); |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
286 | DBUObjectBuilder *builder = dbuObjectBuilder(address, query, mp->allocator); |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
287 | CxList *adr = dbuObjectBuilderGetList(builder); |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
288 | |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
289 | CX_TEST_ASSERT(adr); |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
290 | CX_TEST_ASSERT(cxListSize(adr) == 2); |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
291 | |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
292 | Address *a0 = cxListAt(adr, 0); |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
293 | Address *a1 = cxListAt(adr, 1); |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
294 | CX_TEST_ASSERT(a0); |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
295 | CX_TEST_ASSERT(a1); |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
296 | CX_TEST_ASSERT(!cx_strcmp(a0->street, "street 1")); |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
297 | CX_TEST_ASSERT(!cx_strcmp(a1->street, "street 2")); |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
298 | CX_TEST_ASSERT(!cx_strcmp(a0->zip, "12343")); |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
299 | CX_TEST_ASSERT(!cx_strcmp(a1->zip, "23456")); |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
300 | CX_TEST_ASSERT(!cx_strcmp(a0->city, "city 17")); |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
301 | CX_TEST_ASSERT(!cx_strcmp(a1->city, "city 18")); |
|
26
dc36aa437249
implement json primitives serialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
302 | |
|
dc36aa437249
implement json primitives serialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
303 | dbuObjectBuilderDestroy(builder); |
|
25
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
304 | } |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
305 | |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
306 | cxMempoolFree(mp); |
|
0bb91d1f9bba
add single table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
307 | } |
|
32
6bd927c1cb11
add test for multi table queries
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
308 | |
|
39
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
309 | CX_TEST_SUBROUTINE(verifyMultiTableResult, CxList *persons, bool verify_address) { |
|
37
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
310 | CX_TEST_ASSERT(persons); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
311 | CX_TEST_ASSERT(cxListSize(persons) == 2); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
312 | |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
313 | Person *p0 = cxListAt(persons, 0); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
314 | Person *p1 = cxListAt(persons, 1); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
315 | |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
316 | CX_TEST_ASSERT(p0); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
317 | CX_TEST_ASSERT(p1); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
318 | CX_TEST_ASSERT(!cx_strcmp(p0->name, "alice")); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
319 | CX_TEST_ASSERT(!cx_strcmp(p1->name, "bob")); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
320 | CX_TEST_ASSERT(!cx_strcmp(p0->email, "alice@example.com")); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
321 | CX_TEST_ASSERT(!cx_strcmp(p1->email, "bob@example.com")); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
322 | CX_TEST_ASSERT(p0->age == 30); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
323 | CX_TEST_ASSERT(p1->age == 25); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
324 | CX_TEST_ASSERT(p0->iscustomer == 0); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
325 | CX_TEST_ASSERT(p1->iscustomer == 1); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
326 | CX_TEST_ASSERT(p0->hash == 123456789); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
327 | CX_TEST_ASSERT(p1->hash == 987654321); |
|
39
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
328 | |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
329 | if(verify_address) { |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
330 | CX_TEST_ASSERT(p0->address != NULL); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
331 | CX_TEST_ASSERT(p1->address != NULL); |
|
37
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
332 | |
|
39
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
333 | CX_TEST_ASSERT(!cx_strcmp(p0->address->street, "street 1")); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
334 | CX_TEST_ASSERT(!cx_strcmp(p1->address->street, "street 2")); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
335 | CX_TEST_ASSERT(!cx_strcmp(p0->address->zip, "12343")); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
336 | CX_TEST_ASSERT(!cx_strcmp(p1->address->zip, "23456")); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
337 | CX_TEST_ASSERT(!cx_strcmp(p0->address->city, "city 17")); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
338 | CX_TEST_ASSERT(!cx_strcmp(p1->address->city, "city 18")); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
339 | } |
|
37
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
340 | } |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
341 | |
|
32
6bd927c1cb11
add test for multi table queries
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
342 | CX_TEST(testMultiTableQuery) { |
|
6bd927c1cb11
add test for multi table queries
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
343 | CxMempool *mp = cxMempoolCreateSimple(64); |
|
6bd927c1cb11
add test for multi table queries
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
344 | |
|
6bd927c1cb11
add test for multi table queries
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
345 | CX_TEST_DO { |
|
40
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
346 | // select persons + addresses, a.address_id as __address__address_id (table separator) |
|
32
6bd927c1cb11
add test for multi table queries
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
347 | const char *sql1 = "select p.*, a.address_id as [__address__address_id], a.street, a.zip, a.city from Person p inner join Address a on p.address_id = a.address_id order by p.person_id;"; |
|
6bd927c1cb11
add test for multi table queries
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
348 | DBUQuery *query = dbuQueryCreate(conn, mp->allocator, sql1); |
|
6bd927c1cb11
add test for multi table queries
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
349 | DBUObjectBuilder *builder = dbuObjectBuilder(person, query, mp->allocator); |
|
6bd927c1cb11
add test for multi table queries
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
350 | CxList *persons = dbuObjectBuilderGetList(builder); |
|
6bd927c1cb11
add test for multi table queries
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
351 | |
|
39
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
352 | CX_TEST_CALL_SUBROUTINE(verifyMultiTableResult, persons, true); |
|
32
6bd927c1cb11
add test for multi table queries
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
353 | |
|
33
106ff84c18ed
extend multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
354 | dbuObjectBuilderDestroy(builder); |
|
32
6bd927c1cb11
add test for multi table queries
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
355 | } |
|
6bd927c1cb11
add test for multi table queries
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
356 | |
|
6bd927c1cb11
add test for multi table queries
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
357 | cxMempoolFree(mp); |
|
6bd927c1cb11
add test for multi table queries
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
358 | } |
|
6bd927c1cb11
add test for multi table queries
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
359 | |
|
36
93753b036d9f
add additional multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
360 | CX_TEST(testMultiTableQuery1) { |
|
93753b036d9f
add additional multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
361 | CxMempool *mp = cxMempoolCreateSimple(64); |
|
93753b036d9f
add additional multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
362 | |
|
93753b036d9f
add additional multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
363 | CX_TEST_DO { |
|
40
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
364 | // select persons + addresses, NULL as __address (table seprator) |
|
36
93753b036d9f
add additional multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
365 | 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;"; |
|
93753b036d9f
add additional multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
366 | DBUQuery *query = dbuQueryCreate(conn, mp->allocator, sql1); |
|
93753b036d9f
add additional multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
367 | DBUObjectBuilder *builder = dbuObjectBuilder(person, query, mp->allocator); |
|
93753b036d9f
add additional multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
368 | CxList *persons = dbuObjectBuilderGetList(builder); |
|
93753b036d9f
add additional multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
369 | |
|
39
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
370 | CX_TEST_CALL_SUBROUTINE(verifyMultiTableResult, persons, true); |
|
36
93753b036d9f
add additional multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
371 | |
|
93753b036d9f
add additional multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
372 | dbuObjectBuilderDestroy(builder); |
|
93753b036d9f
add additional multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
373 | } |
|
93753b036d9f
add additional multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
374 | |
|
93753b036d9f
add additional multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
375 | cxMempoolFree(mp); |
|
93753b036d9f
add additional multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
376 | } |
|
93753b036d9f
add additional multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
377 | |
|
37
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
378 | CX_TEST_SUBROUTINE(verifyMultiTableResultCountry, CxList *persons) { |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
379 | Person *p0 = cxListAt(persons, 0); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
380 | Person *p1 = cxListAt(persons, 1); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
381 | CX_TEST_ASSERT(p0 && p1); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
382 | |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
383 | CX_TEST_ASSERT(p0->address->country); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
384 | CX_TEST_ASSERT(p1->address->country); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
385 | CX_TEST_ASSERT(!cx_strcmp(p0->address->country->name, "Germany")); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
386 | CX_TEST_ASSERT(!cx_strcmp(p1->address->country->name, "Germany")); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
387 | } |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
388 | |
|
34
0d2291e77d32
split multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
389 | CX_TEST(testMultiTableQuery2) { |
|
0d2291e77d32
split multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
390 | CxMempool *mp = cxMempoolCreateSimple(64); |
|
0d2291e77d32
split multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
391 | |
|
0d2291e77d32
split multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
392 | CX_TEST_DO { |
|
40
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
393 | // select persons, addresses and countries |
|
34
0d2291e77d32
split multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
394 | const char *sql2 = "select p.*, " |
|
0d2291e77d32
split multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
395 | "a.address_id as [__address__address_id], a.street, a.zip, a.city, " |
|
0d2291e77d32
split multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
396 | "c.country_id as [__country__country_id], c.name " |
|
0d2291e77d32
split multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
397 | "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 " |
|
0d2291e77d32
split multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
398 | "order by p.person_id;"; |
|
0d2291e77d32
split multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
399 | DBUQuery *query = dbuQueryCreate(conn, mp->allocator, sql2); |
|
0d2291e77d32
split multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
400 | DBUObjectBuilder *builder = dbuObjectBuilder(person, query, mp->allocator); |
|
0d2291e77d32
split multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
401 | CxList *persons = dbuObjectBuilderGetList(builder); |
|
0d2291e77d32
split multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
402 | |
|
39
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
403 | CX_TEST_CALL_SUBROUTINE(verifyMultiTableResult, persons, true); |
|
37
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
404 | CX_TEST_CALL_SUBROUTINE(verifyMultiTableResultCountry, persons); |
|
35
16731869cc05
fix that NULL as __tabname did not work as table separator in queries
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
34
diff
changeset
|
405 | |
|
34
0d2291e77d32
split multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
406 | dbuObjectBuilderDestroy(builder); |
|
0d2291e77d32
split multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
407 | } |
|
0d2291e77d32
split multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
408 | |
|
0d2291e77d32
split multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
409 | cxMempoolFree(mp); |
|
0d2291e77d32
split multi table query test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
410 | } |
|
37
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
411 | |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
412 | CX_TEST(testMultiTableQueryUnknownResult1) { |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
413 | CxMempool *mp = cxMempoolCreateSimple(64); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
414 | |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
415 | CX_TEST_DO { |
|
40
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
416 | // select persons, addresses and countries |
|
37
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
417 | const char *sql2 = "select p.*, 'unknown1' as unknown1, " |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
418 | "a.address_id as [__address__address_id], a.street, 'unknown2' as unknown2, a.zip, 123 as unknown3, a.city, " |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
419 | "NULL as [__unknowntab], 456 as unknown_4, " |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
420 | "c.country_id as [__country__country_id], c.name " |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
421 | "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 " |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
422 | "order by p.person_id;"; |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
423 | DBUQuery *query = dbuQueryCreate(conn, mp->allocator, sql2); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
424 | DBUObjectBuilder *builder = dbuObjectBuilder(person, query, mp->allocator); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
425 | CxList *persons = dbuObjectBuilderGetList(builder); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
426 | |
|
39
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
427 | CX_TEST_CALL_SUBROUTINE(verifyMultiTableResult, persons, true); |
|
37
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
428 | CX_TEST_CALL_SUBROUTINE(verifyMultiTableResultCountry, persons); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
429 | |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
430 | dbuObjectBuilderDestroy(builder); |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
431 | } |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
432 | |
|
81dfb9a43a38
add test for queries with unknown columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
433 | cxMempoolFree(mp); |
|
39
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
434 | } |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
435 | |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
436 | CX_TEST_SUBROUTINE(verifyPersonRoles, CxList *persons) { |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
437 | Person *p0 = cxListAt(persons, 0); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
438 | Person *p1 = cxListAt(persons, 1); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
439 | CX_TEST_ASSERT(p0 && p1); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
440 | |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
441 | CX_TEST_ASSERT(cxListSize(p0->roles) == 3); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
442 | CX_TEST_ASSERT(cxListSize(p1->roles) == 1); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
443 | |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
444 | Role *r0 = cxListAt(p0->roles, 0); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
445 | Role *r1 = cxListAt(p0->roles, 1); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
446 | Role *r2 = cxListAt(p0->roles, 2); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
447 | |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
448 | Role *p1_r0 = cxListAt(p1->roles, 0); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
449 | |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
450 | CX_TEST_ASSERT(!cx_strcmp(r0->name, "finance")); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
451 | CX_TEST_ASSERT(!cx_strcmp(r1->name, "dev")); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
452 | CX_TEST_ASSERT(!cx_strcmp(r2->name, "manager")); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
453 | |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
454 | CX_TEST_ASSERT(!cx_strcmp(p1_r0->name, "extern")); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
455 | } |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
456 | |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
457 | CX_TEST(testQuerySubListDense1) { |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
458 | CxMempool *mp = cxMempoolCreateSimple(64); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
459 | |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
460 | CX_TEST_DO { |
|
40
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
461 | // select persons + a list of roles per person |
|
39
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
462 | const char *sql1 = |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
463 | "select p.*, r.role_id as [__role__role_id], r.person_id, r.name from Person p inner join Role r on p.person_id = r.person_id order by p.person_id;"; |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
464 | DBUQuery *query = dbuQueryCreate(conn, mp->allocator, sql1); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
465 | DBUObjectBuilder *builder = dbuObjectBuilder(person, query, mp->allocator); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
466 | dbuObjectBuilderSetDenseResult(builder, true); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
467 | CxList *persons = dbuObjectBuilderGetList(builder); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
468 | |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
469 | CX_TEST_CALL_SUBROUTINE(verifyMultiTableResult, persons, false); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
470 | CX_TEST_CALL_SUBROUTINE(verifyPersonRoles, persons); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
471 | |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
472 | dbuObjectBuilderDestroy(builder); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
473 | } |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
474 | |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
475 | cxMempoolFree(mp); |
|
cefc18b7a9d1
add dense result test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
476 | } |
|
40
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
477 | |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
478 | CX_TEST(testQuerySubListDenseWithMultiTable1) { |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
479 | CxMempool *mp = cxMempoolCreateSimple(64); |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
480 | |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
481 | CX_TEST_DO { |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
482 | const char *sql1 = |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
483 | "select p.*, NULL as [__address], a.*, r.role_id as [__role__role_id], r.person_id, r.name " |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
484 | "from Person p inner join Address a on p.address_id = a.address_id " |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
485 | "inner join Role r on p.person_id = r.person_id order by p.person_id;"; |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
486 | DBUQuery *query = dbuQueryCreate(conn, mp->allocator, sql1); |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
487 | DBUObjectBuilder *builder = dbuObjectBuilder(person, query, mp->allocator); |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
488 | dbuObjectBuilderSetDenseResult(builder, true); |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
489 | CxList *persons = dbuObjectBuilderGetList(builder); |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
490 | |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
491 | CX_TEST_CALL_SUBROUTINE(verifyMultiTableResult, persons, true); // also verify address |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
492 | CX_TEST_CALL_SUBROUTINE(verifyPersonRoles, persons); |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
493 | |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
494 | dbuObjectBuilderDestroy(builder); |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
495 | } |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
496 | |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
497 | cxMempoolFree(mp); |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
498 | } |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
499 | |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
500 | CX_TEST(testQuerySubListDenseWithMultiTable2) { |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
501 | CxMempool *mp = cxMempoolCreateSimple(64); |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
502 | |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
503 | // Same as testQuerySubListDenseWithMultiTable1, but with a different column order |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
504 | // person, role, address |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
505 | |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
506 | CX_TEST_DO { |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
507 | const char *sql1 = |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
508 | "select p.*, r.role_id as [__role__role_id], r.person_id, r.name, NULL as [__address], a.* " |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
509 | "from Person p inner join Address a on p.address_id = a.address_id " |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
510 | "inner join Role r on p.person_id = r.person_id order by p.person_id;"; |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
511 | DBUQuery *query = dbuQueryCreate(conn, mp->allocator, sql1); |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
512 | DBUObjectBuilder *builder = dbuObjectBuilder(person, query, mp->allocator); |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
513 | dbuObjectBuilderSetDenseResult(builder, true); |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
514 | CxList *persons = dbuObjectBuilderGetList(builder); |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
515 | |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
516 | CX_TEST_CALL_SUBROUTINE(verifyMultiTableResult, persons, true); // also verify address |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
517 | CX_TEST_CALL_SUBROUTINE(verifyPersonRoles, persons); |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
518 | |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
519 | dbuObjectBuilderDestroy(builder); |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
520 | } |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
521 | |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
522 | cxMempoolFree(mp); |
|
0b6bc15d022e
add tests for selecting multible tables + list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
523 | } |