Skip to content

Commit cd22706

Browse files
authored
Don't translate string to charlist before sending to NIF (#179)
1 parent 2c3138a commit cd22706

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

c_src/sqlite3_nif.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,6 @@ exqlite_execute(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
204204
return make_error_tuple(env, "sql_not_iolist");
205205
}
206206

207-
enif_inspect_iolist_as_binary(env,
208-
enif_make_list2(env, argv[1], eos),
209-
&bin);
210-
211207
rc = sqlite3_exec(conn->db, (char*)bin.data, NULL, NULL, NULL);
212208
if (rc != SQLITE_OK) {
213209
return make_sqlite3_error_tuple(env, rc, conn->db);

lib/exqlite/sqlite3.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ defmodule Exqlite.Sqlite3 do
4343
"""
4444
@spec execute(db(), String.t()) :: :ok | {:error, reason()}
4545
def execute(conn, sql) do
46-
case Sqlite3NIF.execute(conn, String.to_charlist(sql)) do
46+
case Sqlite3NIF.execute(conn, sql) do
4747
:ok -> :ok
4848
{:error, reason} -> {:error, reason}
4949
_ -> {:error, "unhandled error"}

test/exqlite/sqlite3_test.exs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ defmodule Exqlite.Sqlite3Test do
8787
:ok =
8888
Sqlite3.execute(conn, "insert into things(content) VALUES ('this is content')")
8989
end
90+
91+
test "handles unicode characters" do
92+
{:ok, conn} = Sqlite3.open(":memory:")
93+
94+
:ok =
95+
Exqlite.Sqlite3.execute(
96+
conn,
97+
"create table test (id integer primary key, stuff text)"
98+
)
99+
100+
:ok = Exqlite.Sqlite3.execute(conn, "insert into test (stuff) values ('😝')")
101+
end
90102
end
91103

92104
describe ".prepare/3" do

0 commit comments

Comments
 (0)