Open LoganBresnahan opened 6 years ago
I am facing the same issue. Do you guys have any update on it?
any update for this issue?
I've just come back from a month's holiday and things are a bit less hectic now than they were for the first half of the year so I'm going to try to dedicate at least a few hours a week to updating this library. I'll prioritise merging PRs, since my personal Elixir skills are rather rusty at this point, but if nobody else is picking this issue up I'll get to it.
I just ran into this issue as well. I'd be glad to try my hand at patching this if someone could provide some pointers on where to start in this codebase.
This seems related:
It looks like making inserted an optional parameter is one possible solution: https://github.com/findmypast-oss/mssql_ecto/blob/master/lib/mssql_ecto/query.ex#L107
Unfortunately, we won't be able to get the inserted data back with this approach.
Another alternative might be to check if a trigger exists on a table and dynamically add/remove the inserted bit: https://wateroxconsulting.com/archives/find-triggers-sql-server-database/
But perhaps this would add too much overhead?
Does setting returning: false
on the insert/2
call allow the query to complete? I think that might be the best we can do, allow the user to turn off OUTPUT
. I don't want to have every DML statement have to make an extra query to figure out if there are triggers and I don't think we can get the ODBC adapter we depend on to do the multiline statement necessary to output into a temp table and then select from it (though I might be wrong there).
I think you're right (allow the user to turn off OUTPUT
).
Setting returning: false
didn't work for me. Where is insert/2
defined? All I'm seeing is this def: https://github.com/findmypast-oss/mssql_ecto/blob/master/lib/mssql_ecto/query.ex#L98
I meant Ecto.Repo.insert/2
which is how the end-user interacts with the adapter. I also think I got it wrong and "return nothing" is expressed as returning: []
rather than false
, which I believe gets translated into the returning
argument being []
in query.ex
which looking at the code should remove the OUTPUT
clause.
In the db you can delete the trigger which is not in use. can solve this issue. I did delete the trigger from the table . and it worked fine.
Problem:
When a database table has a trigger attached to it,
insert/1
will fail because the adapter is not utilizing anINTO
clause.This blog post from the SQL Server team explains the issue well: https://blogs.msdn.microsoft.com/sqlprogrammability/2008/07/11/update-with-output-clause-triggers-and-sqlmoreresults/
Error Example:
result:
DB Trigger Example:
Temporary Workaround:
Even if you're only looking to insert one record, you can use
insert_all/2
and pass in your one entry because it does not rely on a return value from the database. https://hexdocs.pm/ecto/Ecto.Repo.html#c:insert_all/3Environment: