Skip to content

Commit

Permalink
remove columns definition cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed May 11, 2017
1 parent 3361273 commit 51742f9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 32 deletions.
23 changes: 3 additions & 20 deletions rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ type mysqlRows struct {

type binaryRows struct {
mysqlRows
// stmtCols is a pointer to the statement's cached columns for different
// result sets.
stmtCols *[][]mysqlField
// i is a number of the current result set. It is used to fetch proper
// columns from stmtCols.
i int
}

type textRows struct {
Expand Down Expand Up @@ -132,25 +126,14 @@ func (rows *mysqlRows) nextNotEmptyResultSet() (int, error) {
}
}

func (rows *binaryRows) NextResultSet() (err error) {
func (rows *binaryRows) NextResultSet() error {
resLen, err := rows.nextNotEmptyResultSet()
if err != nil {
return err
}

// get columns, if not cached, read them and cache them.
if rows.i >= len(*rows.stmtCols) {
rows.rs.columns, err = rows.mc.readColumns(resLen)
*rows.stmtCols = append(*rows.stmtCols, rows.rs.columns)
} else {
rows.rs.columns = (*rows.stmtCols)[rows.i]
if err := rows.mc.readUntilEOF(); err != nil {
return err
}
}

rows.i++
return nil
rows.rs.columns, err = rows.mc.readColumns(resLen)
return err
}

func (rows *binaryRows) Next(dest []driver.Value) error {
Expand Down
13 changes: 1 addition & 12 deletions statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type mysqlStmt struct {
mc *mysqlConn
id uint32
paramCount int
columns [][]mysqlField // cached from the first query
}

func (stmt *mysqlStmt) Close() error {
Expand Down Expand Up @@ -109,20 +108,10 @@ func (stmt *mysqlStmt) Query(args []driver.Value) (driver.Rows, error) {
}

rows := new(binaryRows)
rows.stmtCols = &stmt.columns

if resLen > 0 {
rows.mc = mc
rows.i++
// Columns
// If not cached, read them and cache them
if len(stmt.columns) == 0 {
rows.rs.columns, err = mc.readColumns(resLen)
stmt.columns = append(stmt.columns, rows.rs.columns)
} else {
rows.rs.columns = stmt.columns[0]
err = mc.readUntilEOF()
}
rows.rs.columns, err = mc.readColumns(resLen)
} else {
rows.rs.done = true

Expand Down

0 comments on commit 51742f9

Please sign in to comment.