Skip to content

Commit 72f6900

Browse files
committed
Fix handling of queries without columns and rows
1 parent 7094cf0 commit 72f6900

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

connection.go

+2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ func (mc *mysqlConn) Query(query string, args []driver.Value) (driver.Rows, erro
225225
if resLen > 0 {
226226
// Columns
227227
rows.columns, err = mc.readColumns(resLen)
228+
} else {
229+
return emptyRows{}, nil
228230
}
229231
return rows, err
230232
}

rows.go

+14
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ type textRows struct {
3232
mysqlRows
3333
}
3434

35+
type emptyRows struct{}
36+
3537
func (rows *mysqlRows) Columns() []string {
3638
columns := make([]string, len(rows.columns))
3739
for i := range columns {
@@ -84,3 +86,15 @@ func (rows *textRows) Next(dest []driver.Value) error {
8486
}
8587
return io.EOF
8688
}
89+
90+
func (rows emptyRows) Columns() []string {
91+
return nil
92+
}
93+
94+
func (rows emptyRows) Close() error {
95+
return nil
96+
}
97+
98+
func (rows emptyRows) Next(dest []driver.Value) error {
99+
return io.EOF
100+
}

0 commit comments

Comments
 (0)