Skip to content
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
8 changes: 5 additions & 3 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,12 @@ func (mc *mysqlConn) Query(query string, args []driver.Value) (driver.Rows, erro
rows := new(textRows)
rows.mc = mc

if resLen > 0 {
// Columns
rows.columns, err = mc.readColumns(resLen)
if resLen == 0 {
// no columns, no more data
return emptyRows{}, nil
}
// Columns
rows.columns, err = mc.readColumns(resLen)
return rows, err
}
}
Expand Down
11 changes: 11 additions & 0 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ func (dbt *DBTest) mustQuery(query string, args ...interface{}) (rows *sql.Rows)
return rows
}

func TestEmptyQuery(t *testing.T) {
runTests(t, dsn, func(dbt *DBTest) {
// just a comment, no query
rows := dbt.mustQuery("--")
// will hang before #255
if rows.Next() {
dbt.Errorf("Next on rows must be false")
}
})
}

func TestCRUD(t *testing.T) {
runTests(t, dsn, func(dbt *DBTest) {
// Create Table
Expand Down
14 changes: 14 additions & 0 deletions rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type textRows struct {
mysqlRows
}

type emptyRows struct{}

func (rows *mysqlRows) Columns() []string {
columns := make([]string, len(rows.columns))
for i := range columns {
Expand Down Expand Up @@ -84,3 +86,15 @@ func (rows *textRows) Next(dest []driver.Value) error {
}
return io.EOF
}

func (rows emptyRows) Columns() []string {
return nil
}

func (rows emptyRows) Close() error {
return nil
}

func (rows emptyRows) Next(dest []driver.Value) error {
return io.EOF
}