Closed dfrese closed 10 months ago
I traced it down into jamdb_oracle_conn.erl
and the sql_query
function:
Data = lists:filtermap(fun(L) -> if hd(L) =:= $: -> {true, list_to_integer(tl(L))}; true -> false end end,
string:tokens(Query," \t\r\n;,()=")),
Seems this tries to parse :id
like a query parameter :1
which are usually integers.
Hi!
Returning param must be declared as :out
in opts
Repo.query("insert into xxx (yyy) values (:1) return id into :2 ", ["aaa", out: :integer])
I'll try to implement this
Database.insert!(%Xxx{yyy: "bar"}, [returning: false, out: [:integer]])
Thank you!
I'll try too, in the mean time.
Did a quick&dirty fix, by adding a second variant of Jamdb.Oracle.Query/returning
defp returning(_, []),
do: []
defp returning(header, fields) do
returning = fields |> Enum.filter(& is_tuple(&1) == false)
offset = Enum.count(header)
[" RETURN ", intersperse_map(returning, ", ", "e_name/1),
" INTO ", intersperse_map(Enum.to_list(1..Enum.count(returning)), ", ", fn i -> [?: | "#{offset + i}"] end)]
end
which takes 'header' from insert
to append the correct indices of out params after the other params.
Calling Repo.insert(..., out: [:integer])
worked then!
I didn't look into Repo.delete and Repo.update.
(Feel free to use it, in case this isn't as dirty as I think ;-) )
Thanks! It works; but I still need to specify out: [:integer]
.
Unfortunately, I get the same error now for 'sub entities', i.e. a 'has_many' relation, where afaik Ecto generates multiple insert statements for one Repo.insert
. I don't think I can add 'out:' there.
So adding 'out:' implicitly based on 'returning' would imho be needed to fix that.
Hi there!
I'm getting an error trying an Ecto.Repo.insert on a table with a generated id column. With the current code from master, against an Oracle 19c server.
The table was created like this:
The corresponding schema:
And the insert is done like this (Database is my Ecto.Repo)
The error details and log output I get are:
Same without the 'returning' option, or 'returning [:id]'.
Any help much appreciated!