This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-22
Channels
- # announcements (1)
- # babashka (28)
- # beginners (120)
- # braveandtrue (6)
- # calva (59)
- # cider (10)
- # clj-kondo (10)
- # cljfx (2)
- # clojure (66)
- # clojure-europe (20)
- # clojure-germany (1)
- # clojure-italy (3)
- # clojure-nl (4)
- # clojure-norway (1)
- # clojure-serbia (17)
- # clojure-spain (1)
- # clojure-uk (17)
- # clojurescript (120)
- # clojureverse-ops (4)
- # core-async (5)
- # cursive (18)
- # data-oriented-programming (1)
- # datomic (4)
- # deps-new (8)
- # emacs (14)
- # fulcro (16)
- # funcool (2)
- # kaocha (4)
- # lambdaisland (5)
- # luminus (1)
- # malli (47)
- # membrane (9)
- # mid-cities-meetup (2)
- # music (1)
- # off-topic (44)
- # pathom (13)
- # practicalli (2)
- # re-frame (15)
- # reagent (34)
- # reveal (25)
- # ring (56)
- # rum (1)
- # shadow-cljs (23)
- # sql (14)
- # startup-in-a-month (1)
- # tools-deps (10)
- # vim (9)
- # vscode (3)
- # xtdb (9)
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).
so no way to escape 2x db-operations
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
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
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 _))))