Sqlitex.exec() accepts bind: option but nothing is bound?
dognotdog opened this issue · 4 comments
Doing an INSERT statement with bound values, Sqlitex.exec("INSERT ... VALUES(?1,...)", bind:[...]) fails to bind anything. Sqlitex.query() with the same statement works as expected.
With sqlitex 1.7.0.
@dognotdog We currently have some tests in our test suite like this:
{:ok, []} = Sqlitex.query(db, "INSERT INTO t VALUES (?1, ?2)", bind: [1, true])Is that similar to how your query works? It could be that you are inserting a data type that we haven't tested yet? If you could post a more complete sample of what you're seeing I'd be happy to take a look and troubleshoot
BTW you can see a bunch of our test in the sqlitex_test.exs file where we test inserting decimals, dates etc
I guess in my case
{:ok, []} = Sqlitex.query(db, "INSERT INTO t VALUES (?1, ?2)", bind: [1, true])
works, but
:ok = Sqlitex.exec(db, "INSERT INTO t VALUES (?1, ?2)", bind: [1, true])
results in NULLs being inserted into the table instead.
Sorry I haven't had time yet to look into how to run the tests for this myself, yet, I'm quite new to the elixir ecosystem.
@dognotdog welcome to the ecosystem ❤️ 💛 💙 💚 💜
That makes sense. The exec function goes straight to the sqlite3 query engine without any preparation or binding steps taking place. We didn't do a great job of documenting those top-level functions, but the Sqlitex.query function just calls the Sqlitex.Query.query function which has some decent documentation.
I'll try to write up some documentation around the exec function one of these days to make it clearer that it doesn't do any binding or query preparation.