Permalink
Browse files

[SQLite3] Fix the case where a query returns zero results

  • Loading branch information...
1 parent a2e201f commit 81a1a0b7ef511e53871faf9a6d06e101b0372a4e @Whiteknight committed Apr 18, 2012
Showing with 15 additions and 7 deletions.
  1. +11 −6 sqlite3/pmc/sqlite3datatable.pmc
  2. +4 −1 sqlite3/pmc/sqlite3dbcontext.pmc
@@ -12,6 +12,8 @@ pmclass SQLite3DataTable dynpmc auto_attrs provides iterator {
VTABLE void init()
{
+ PMC * const rows = Parrot_pmc_new(INTERP, enum_class_ResizablePMCArray);
+ PARROT_SQLITE3DATATABLE(SELF)->rows = rows;
PObj_custom_mark_SET(SELF);
}
@@ -20,11 +22,7 @@ pmclass SQLite3DataTable dynpmc auto_attrs provides iterator {
Hash * const colnames = (Hash*)rawptr;
if (!colnames)
Parrot_ex_throw_from_c_args(INTERP, NULL, 0, "SQLite: Null column names hash");
- else {
- PMC * const rows = Parrot_pmc_new(INTERP, enum_class_ResizablePMCArray);
- PARROT_SQLITE3DATATABLE(SELF)->colnames = colnames;
- PARROT_SQLITE3DATATABLE(SELF)->rows = rows;
- }
+ PARROT_SQLITE3DATATABLE(SELF)->colnames = colnames;
}
VTABLE void mark()
@@ -36,6 +34,12 @@ pmclass SQLite3DataTable dynpmc auto_attrs provides iterator {
Parrot_gc_mark_PMC_alive(INTERP, attrs->rows);
}
+ VTABLE INTVAL elements()
+ {
+ PMC * const rows = PARROT_SQLITE3DATATABLE(SELF)->rows;
+ return VTABLE_elements(INTERP, rows);
+ }
+
VTABLE void push_pmc(PMC * row)
{
VTABLE_push_pmc(INTERP, PARROT_SQLITE3DATATABLE(SELF)->rows, row);
@@ -53,7 +57,8 @@ pmclass SQLite3DataTable dynpmc auto_attrs provides iterator {
VTABLE PMC *get_iter()
{
- return Parrot_pmc_new_init(INTERP, enum_class_ArrayIterator, PARROT_SQLITE3DATATABLE(SELF)->rows);
+ PMC * const rows = PARROT_SQLITE3DATATABLE(SELF)->rows;
+ return Parrot_pmc_new_init(INTERP, enum_class_ArrayIterator, rows);
}
VTABLE void *get_pointer_keyed(PMC * row)
@@ -65,12 +65,15 @@ pmclass SQLite3DbContext dynpmc auto_attrs {
METHOD query(STRING * query) {
sqlite3 * const db = GET_DB(SELF);
SQLite3_cb_args * args;
- PMC * const table = Parrot_pmc_new(INTERP, SQLite3DataTable_type);
+ PMC * table = Parrot_pmc_new(INTERP, SQLite3DataTable_type);
int rc;
char * err_msg = NULL;
ALLOC_CB_ARGS(args, INTERP, SELF, table);
+ // TODO: We probably should split on ';' and execute each query
+ // individually
+
STRING_TO_CSTRING(INTERP, query, cquery,
rc = sqlite3_exec(db, cquery, sqlite_callback, args, &err_msg);
);

0 comments on commit 81a1a0b

Please sign in to comment.