/*
 * 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(obj)
  VALUE obj;
{
  PGresult *result;
  int nt, nf, i, j;

  result = get_pgresult(obj);
  nt = PQntuples(result);
  nf = PQnfields(result);
  for (i=0; i<nt; i++) {
    VALUE row = rb_ary_new2(nf);
    for (j=0; j<nf; j++) {
      VALUE value = fetch_pgresult(result, i, j);
      rb_ary_push(row, value);
    }
    rb_yield(row);
  };

  return Qnil;
}