Skip to content

Commit

Permalink
set rows.finish directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo82148 committed Jun 6, 2017
1 parent 1fdad70 commit 9b979f2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
4 changes: 4 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ func (mc *mysqlConn) exec(query string) error {
}

func (mc *mysqlConn) Query(query string, args []driver.Value) (driver.Rows, error) {
return mc.query(query, args)
}

func (mc *mysqlConn) query(query string, args []driver.Value) (*textRows, error) {
if mc.isBroken() {
errLog.Print(ErrInvalidConn)
return nil, driver.ErrBadConn
Expand Down
20 changes: 4 additions & 16 deletions connection_go18.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ import (
"errors"
)

type setfinish interface {
setFinish(f func())
}

// Ping implements driver.Pinger interface
func (mc *mysqlConn) Ping(ctx context.Context) error {
if mc.isBroken() {
Expand Down Expand Up @@ -81,16 +77,12 @@ func (mc *mysqlConn) QueryContext(ctx context.Context, query string, args []driv
return nil, err
}

rows, err := mc.Query(query, dargs)
rows, err := mc.query(query, dargs)
if err != nil {
mc.finish()
return nil, err
}
if set, ok := rows.(setfinish); ok {
set.setFinish(mc.finish)
} else {
mc.finish()
}
rows.finish = mc.finish
return rows, err
}

Expand Down Expand Up @@ -138,16 +130,12 @@ func (stmt *mysqlStmt) QueryContext(ctx context.Context, args []driver.NamedValu
return nil, err
}

rows, err := stmt.Query(dargs)
rows, err := stmt.query(dargs)
if err != nil {
stmt.mc.finish()
return nil, err
}
if set, ok := rows.(setfinish); ok {
set.setFinish(stmt.mc.finish)
} else {
stmt.mc.finish()
}
rows.finish = stmt.mc.finish
return rows, err
}

Expand Down
4 changes: 0 additions & 4 deletions rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ func (rows *mysqlRows) Columns() []string {
return columns
}

func (rows *mysqlRows) setFinish(f func()) {
rows.finish = f
}

func (rows *mysqlRows) Close() (err error) {
if f := rows.finish; f != nil {
f()
Expand Down
4 changes: 4 additions & 0 deletions statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func (stmt *mysqlStmt) Exec(args []driver.Value) (driver.Result, error) {
}

func (stmt *mysqlStmt) Query(args []driver.Value) (driver.Rows, error) {
return stmt.query(args)
}

func (stmt *mysqlStmt) query(args []driver.Value) (*binaryRows, error) {
if stmt.mc.isBroken() {
errLog.Print(ErrInvalidConn)
return nil, driver.ErrBadConn
Expand Down

0 comments on commit 9b979f2

Please sign in to comment.