/*
 * call-seq:
 *    res.getvalue( tup_num, field_num )
 *
 * Returns the value in tuple number _tup_num_, field _field_num_,
 * or +nil+ if the field is +NULL+.
 */
static VALUE
pgresult_getvalue(VALUE self, VALUE tup_num, VALUE field_num)
{
        PGresult *result;
        int i = NUM2INT(tup_num);
        int j = NUM2INT(field_num);

        result = get_pgresult(self);
        if(i < 0 || i >= PQntuples(result)) {
                rb_raise(rb_eArgError,"invalid tuple number %d", i);
        }
        if(j < 0 || j >= PQnfields(result)) {
                rb_raise(rb_eArgError,"invalid field number %d", j);
        }
        if(PQgetisnull(result, i, j))
                return Qnil;
        return rb_tainted_str_new(PQgetvalue(result, i, j), 
                                PQgetlength(result, i, j));
}