Skip to content

Commit

Permalink
[MySQL] Add in a few interfaces for iteration. MySqlDataTable is its …
Browse files Browse the repository at this point in the history
…own iterator, so implement that interface. MySqlDataRow uses a HashIterator over the column names hash. In the future we might use something more custom, since rows should be able to be iterated by column name and by raw indexed value
  • Loading branch information
Whiteknight committed Apr 15, 2012
1 parent 84feff6 commit 0605f32
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 12 additions & 0 deletions mysql/pmc/mysqldatarow.pmc
Expand Up @@ -69,4 +69,16 @@ pmclass MySqlDataRow dynpmc auto_attrs provides array provides hash {
{
return VTABLE_elements(INTERP, PARROT_MYSQLDATAROW(SELF)->data);
}

VTABLE PMC *get_iter()
{
return Parrot_pmc_new_init(INTERP, enum_class_HashIterator, SELF);
}

VTABLE void * get_pointer()
{
// Return a pointer to the Hash* representing the column hash. Currently
// we get that from the table. This interface is required by HashIterator.
return VTABLE_get_pointer_keyed(INTERP, PARROT_MYSQLDATAROW(SELF)->table, SELF);
}
}
13 changes: 7 additions & 6 deletions mysql/pmc/mysqldatatable.pmc
Expand Up @@ -48,12 +48,6 @@ pmclass MySqlDataTable dynpmc auto_attrs provides iterator {
Parrot_hash_mark(INTERP, colnames);
}

VTABLE void* get_pointer()
{
MYSQL_RES * const result = GET_RESULT(SELF);
return result;
}

VTABLE void destroy()
{
MYSQL_RES * const result = GET_RESULT(SELF);
Expand Down Expand Up @@ -103,4 +97,11 @@ pmclass MySqlDataTable dynpmc auto_attrs provides iterator {
// This is necessary for the iterator interface
UNUSED(iter_dir);
}

VTABLE void *get_pointer_keyed(PMC *row)
{
// For iterating rows, we need an easy way to get a pointer to the colnames
// hash. In the future we should find a better way to do it.
return PARROT_MYSQLDATATABLE(SELF)->colnames;
}
}

0 comments on commit 0605f32

Please sign in to comment.