Skip to content

remove columns definition cache. #592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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