get_copy_data (PGconn)

    /*
     * call-seq:
     *    conn.get_copy_data( [ async = false ] ) -> String
     *
     * Return a string containing one row of data, +nil+
     * if the copy is done, or +false+ if the call would
     * block (only possible if _async_ is true).
     *
     */
    static VALUE
    pgconn_get_copy_data(int argc, VALUE *argv, VALUE self )
    {
            VALUE async_in;
            VALUE error;
            VALUE result_str;
            int ret;
            int async;
            char *buffer;
            PGconn *conn = get_pgconn(self);

            if (rb_scan_args(argc, argv, "01", &async_in) == 0)
                    async = 0;
            else
                    async = (async_in == Qfalse || async_in == Qnil) ? 0 : 1;

            ret = PQgetCopyData(conn, &buffer, async);
            if(ret == -2) { // error
                    error = rb_exc_new2(rb_ePGError, PQerrorMessage(conn));
                    rb_iv_set(error, "@connection", self);
                    rb_exc_raise(error);
            }
            if(ret == -1) { // No data left
                    return Qnil;
            }
            if(ret == 0) { // would block
                    return Qfalse;
            }
            result_str = rb_tainted_str_new(buffer, ret);
            PQfreemem(buffer);
            return result_str;
    }