revert Multiple Result Set

csv
Yasuhiro Matsumoto 2016-11-08 13:22:46 +09:00
parent dc448a0cb6
commit ea2afbe9e8
2 changed files with 1 additions and 79 deletions

View File

@ -191,7 +191,6 @@ type SQLiteRows struct {
decltype []string decltype []string
cls bool cls bool
done chan struct{} done chan struct{}
next *SQLiteRows
} }
type functionInfo struct { type functionInfo struct {
@ -471,7 +470,6 @@ func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, erro
} }
func (c *SQLiteConn) query(ctx context.Context, query string, args []namedValue) (driver.Rows, error) { func (c *SQLiteConn) query(ctx context.Context, query string, args []namedValue) (driver.Rows, error) {
var top, cur *SQLiteRows
start := 0 start := 0
for { for {
s, err := c.Prepare(query) s, err := c.Prepare(query)
@ -489,14 +487,7 @@ func (c *SQLiteConn) query(ctx context.Context, query string, args []namedValue)
rows, err := s.(*SQLiteStmt).query(ctx, args[:na]) rows, err := s.(*SQLiteStmt).query(ctx, args[:na])
if err != nil && err != driver.ErrSkip { if err != nil && err != driver.ErrSkip {
s.Close() s.Close()
return top, err return rows, err
}
if top == nil {
top = rows.(*SQLiteRows)
cur = top
} else {
cur.next = rows.(*SQLiteRows)
cur = cur.next
} }
args = args[na:] args = args[na:]
start += na start += na
@ -772,7 +763,6 @@ func (s *SQLiteStmt) query(ctx context.Context, args []namedValue) (driver.Rows,
decltype: nil, decltype: nil,
cls: s.cls, cls: s.cls,
done: make(chan struct{}), done: make(chan struct{}),
next: nil,
} }
go func() { go func() {
@ -970,15 +960,3 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error {
} }
return nil return nil
} }
func (rc *SQLiteRows) HasNextResultSet() bool {
return rc.next != nil
}
func (rc *SQLiteRows) NextResultSet() error {
if rc.next == nil {
return io.EOF
}
*rc = *rc.next
return nil
}

View File

@ -9,7 +9,6 @@ package sqlite3
import ( import (
"database/sql" "database/sql"
"fmt"
"os" "os"
"testing" "testing"
) )
@ -49,58 +48,3 @@ func TestNamedParams(t *testing.T) {
t.Error("Failed to db.QueryRow: not matched results") t.Error("Failed to db.QueryRow: not matched results")
} }
} }
func TestMultipleResultSet(t *testing.T) {
tempFilename := TempFilename(t)
defer os.Remove(tempFilename)
db, err := sql.Open("sqlite3", tempFilename)
if err != nil {
t.Fatal("Failed to open database:", err)
}
defer db.Close()
_, err = db.Exec(`
create table foo (id integer, name text);
`)
if err != nil {
t.Error("Failed to call db.Query:", err)
}
for i := 0; i < 100; i++ {
_, err = db.Exec(`insert into foo(id, name) values(?, ?)`, i+1, fmt.Sprintf("foo%03d", i+1))
if err != nil {
t.Error("Failed to call db.Exec:", err)
}
}
rows, err := db.Query(`
select id, name from foo where id < :id1;
select id, name from foo where id = :id2;
select id, name from foo where id > :id3;
`,
sql.Param(":id1", 3),
sql.Param(":id2", 50),
sql.Param(":id3", 98),
)
if err != nil {
t.Error("Failed to call db.Query:", err)
}
var id int
var extra string
for {
for rows.Next() {
err = rows.Scan(&id, &extra)
if err != nil {
t.Error("Failed to db.Scan:", err)
}
if id != 1 || extra != "foo" {
t.Error("Failed to db.QueryRow: not matched results")
}
}
if !rows.NextResultSet() {
break
}
}
}