Fork me on GitHub
#sql
<
2020-08-18
>
Saikyun12:08:27

we have a procedure that ends with select @@IDENTITY. however, when using jdbc.next/execute! or jdbc.next.sql/query to run the procedure, I only get back the update-count. is it possible to get the result of select @@IDENTITY?

seancorfield17:08:03

@saikyun Per the next.jdbc *Getting Started* page: "If you pass the :multi-rs true option to execute!, you will get back a vector of results sets, instead of just one result set: a vector of zero or more vectors. The result may well be a mix of vectors containing realized rows and vectors containing update counts, reflecting the results from specific SQL operations in the stored procedure or script."

Saikyun05:08:00

I think I tried that option, but I don't remember exactly how I did it. I'll give it another shot and come back if I have more questions 🙂

Saikyun05:08:06

thanks for the reply

seancorfield06:08:57

It will depend on your DB/driver -- what are you using?

Saikyun09:08:16

microsoft sql server

seancorfield17:08:33

OK, I've tested multiple result sets on SQL Server and it works (this is from the test suite):

(jdbc/execute! (ds)
                           [(str "begin"
                                 " select * from fruit;"
                                 " select * from fruit where id < 4;"
                                 " end")

seancorfield17:08:28

That produces a vector containing two result sets, i.e., two vectors of hash maps, and the first result set contains four rows and the second result set contains three rows.

seancorfield17:08:27

(it's also described on the All The Options page and in the docstring itself for execute!)