driver.Rows -> sql.Rows

234 views
Skip to first unread message

Tamás Gulácsi

unread,
Nov 12, 2017, 1:37:19 AM11/12/17
to golang-sql
Hi,

Is there a way to convert a driver.Rows to an sql.Rows ?
Oracle is a strange, inconsistent beast where you can return a cursor from a statement executed with Exec.
gopkg.in/goracle.v2 returns this as driver.Rows, but that's uneasy to use.

Maybe a helper for use a driver.Rows as an sql.Rows could be enough.

Or any other idea?
What to return from the driver?

Thanks,
Tamás Gulácsi

Daniel Theophanes

unread,
Nov 13, 2017, 4:20:32 PM11/13/17
to golang-sql
Hi Tomas,

I saw your email over the weekend, but didn't get to it until work today.

Could you give me some context for this request / or some example code with perhaps a magic function that does what you want?

Alternately, in what situation do you end up with a driver.Rows rather then a sql.Rows? Maybe we can address the issue of using cursors with the sql package.

Thanks, -Daniel

Tamás Gulácsi

unread,
Nov 14, 2017, 2:16:59 PM11/14/17
to golang-sql

2017. november 13., hétfő 22:20:32 UTC+1 időpontban Daniel Theophanes a következőt írta:
Hi Tomas,

I saw your email over the weekend, but didn't get to it until work today.

Could you give me some context for this request / or some example code with perhaps a magic function that does what you want?

Alternately, in what situation do you end up with a driver.Rows rather then a sql.Rows? Maybe we can address the issue of using cursors with the sql package.

Thanks, -Daniel

For example

var v interface{}
sql.Exec(`BEGIN OPEN :1 FOR SELECT 1 FROM DUAL; END;`, sql.Out{Dest: &v})

How to return that cursor?
What should the user provide instead of interface{}, and what should the driver return?
How could it create an sql.Rows ? It can provide a driver.Rows, but I couldn't find a way to turn it into an sql.Rows.

Tamás

Daniel Theophanes

unread,
Nov 14, 2017, 2:56:21 PM11/14/17
to Tamás Gulácsi, golang-sql
That makes complete sense. Thanks for the context.
I'll look into it in the next couple of days.

--
You received this message because you are subscribed to the Google Groups "golang-sql" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-sql+...@googlegroups.com.
To post to this group, send email to golan...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-sql/9a90bf65-b03f-4942-8fd4-a4ff8d1118c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tamás Gulácsi

unread,
Nov 15, 2017, 11:33:01 AM11/15/17
to golang-sql

For example

var v interface{}
sql.Exec(`BEGIN OPEN :1 FOR SELECT 1 FROM DUAL; END;`, sql.Out{Dest: &v})

How to return that cursor?
What should the user provide instead of interface{}, and what should the driver return?
How could it create an sql.Rows ? It can provide a driver.Rows, but I couldn't find a way to turn it into an sql.Rows.

IMHO the most user-friendly way would be to allow the user to Dest into an *sql.Rows, the driver to return a driver.Rows, and
let the magic happen (fill the user-supplied sql.Rows as needed).

Tamás Gulácsi

unread,
Sep 17, 2018, 2:05:24 PM9/17/18
to golang-sql


2017. november 15., szerda 17:33:01 UTC+1 időpontban Tamás Gulácsi a következőt írta:

For example

var v interface{}
sql.Exec(`BEGIN OPEN :1 FOR SELECT 1 FROM DUAL; END;`, sql.Out{Dest: &v})

How to return that cursor?
What should the user provide instead of interface{}, and what should the driver return?
How could it create an sql.Rows ? It can provide a driver.Rows, but I couldn't find a way to turn it into an sql.Rows.


by executing QueryContext with the previously returned driver.Rows, and essentially just returning it.
This way a driver.Rows is getting wrapped as *sql.Rows.

Couldn't the database/sql package do this (return a driver.Rows as an *sql.Rows) in Scan?

Tamás Gulácsi

unread,
Oct 29, 2018, 5:41:03 PM10/29/18
to golang-sql
Ping.

Any follow up on this?

Daniel Theophanes

unread,
Oct 29, 2018, 7:30:27 PM10/29/18
to golang-sql
Can you try the CL  here: https://go-review.googlesource.com/c/go/+/145738 .

If you build Go from source, you can pull this CL to try it, look for the DOWNLOAD button above the file list.

Alternatively, you could send me some Oracle SQL and maybe some instructions to get oracle xe running on debian based systems or a service I could connect to to try it out.

Thanks, -Daniel

Tamás Gulácsi

unread,
Oct 30, 2018, 2:24:10 AM10/30/18
to golang-sql
2018. október 30., kedd 0:30:27 UTC+1 időpontban Daniel Theophanes a következőt írta:
Can you try the CL  here: https://go-review.googlesource.com/c/go/+/145738 .

If you build Go from source, you can pull this CL to try it, look for the DOWNLOAD button above the file list.

Alternatively, you could send me some Oracle SQL and maybe some instructions to get oracle xe running on debian based systems or a service I could connect to to try it out.

Thanks, -Daniel


Sure, I'll try.

Till that, you can use my test Oracle server at host=oracle.gthomas.eu port=49161 serviceName=xe user=test password=test
(the connection string is `user+"/"+password="@"+host+":"+port+"/"+serviceName).

It's in a Docker container, erased at every full hour.
SQL: `select cursor(select * from TestQuery) from dual` - copied from
page 39.

The CL is very nice!
Seems a simple addition - maybe `sql.*Rows.WrapCursor(cursori driver.Rows) *Rows` is surplus (Scan will convert into an *sql.Rows).
How/why would a user get a driver.Rows to be converted into an *sql.Rows ?

Thanks you for working on this!
Tamás Gulácsi
Reply all
Reply to author
Forward
0 new messages