/* * call-seq: * res.each{ |tuple| ... } * * Invokes the block for each tuple (row) in the result. * * Equivalent to <tt>res.result.each{ |tuple| ... }</tt>. */ static VALUE pgresult_each(self) VALUE self; { int i, j; PGresult *result = get_pgresult(self); int nt = PQntuples(result); int nf = PQnfields(result); VALUE fields[1] = { rb_ary_new2(nf) }; for (i = 0; i < nf; i++) rb_ary_push(fields[0], rb_tainted_str_new2(PQfname(result, i))); for (i=0; i<nt; i++) { VALUE row = rb_funcall2(rb_cPGrow, rb_intern("new"), 1, fields); for (j=0; j<nf; j++) { rb_ary_store(row, j, fetch_pgresult(result, i, j)); } rb_yield(row); } return self; }