From 5ae0fb31d3d2576e3ed965202b8edc3d842cf2e3 Mon Sep 17 00:00:00 2001 From: Christophe Meyer Date: Wed, 29 Dec 2021 20:22:30 +0100 Subject: [PATCH] COPY with parameter is not supported --- src/copy.jl | 14 +++++--------- test/runtests.jl | 6 +++++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/copy.jl b/src/copy.jl index 8e3b5a05..7484e827 100644 --- a/src/copy.jl +++ b/src/copy.jl @@ -119,16 +119,12 @@ function execute( ) level = throw_error ? error : warn if parameters !== nothing - string_params = string_parameters(parameters) - pointer_params = parameter_pointers(string_params) + # https://postgrespro.com/list/thread-id/1893680 + throw(ArgumentError("COPY can't take any parameter")) end copy_end_result = lock(jl_conn) do - if parameters === nothing - result = _execute(jl_conn.conn, copy.query) - else - result = _execute(jl_conn.conn, copy.query, pointer_params) - end + result = _execute(jl_conn.conn, copy.query) result_status = libpq_c.PQresultStatus(result) if result_status != libpq_c.PGRES_COPY_OUT @@ -154,8 +150,8 @@ function execute( seekstart(io) # rewind iobuffer so future user read will begin from start if -2 == status_code level(LOGGER, Errors.JLResultError( - "PQgetCopyData error: $(error_message(jl_conn))" - )) + "PQgetCopyData error: $(error_message(jl_conn))" + )) end libpq_c.PQgetResult(jl_conn.conn) diff --git a/test/runtests.jl b/test/runtests.jl index e220470c..2160512e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -505,7 +505,7 @@ end @testset "Wrong COPY TO" begin conn = LibPQ.Connection("dbname=postgres user=$DATABASE_USER") - # test CopyOut! + # test CopyOut! with an error databuf = IOBuffer() copyout = LibPQ.CopyOut!(databuf, "SELECT libpqjl_test;") @@ -517,6 +517,10 @@ end @test occursin("ERROR", err_msg) close(result) + # parameters are not supported + copyout = LibPQ.CopyOut!(databuf, "COPY (SELECT * FROM libpqjl_test WHERE no_nulls = \$1) TO STDOUT (FORMAT CSV, HEADER);") + @test_throws ArgumentError execute(conn, copyout, ['z']) + close(conn) end end