diff --git a/Project.toml b/Project.toml index 570efc93..70be90a0 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "LibPQ" uuid = "194296ae-ab2e-5f79-8cd4-7183a0a5a0d1" license = "MIT" -version = "1.9.0" +version = "1.10.0" [deps] BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232" diff --git a/src/results.jl b/src/results.jl index 04b59fe9..63d2b4cc 100644 --- a/src/results.jl +++ b/src/results.jl @@ -378,7 +378,11 @@ function string_parameter(parameter::AbstractVector) return String(take!(io)) end -_array_element(el::AbstractString) = "\"$el\"" +function _array_element(el::AbstractString) + el = replace(el, "\\" => "\\\\") + el = replace(el, "\"" => "\\\"") + return "\"$el\"" +end _array_element(el::Missing) = "NULL" _array_element(el) = string_parameter(el) diff --git a/test/runtests.jl b/test/runtests.jl index 51eca301..e8c807f7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1410,33 +1410,38 @@ end conn = LibPQ.Connection("dbname=postgres user=$DATABASE_USER"; throw_error=true) @testset "Arrays" begin - result = execute(conn, "SELECT 'foo' = ANY(\$1)", [["bar", "foo"]]) - @test first(first(result)) - close(result) - - result = execute(conn, "SELECT 'foo' = ANY(\$1)", (["bar", "foo"],)) - @test first(first(result)) - close(result) - - result = execute(conn, "SELECT 'foo' = ANY(\$1)", [Any["bar", "foo"]]) - @test first(first(result)) - close(result) + tests = ( + ("SELECT 'foo' = ANY(\$1)", [["bar", "foo"]]), + ("SELECT 'foo' = ANY(\$1)", (["bar", "foo"],)), + ("SELECT 'foo' = ANY(\$1)", [Any["bar", "foo"]]), + ("SELECT 'foo' = ANY(\$1)", Any[Any["bar", "foo"]]), + ("SELECT 'f\"oo' = ANY(\$1)", [["b\"ar", "f\"oo"]]), + ("SELECT 'f\\oo' = ANY(\$1)", [["b\\ar", "f\\oo"]]), + ("SELECT 'f\\\\oo' = ANY(\$1)", [["b\\\\ar", "f\\\\oo"]]), + ("SELECT 'f\\\"oo' = ANY(\$1)", [["b\\\"ar", "f\\\"oo"]]), + ("SELECT 'f\"\\oo' = ANY(\$1)", [["b\"\\ar", "f\"\\oo"]]), + ("SELECT ARRAY[1, 2] = \$1", [[1, 2]]), + ("SELECT ARRAY[1, 2] = \$1", Any[Any[1, 2]]) + ) - result = execute(conn, "SELECT 'foo' = ANY(\$1)", Any[Any["bar", "foo"]]) - @test first(first(result)) - close(result) + @testset for (query, arr) in tests + result = execute(conn, query, arr) + @test first(first(result)) + close(result) + end - result = execute(conn, "SELECT 'foo' = ANY(\$1)", [["bar", "foobar"]]) - @test !first(first(result)) - close(result) + tests = ( + ("SELECT 'foo' = ANY(\$1)", [["bar", "foobar"]]), + ("SELECT 'f\\\\oo' = ANY(\$1)", [["b\\ar", "f\\oo"]]), + ("SELECT 'f\\oo' = ANY(\$1)", [["b\\\\ar", "f\\\\oo"]]) + ) - result = execute(conn, "SELECT ARRAY[1, 2] = \$1", [[1, 2]]) - @test first(first(result)) - close(result) + @testset for (query, arr) in tests + result = execute(conn, query, arr) + @test !first(first(result)) + close(result) + end - result = execute(conn, "SELECT ARRAY[1, 2] = \$1", Any[Any[1, 2]]) - @test first(first(result)) - close(result) end @testset "Intervals" begin