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

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

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

@katiehockman
Copy link
Contributor

/cc @bradfitz @kardianos

@katiehockman katiehockman added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Oct 31, 2018
@bradfitz
Copy link
Contributor

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 commented Nov 1, 2018 via email

@kardianos kardianos added Proposal-Accepted and removed NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Nov 1, 2018
@tgulacsi
Copy link
Contributor

tgulacsi commented Nov 9, 2018

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

@kardianos
Copy link
Contributor Author

kardianos commented Nov 9, 2018 via email

@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
Development

No branches or pull requests

5 participants