Fork me on GitHub
#sql
<
2017-11-28
>
plins19:11:16

hello everyone, I’m using SQLHoney and mysql, is anyone aware of how im supposed to retrieve the generated id? it is returning the number of affected rows (like im doing some multiinsert) although im inserting only one record

seancorfield19:11:05

You'll only get generated IDs back if you use clojure.java.jdbcs insert! directly, I believe. If you use execute! you won't get generated IDs.

seancorfield19:11:17

(so I'm not sure how HoneySQL plays into that?)

plins19:11:25

in that case i guess i should not be using HoneySQL, jdbc/insert! already accepts a nice map as parameter

plins19:11:29

thanks 🙂

seancorfield20:11:58

HoneySQL is great for queries -- I wouldn't use it for anything else, personally. I didn't even know it had insert support...

seancorfield20:11:32

Ah, interesting... insert-into...

seancorfield20:11:12

I guess that could be useful sometimes -- but when using execute! you will only get the affected row count back, not generated keys. I guess I could add an option to execute! to attempt to force that...

donaldball20:11:04

IIRC I’ve used db-do-prepared or similar to get generated keys for inserts not mediated by jdbc/insert!

seancorfield20:11:11

@donaldball That function doesn't return generated keys. Are you thinking of db-do-prepared-return-keys?

seancorfield20:11:04

execute! currently always uses db-do-prepared, insert! and insert-multi! use db-do-prepared-return-keys if they are called with maps (but not the column variant).

seancorfield20:11:20

I'm not quite sure why the column variant doesn't (can't?) use the -return-keys version -- I'd have to investigate. But execute! certainly could be told to use the -return-keys variant if multi? true is not specified -- if I add a new option check there.