Skip to content

Commit 4834ee6

Browse files
committed
Minor stylistic improvement, added a test
1 parent 72f6900 commit 4834ee6

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

connection.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,12 @@ func (mc *mysqlConn) Query(query string, args []driver.Value) (driver.Rows, erro
222222
rows := new(textRows)
223223
rows.mc = mc
224224

225-
if resLen > 0 {
226-
// Columns
227-
rows.columns, err = mc.readColumns(resLen)
228-
} else {
225+
if resLen == 0 {
226+
// no columns, no more data
229227
return emptyRows{}, nil
230228
}
229+
// Columns
230+
rows.columns, err = mc.readColumns(resLen)
231231
return rows, err
232232
}
233233
}

driver_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ func (dbt *DBTest) mustQuery(query string, args ...interface{}) (rows *sql.Rows)
117117
return rows
118118
}
119119

120+
func TestEmptyQuery(t *testing.T) {
121+
runTests(t, dsn, func(dbt *DBTest) {
122+
// just a comment, no query
123+
rows := dbt.mustQuery("--")
124+
// will hang before #255
125+
if rows.Next() {
126+
dbt.Errorf("Next on rows must be false")
127+
}
128+
})
129+
}
130+
120131
func TestCRUD(t *testing.T) {
121132
runTests(t, dsn, func(dbt *DBTest) {
122133
// Create Table

0 commit comments

Comments
 (0)