/*
 * call-seq:
 *    conn.put_copy_end( [ error_message ] ) -> Boolean
 *
 * Sends end-of-data indication to the server.
 *
 * _error_message_ is an optional parameter, and if set,
 * forces the COPY command to fail with the string
 * _error_message_.
 *
 * Returns true if the end-of-data was sent, false if it was
 * not sent (false is only possible if the connection
 * is in nonblocking mode, and this command would block).
 */ 
static VALUE
pgconn_put_copy_end(int argc, VALUE *argv, VALUE self)
{
    VALUE str;
    VALUE error;
    int ret;
    char *error_message = NULL;
    PGconn *conn = get_pgconn(self);

    if (rb_scan_args(argc, argv, "01", &str) == 0)
        error_message = NULL;
    else
        error_message = StringValuePtr(str);

    ret = PQputCopyEnd(conn, error_message);
    if(ret == -1) {
        error = rb_exc_new2(rb_ePGError, PQerrorMessage(conn));
        rb_iv_set(error, "@connection", self);
        rb_exc_raise(error);
    }
    return (ret) ? Qtrue : Qfalse;
}