Is there anyway to get the "updated-rows" keys/columns from an update query (with next.jdbc 1.1.582 & MySQL)
(next.jdbc/execute!
ds
["UPDATE table SET col1=1 WHERE col2=test"]
{:return-keys ["col1" "col2"]})
=> []
although an update occurred..@aviv The JDBC driver doesn’t provide that information (otherwise the above would work).
doesn't it support .getGeneratedKeys()
or this won't do in MYSQL, I remember from Java days this is usually supported
There is no ResultSet
from the update
— next.jdbc
tries to return a ResultSet
first in all cases and only if one isn’t available does it ask for the update count. If you ask for :return-keys
, it will also try .getGeneratedKeys()
(after asking for a ResultSet
but before falling back to update counts).
I see
so no way to escape 2x db-operations
next.jdbc
is pretty close to the JDBC layer: when you execute!
or execute-one!
, it does this:
(if (.execute stmt)
(.getResultSet stmt)
(when (:return-keys opts)
(try
(.getGeneratedKeys stmt)
(catch Exception _))))
You mean an update
followed by a select
in a single transaction?
(or even sending multiple statements in a single operation — that’s documented for MySQL but not advised because it’s easier to succumb to a SQL injection attack that way)
Update without a followed select (for simplicity), but I guess this is not possible
update&select in a single transaction is possible by wrapping with the transaction macro
Per the link above you can do update ...; select ...
if you add that JDBC connection setting. Like I say, not recommended in general.
cool, thx