@@ -95,7 +95,8 @@ Notes:
<ol>
<li id="vn1">When fetching VARCHAR, TEXT etc. they are returned as `binary()'.
- When sending (insert or update) any `iodata()' is accepted.</li>
+ When sending (insert or update) any `iodata()' is accepted. Lists will be
+ interpreted as utf8 unicode, binaries will be left as is.</li>
<li id="vn2">DECIMALs are returned as `integer()' or `float()' when the value
can be represented without precision loss and as `binary()' for high
precision DECIMAL values. This is similar to how the `odbc' OTP application
@@ -16,10 +16,11 @@ encode(Int) when is_integer(Int) ->
encode(Float) when is_float(Float) ->
%% "floats are printed accurately as the shortest, correctly rounded string"
io_lib:format("~w", [Float]);
-encode(String) when is_list(String); is_binary(String) ->
- Bin = iolist_to_binary(String),
+encode(Bin) when is_binary(Bin) ->
Escaped = binary:replace(Bin, <<"'">>, <<"''">>, [global]),
[$', Escaped, $'];
+encode(String) when is_list(String) ->
+ encode(unicode:characters_to_binary(String));
encode(Bitstring) when is_bitstring(Bitstring) ->
["b'", [ case B of 0 -> $0; 1 -> $1 end || <<B:1>> <= Bitstring ], $'];
encode({Y, M, D}) ->
@@ -13,6 +13,7 @@ encode_test() ->
{3.14, "3.14"},
{"isn't didn't", "'isn''t didn''t'"}, %% Escape single quotes.
{"\\n", "'\\n'"}, %% Don't escape backslash.
+ {[<<"asdf">>,"ščžć€"], <<"'asdf",197,161,196,141,197,190,196,135,226,130,172,"'">>},
%% BIT(N)
{<<255, 2:3>>, "b'11111111010'"},
%% DATE