Replies: 1 comment 5 replies
-
Pretty much every DB driver returns generated keys differently, unfortunately: (let [new-key (cond (derby?) :1
(jtds?) :ID
(maria?) :insert_id
(mssql?) :GENERATED_KEYS
(mysql?) :GENERATED_KEY
(postgres?) :fruit/id
(sqlite?) (keyword "last_insert_rowid()")
:else :FRUIT/ID)] And those are only the ones I know about from testing -- other databases probably do something else. What you get back also depends on the builder-fn you are using. I'm not sure how a generic solution could work, without imposing a performance penalty on everyone... |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there - I've moved from JTDS to Microsoft's JDBC Driver and the app broke. It turns out that JTDS returns the new PK ID under a field called
:id
:{:id THE_ID}
but Microsoft's JDBC Driver doesn't:{:generated_keys THE_ID}
.I'd naively assumed that
:id
was standard/part of this library's API and that simply changing the driver (same app, same database, same server) wouldn't have such a big impact. Sigh - thanks Microsoft :-).Anyway, I could elegantly solve this if:
id-extractor-fn
I could painfully solve this by tracking down each and every instance in my app which performs an insert and then looks up the
:id
, but please, no :-). Going back to JTDS isn't feasible as it seems dead.What would you suggest (other than not making such assumptions again!)?
Beta Was this translation helpful? Give feedback.
All reactions