Skip to content

Don't translate string to charlist before sending to NIF #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 0 additions & 4 deletions c_src/sqlite3_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,6 @@ exqlite_execute(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
return make_error_tuple(env, "sql_not_iolist");
}

enif_inspect_iolist_as_binary(env,
enif_make_list2(env, argv[1], eos),
&bin);

rc = sqlite3_exec(conn->db, (char*)bin.data, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
return make_sqlite3_error_tuple(env, rc, conn->db);
Expand Down
2 changes: 1 addition & 1 deletion lib/exqlite/sqlite3.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defmodule Exqlite.Sqlite3 do
"""
@spec execute(db(), String.t()) :: :ok | {:error, reason()}
def execute(conn, sql) do
case Sqlite3NIF.execute(conn, String.to_charlist(sql)) do
case Sqlite3NIF.execute(conn, sql) do
:ok -> :ok
{:error, reason} -> {:error, reason}
_ -> {:error, "unhandled error"}
Expand Down
12 changes: 12 additions & 0 deletions test/exqlite/sqlite3_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ defmodule Exqlite.Sqlite3Test do
:ok =
Sqlite3.execute(conn, "insert into things(content) VALUES ('this is content')")
end

test "handles unicode characters" do
{:ok, conn} = Sqlite3.open(":memory:")

:ok =
Exqlite.Sqlite3.execute(
conn,
"create table test (id integer primary key, stuff text)"
)

:ok = Exqlite.Sqlite3.execute(conn, "insert into test (stuff) values ('😝')")
end
end

describe ".prepare/3" do
Expand Down