| 212 dbuQueryFree(q); |
212 dbuQueryFree(q); |
| 213 |
213 |
| 214 } |
214 } |
| 215 } |
215 } |
| 216 |
216 |
| 217 CX_TEST(testSqlExec) { |
217 CX_TEST(testSqlExecQuery) { |
| 218 CX_TEST_DO { |
218 CX_TEST_DO { |
| 219 CX_TEST_ASSERT(conn); |
219 CX_TEST_ASSERT(conn); |
| 220 |
220 |
| 221 DBUResult *r = dbuSqlExec(conn, NULL, "select email from person where name = 'alice';"); |
221 DBUResult *r = dbuSqlExecQuery(conn, NULL, "select email from person where name = 'alice';"); |
| 222 CX_TEST_ASSERT(r); |
222 CX_TEST_ASSERT(r); |
| 223 cxmutstr value; |
223 cxmutstr value; |
| 224 CX_TEST_ASSERT(dbuResultAsValue(r, &value) == 0); |
224 CX_TEST_ASSERT(dbuResultAsValue(r, &value) == 0); |
| 225 CX_TEST_ASSERT(!cx_strcmp(value, "alice@example.com")); |
225 CX_TEST_ASSERT(!cx_strcmp(value, "alice@example.com")); |
| 226 free(value.ptr); |
226 free(value.ptr); |
| 227 } |
227 } |
| 228 } |
228 } |
| 229 |
229 |
| 230 CX_TEST(testSqlExecParam) { |
230 CX_TEST(testSqlExecQueryParam) { |
| 231 CX_TEST_DO { |
231 CX_TEST_DO { |
| 232 CX_TEST_ASSERT(conn); |
232 CX_TEST_ASSERT(conn); |
| 233 |
233 |
| 234 DBUResult *r = dbuSqlExecParam(conn, NULL, "select email from person where name = ?;", "alice"); |
234 DBUResult *r = dbuSqlExecQueryParam(conn, NULL, "select email from person where name = ?;", "alice"); |
| 235 CX_TEST_ASSERT(r); |
235 CX_TEST_ASSERT(r); |
| 236 cxmutstr value; |
236 cxmutstr value; |
| 237 CX_TEST_ASSERT(dbuResultAsValue(r, &value) == 0); |
237 CX_TEST_ASSERT(dbuResultAsValue(r, &value) == 0); |
| 238 CX_TEST_ASSERT(!cx_strcmp(value, "alice@example.com")); |
238 CX_TEST_ASSERT(!cx_strcmp(value, "alice@example.com")); |
| 239 free(value.ptr); |
239 free(value.ptr); |
| 240 |
240 |
| 241 r = dbuSqlExecParam(conn, NULL, "select name from person where hash = ?;", 987654321); |
241 r = dbuSqlExecQueryParam(conn, NULL, "select name from person where hash = ?;", 987654321); |
| 242 CX_TEST_ASSERT(r); |
242 CX_TEST_ASSERT(r); |
| 243 CX_TEST_ASSERT(dbuResultAsValue(r, &value) == 0); |
243 CX_TEST_ASSERT(dbuResultAsValue(r, &value) == 0); |
| 244 CX_TEST_ASSERT(!cx_strcmp(value, "bob")); |
244 CX_TEST_ASSERT(!cx_strcmp(value, "bob")); |
| 245 free(value.ptr); |
245 free(value.ptr); |
| 246 } |
246 } |