How can SQL return both sql.Rows and sql.Result

120 views
Skip to first unread message

Daniel Fava

unread,
Aug 22, 2024, 4:33:04 AMAug 22
to golang-nuts
Hi,

How can I combine QueryContext and ExecContext so that both sql.Rows and sql.Result are returned?  For example, if I have a stored procedure with:

```
insert into Users (Username) values ('JohnDoe');
select X = 1, Y = 'one';
select X = 2;
update Transfers set Value = 10 where Value = 0;
```

then I would like to get back sql.Rows with results from the two selects, and sql.Result with the RowsAffected for the insert and update statements.

I would like for this to work with any stored procedure; meaning, any combination of inserts/updates/selects.

Please advise :-)

Daniel

Marcin Romaszewicz

unread,
Aug 26, 2024, 4:29:00 PMAug 26
to Daniel Fava, golang-nuts
You can't. Split the SQL into individual statements.

Any of those statements can fail, or generate an error, and the API isn't designed to disentangle multiple entangled statements.

Problem is, it's not easy to split SQL into statements reliably because it's not a simple grammar.


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAM7K%2BQZx1bZybNCYZ5LXET5ynrGcYVS_BasSXtRctpufrfxP0g%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages