Skip to content

Commit

Permalink
COPY with parameter is not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
cmey committed Dec 30, 2021
1 parent e0da87b commit 5ae0fb3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 5 additions & 9 deletions src/copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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;")

Expand All @@ -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
Expand Down

0 comments on commit 5ae0fb3

Please sign in to comment.