diff options
| author | Daniel Theophanes <kardianos@gmail.com> | 2018-10-29 16:22:37 -0700 |
|---|---|---|
| committer | Daniel Theophanes <kardianos@gmail.com> | 2018-11-08 21:19:17 +0000 |
| commit | 968742a824de0a6459d2820d11b9e2e58803f472 (patch) | |
| tree | 946104b6aa08dd0e575944ee2b56f1ba16711d80 /src/database/sql/sql.go | |
| parent | ad4a58e31501bce5de2aad90a620eaecdc1eecb8 (diff) | |
| download | go-968742a824de0a6459d2820d11b9e2e58803f472.tar.xz | |
database/sql: add support for returning cursors to client
This CL add support for converting a returned cursor (presented
to this package as a driver.Rows) and scanning it into a *Rows.
Fixes #28515
Change-Id: Id8191c568dc135af9e5e8555efcd01987708edcb
Reviewed-on: https://go-review.googlesource.com/c/145738
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/database/sql/sql.go')
| -rw-r--r-- | src/database/sql/sql.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go index 099701ce7c..71800aae83 100644 --- a/src/database/sql/sql.go +++ b/src/database/sql/sql.go @@ -2882,6 +2882,7 @@ func rowsColumnInfoSetupConnLocked(rowsi driver.Rows) []*ColumnType { // *float32, *float64 // *interface{} // *RawBytes +// *Rows (cursor value) // any type implementing Scanner (see Scanner docs) // // In the most simple case, if the type of the value from the source @@ -2918,6 +2919,11 @@ func rowsColumnInfoSetupConnLocked(rowsi driver.Rows) []*ColumnType { // // For scanning into *bool, the source may be true, false, 1, 0, or // string inputs parseable by strconv.ParseBool. +// +// Scan can also convert a cursor returned from a query, such as +// "select cursor(select * from my_table) from dual", into a +// *Rows value that can itself be scanned from. The parent +// select query will close any cursor *Rows if the parent *Rows is closed. func (rs *Rows) Scan(dest ...interface{}) error { rs.closemu.RLock() @@ -2939,7 +2945,7 @@ func (rs *Rows) Scan(dest ...interface{}) error { return fmt.Errorf("sql: expected %d destination arguments in Scan, not %d", len(rs.lastcols), len(dest)) } for i, sv := range rs.lastcols { - err := convertAssign(dest[i], sv) + err := convertAssignRows(dest[i], sv, rs) if err != nil { return fmt.Errorf(`sql: Scan error on column index %d, name %q: %v`, i, rs.rowsi.Columns()[i], err) } |
