Class: RDO::MySQL::TupleList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
ext/rdo_mysql/tuples.c

Instance Method Summary collapse

Instance Method Details

#eachObject

Iterate over all tuples in the list



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'ext/rdo_mysql/tuples.c', line 102

static VALUE rdo_mysql_tuple_list_each(VALUE self) {
  RDOMySQLTupleList * list;
  Data_Get_Struct(self, RDOMySQLTupleList, list);

  if (!rb_block_given_p() || list->res == NULL) {
    return self;
  }

  mysql_data_seek(list->res, 0);

  unsigned int    nfields = mysql_num_fields(list->res);
  MYSQL_FIELD   * fields  = mysql_fetch_fields(list->res);
  MYSQL_ROW       row;

  while ((row = mysql_fetch_row(list->res))) {
    unsigned long * lengths = mysql_fetch_lengths(list->res);
    VALUE           hash    = rb_hash_new();
    unsigned int    i       = 0;

    for (; i < nfields; ++i) {
      rb_hash_aset(hash,
          ID2SYM(rb_intern(fields[i].name)),
          rdo_mysql_cast_value(row[i], lengths[i], fields[i], list->encoding));
    }

    rb_yield(hash);
  }

  return self;
}