/*
 * call-seq:
 *    conn.get_result() -> PGresult
 *
 * Blocks waiting for the next result from a call to
 * +PGconn#send_query+ (or another asynchronous command), and returns
 * it. Returns +nil+ if no more results are available.
 *
 * Note: call this function repeatedly until it returns +nil+, or else
 * you will not be able to issue further commands.
 */
static VALUE
pgconn_get_result(VALUE self)
{
        PGconn *conn = get_pgconn(self);
        PGresult *result;
        VALUE rb_pgresult;

        result = PQgetResult(conn);
        if(result == NULL)
                return Qnil;
        rb_pgresult = new_pgresult(result);
        if (rb_block_given_p()) {
                return rb_ensure(yield_pgresult, rb_pgresult,
                        pgresult_clear, rb_pgresult);
        }
        return rb_pgresult;
}