| 174 CX_TEST_ASSERT(conn); |
174 CX_TEST_ASSERT(conn); |
| 175 CX_TEST_ASSERT(dbuConnectionIsActive(conn)); |
175 CX_TEST_ASSERT(dbuConnectionIsActive(conn)); |
| 176 } |
176 } |
| 177 } |
177 } |
| 178 |
178 |
| 179 CX_TEST(testConnectionExec) { |
|
| 180 CX_TEST_DO { |
|
| 181 CX_TEST_ASSERT(conn); |
|
| 182 |
|
| 183 int t1 = dbuConnectionExec(conn, "create table ExecTest1(a int);"); |
|
| 184 CX_TEST_ASSERT(t1 == 0); |
|
| 185 |
|
| 186 int t2 = dbuConnectionExec(conn, "insert into ExecTest1(a) values (1);"); |
|
| 187 CX_TEST_ASSERT(t2 == 0); |
|
| 188 |
|
| 189 int t3 = dbuConnectionExec(conn, "drop table ExecTest1;"); |
|
| 190 CX_TEST_ASSERT(t3 == 0); |
|
| 191 |
|
| 192 int fail = dbuConnectionExec(conn, "select * from Fail;"); |
|
| 193 CX_TEST_ASSERT(fail != 0); |
|
| 194 } |
|
| 195 } |
|
| 196 |
|
| 197 CX_TEST(testSingleValueQuery) { |
179 CX_TEST(testSingleValueQuery) { |
| 198 CX_TEST_DO { |
180 CX_TEST_DO { |
| 199 CX_TEST_ASSERT(conn); |
181 CX_TEST_ASSERT(conn); |
| 200 |
182 |
| 201 DBUQuery *q = dbuConnectionQuery(conn, NULL); |
183 DBUQuery *q = dbuConnectionQuery(conn, NULL); |
| 244 CX_TEST_ASSERT(!cx_strcmp(value, "bob")); |
226 CX_TEST_ASSERT(!cx_strcmp(value, "bob")); |
| 245 free(value.ptr); |
227 free(value.ptr); |
| 246 } |
228 } |
| 247 } |
229 } |
| 248 |
230 |
| 249 CX_TEST(testSqlExecParam) { |
231 CX_TEST(testSqlExec) { |
| 250 CX_TEST_DO { |
232 CX_TEST_DO { |
| |
233 CX_TEST_ASSERT(conn); |
| |
234 |
| |
235 int t1 = dbuSqlExec(conn, "create table ExecTest1(a int);"); |
| |
236 CX_TEST_ASSERT(t1 == 0); |
| |
237 |
| |
238 int t2 = dbuSqlExec(conn, "insert into ExecTest1(a) values (1);"); |
| |
239 CX_TEST_ASSERT(t2 == 0); |
| |
240 |
| |
241 int t3 = dbuSqlExec(conn, "drop table ExecTest1;"); |
| |
242 CX_TEST_ASSERT(t3 == 0); |
| |
243 |
| |
244 int fail = dbuSqlExec(conn, "select * from Fail;"); |
| |
245 CX_TEST_ASSERT(fail != 0); |
| |
246 |
| |
247 |
| 251 CX_TEST_ASSERT(dbuSqlExec(conn, "PRAGMA foreign_keys = ON;") == 0); |
248 CX_TEST_ASSERT(dbuSqlExec(conn, "PRAGMA foreign_keys = ON;") == 0); |
| 252 CX_TEST_ASSERT(dbuSqlExec(conn, |
249 CX_TEST_ASSERT(dbuSqlExec(conn, |
| 253 "create table ExecTest3( " |
250 "create table ExecTest3( " |
| 254 "test1_id integer primary key autoincrement, " |
251 "test1_id integer primary key autoincrement, " |
| 255 "value int);") == 0); |
252 "value int, " |
| |
253 "str text);") == 0); |
| 256 CX_TEST_ASSERT(dbuSqlExec(conn, |
254 CX_TEST_ASSERT(dbuSqlExec(conn, |
| 257 "create table ExecTest4( " |
255 "create table ExecTest4( " |
| 258 "test2_id integer primary key autoincrement, " |
256 "test2_id integer primary key autoincrement, " |
| 259 "exectest1_id int references ExecTest3(test1_id), " |
257 "exectest1_id int references ExecTest3(test1_id), " |
| 260 "value int);") == 0); |
258 "value int);") == 0); |
| 261 CX_TEST_ASSERT(dbuSqlExec(conn, "insert into ExecTest3(value) values (123);") == 0); |
259 CX_TEST_ASSERT(dbuSqlExec(conn, "insert into ExecTest3(value) values (123);") == 0); |
| 262 |
260 |
| 263 // fail test |
261 // fail test |
| 264 CX_TEST_ASSERT(dbuSqlExec(conn, "insert into ExecTest4(exectest1_id, value) values (-999, 123);") != 0); |
262 CX_TEST_ASSERT(dbuSqlExec(conn, "insert into ExecTest4(exectest1_id, value) values (-999, 123);") != 0); |
| |
263 |
| |
264 // param tests |
| |
265 CX_TEST_ASSERT(dbuSqlExecParamInt32(conn, "insert into ExecTest3(value) values (?);", 11) == 0); |
| |
266 CX_TEST_ASSERT(dbuSqlExecParamUInt32(conn, "insert into ExecTest3(value) values (?);", 12) == 0); |
| |
267 CX_TEST_ASSERT(dbuSqlExecParamInt64(conn, "insert into ExecTest3(value) values (?);", 4000000000L) == 0); |
| |
268 CX_TEST_ASSERT(dbuSqlExecParamUInt64(conn, "insert into ExecTest3(value) values (?);", 5000000000L) == 0); |
| |
269 CX_TEST_ASSERT(dbuSqlExecParamString(conn, "insert into ExecTest3(str) values (?);", "str1") == 0); |
| |
270 CX_TEST_ASSERT(dbuSqlExecParamCxString(conn, "insert into ExecTest3(str) values (?);", cx_str("str2")) == 0); |
| |
271 CX_TEST_ASSERT(dbuSqlExecParamCxMutStr(conn, "insert into ExecTest3(str) values (?);", cx_mutstr("str3")) == 0); |
| |
272 |
| |
273 // param macro test |
| |
274 CX_TEST_ASSERT(dbuSqlExecParam(conn, "insert into ExecTest3(value) values (?);", 111) == 0); |
| |
275 CX_TEST_ASSERT(dbuSqlExecParam(conn, "insert into ExecTest3(str) values (?);", "str4") == 0); |
| |
276 CX_TEST_ASSERT(dbuSqlExecParam(conn, "insert into ExecTest3(str) values (?);", cx_str("str5")) == 0); |
| |
277 CX_TEST_ASSERT(dbuSqlExecParam(conn, "insert into ExecTest3(str) values (?);", cx_mutstr("str6")) == 0); |
| 265 } |
278 } |
| 266 } |
279 } |
| 267 |
280 |
| 268 CX_TEST(testSingleTableQuery) { |
281 CX_TEST(testSingleTableQuery) { |
| 269 CxMempool *mp = cxMempoolCreateSimple(64); |
282 CxMempool *mp = cxMempoolCreateSimple(64); |