Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/clickhousex/codec/values.ex
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ defmodule Clickhousex.Codec.Values do
["'", escape(param), "'"]
end

defp escape(s) when is_map(s) do
m = Jason.encode!(s)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it be Jason.encode_to_iodata!/1?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Thank you for the suggestion!

Copy link

@ruslandoga ruslandoga Nov 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't JSON iodata still need to be escaped?

With the current implementation I'm getting

Code: 62. DB::Exception: Cannot parse expression of type Object('json') here: '{\"should\":{\"'\":\"%\",\"\\\\\":\"\",\"_\":\"?\",\"it be\":\"escaped?\"}}'

for a map like

%{"should" => %{"it be" => "escaped?", "_" => "?", "'" => "%", "\\" => ""}}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the confusion. I think the previous approach with Jason.encode! is the way to go since escaping iodata seems like too much work.

to_iodata(m, 0, m, [])
end

defp escape(s) do
to_iodata(s, 0, s, [])
end
Expand Down