Commit 624e05cd authored by gwenn's avatar gwenn

Fix database/sql/driver impl based on tip.

parent aa12f9e2
...@@ -27,6 +27,9 @@ type connImpl struct { ...@@ -27,6 +27,9 @@ type connImpl struct {
c *Conn c *Conn
} }
type stmtImpl struct { type stmtImpl struct {
s *Stmt
}
type rowsImpl struct {
s *Stmt s *Stmt
columnNames []string // cache columnNames []string // cache
} }
...@@ -68,7 +71,7 @@ func (c *connImpl) Prepare(query string) (driver.Stmt, error) { ...@@ -68,7 +71,7 @@ func (c *connImpl) Prepare(query string) (driver.Stmt, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &stmtImpl{s, nil}, nil return &stmtImpl{s}, nil
} }
func (c *connImpl) Close() error { func (c *connImpl) Close() error {
...@@ -121,7 +124,7 @@ func (s *stmtImpl) Query(args []driver.Value) (driver.Rows, error) { ...@@ -121,7 +124,7 @@ func (s *stmtImpl) Query(args []driver.Value) (driver.Rows, error) {
if err := s.bind(args); err != nil { if err := s.bind(args); err != nil {
return nil, err return nil, err
} }
return s, nil return &rowsImpl{s.s, nil}, nil
} }
func (s *stmtImpl) bind(args []driver.Value) error { func (s *stmtImpl) bind(args []driver.Value) error {
...@@ -133,16 +136,15 @@ func (s *stmtImpl) bind(args []driver.Value) error { ...@@ -133,16 +136,15 @@ func (s *stmtImpl) bind(args []driver.Value) error {
return nil return nil
} }
// TODO Cache result? func (r *rowsImpl) Columns() []string {
func (s *stmtImpl) Columns() []string { if r.columnNames == nil {
if s.columnNames == nil { r.columnNames = r.s.ColumnNames()
s.columnNames = s.s.ColumnNames()
} }
return s.columnNames return r.columnNames
} }
func (s *stmtImpl) Next(dest []driver.Value) error { func (r *rowsImpl) Next(dest []driver.Value) error {
ok, err := s.s.Next() ok, err := r.s.Next()
if err != nil { if err != nil {
return err return err
} }
...@@ -150,7 +152,11 @@ func (s *stmtImpl) Next(dest []driver.Value) error { ...@@ -150,7 +152,11 @@ func (s *stmtImpl) Next(dest []driver.Value) error {
return io.EOF return io.EOF
} }
for i := range dest { for i := range dest {
dest[i] = s.s.ScanValue(i) dest[i] = r.s.ScanValue(i)
} }
return nil return nil
} }
func (r *rowsImpl) Close() error {
return r.s.Reset()
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment