/* * call-seq: * conn.get_result() -> PGresult * conn.get_result() {|pg_result| block } * * 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. * * If the optional code block is given, it will be passed <i>result</i> as an argument, * and the PGresult object will automatically be cleared when the block terminates. * In this instance, <code>conn.exec</code> returns the value of the block. */ 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, conn); if (rb_block_given_p()) { return rb_ensure(rb_yield, rb_pgresult, pgresult_clear, rb_pgresult); } return rb_pgresult; }