Closed gtaranti closed 1 year ago
The third argument to query is not a param, it's a list of parameters. That's why sending a single ID seemingly worked. So the invocation should rather be:
ids = [139937, 139935]
MyXQL.query(conn, "delete from log where id in (?)", [ids])
It still won't work as expected since mysql neither has array type nor supports sending them over the wire. It does support JSON and Elixir lists and maps are encoded as such:
iex> MyXQL.query!(pid, "SELECT ?", [[1, 2]]).rows
[["[1,2]"]]
Starting in mysql server 8.0.17, you can write the equivalent of WHERE id IN ?
for json arrays, WHERE id MEMBER OF(?)
:
ids = [139937, 139935]
MyXQL.query!(pid, "DELETE FROM logs WHERE id MEMBER OF(?)", [ids])
Personally I think I'd go with building the query manually, as explicit as possible so there are no security holes:
MyXQL.query!(pid, "DELETE FROM logs WHERE id in (" <> Enum.map_join(ids, ",", &Integer.to_string/1) <> ")")
Thanks! It's clear now.
You've been very helpful!!
I try this code :
and get back error
When I try without only in element in the list, it works :
Is there a special syntax for more than one elements in the list?