/* * call-seq: * res[ n ] * * Returns the tuple (row) corresponding to _n_. Returns +nil+ if <tt>_n_ >= res.num_tuples</tt>. * * Equivalent to <tt>res.result[n]</tt>. */ static VALUE pgresult_aref(argc, argv, obj) int argc; VALUE *argv; VALUE obj; { PGresult *result; VALUE a1, a2, val; int i, j, nf, nt; result = get_pgresult(obj); nt = PQntuples(result); nf = PQnfields(result); switch (rb_scan_args(argc, argv, "11", &a1, &a2)) { case 1: i = NUM2INT(a1); if( i >= nt ) return Qnil; val = rb_ary_new(); for (j=0; j<nf; j++) { VALUE value = fetch_pgresult(result, i, j); rb_ary_push(val, value); } return val; case 2: i = NUM2INT(a1); if( i >= nt ) return Qnil; j = NUM2INT(a2); if( j >= nf ) return Qnil; return fetch_pgresult(result, i, j); default: return Qnil; /* not reached */ } }