Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

database/sql: support handling returned cursors #28515

Closed
kardianos opened this issue Oct 31, 2018 · 6 comments
Closed

database/sql: support handling returned cursors #28515

kardianos opened this issue Oct 31, 2018 · 6 comments

Comments

@kardianos
Copy link
Contributor

@kardianos kardianos commented Oct 31, 2018

Driver author @tgulacsi has created gopkg.in/goracle.v2, a go package for connecting to the Oracle database (there are a few others too). We would like to support returning cursors.

This has no API changes.

A client would cursors like:


import (
	"context"
	"database/sql"
	"testing"
	"time"

	_ "gopkg.in/goracle.v2"
)

func TestCursor(t *testing.T) {
	cn := "user/pass@hostname:port/instance"
	db, err := sql.Open("goracle", cn)
	defer db.Close()

	ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
	defer cancel()

	db.ExecContext(ctx, `drop table TestQuery`)

	defer db.ExecContext(ctx, `drop table TestQuery`)
	_, err = db.ExecContext(ctx, `
create table TestQuery (
	IntCol number(9) not null,
	StringCol varchar2(30) not null
);
begin
	for i in 1..10 loop
		insert into TestQuery values (power(3, i), '3 ^ ' || to_char(i));
	end loop;
	commit;
end;
	`)
	if err != nil {
		t.Fatal(err)
	}

	rows, err := db.QueryContext(ctx, `
select cursor(select * from TestQuery) from dual`)
	if err != nil {
		t.Fatal(err)
	}
	defer rows.Close()

	if !rows.Next() {
		t.Fatal("no rows")
	}
	var cursor = &sql.Rows{}
	err = rows.Scan(cursor)
	if err != nil {
		t.Fatal(err)
	}
	defer cursor.Close()

	var n int64
	var s string
	for cursor.Next() {
		err = cursor.Scan(&n, &s)
		if err != nil {
			t.Fatal(err)
		}
		t.Log(n, s)
	}

}

CL to follow.

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 31, 2018

Change https://golang.org/cl/145738 mentions this issue: database/sql: add support for returning cursors to client

@katiehockman
Copy link
Member

@katiehockman katiehockman commented Oct 31, 2018

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Nov 1, 2018

So this lets an *sql.Rows be a Scan target for *sql.Row.Scan?

SGTM, as long as it's documented.

@kardianos
Copy link
Contributor Author

@kardianos kardianos commented Nov 1, 2018

@tgulacsi
Copy link
Contributor

@tgulacsi tgulacsi commented Nov 9, 2018

Thanks to all!
So, this will be in Go 1.12 ?

@kardianos
Copy link
Contributor Author

@kardianos kardianos commented Nov 9, 2018

@golang golang locked and limited conversation to collaborators Nov 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.