Browse Source

Minor stylistic improvement, added a test

Arne Hormann 11 years ago
parent
commit
4834ee6ac2
2 changed files with 15 additions and 4 deletions
  1. 4 4
      connection.go
  2. 11 0
      driver_test.go

+ 4 - 4
connection.go

@@ -222,12 +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)
-				} else {
+				if resLen == 0 {
+					// no columns, no more data
 					return emptyRows{}, nil
 				}
+				// Columns
+				rows.columns, err = mc.readColumns(resLen)
 				return rows, err
 			}
 		}

+ 11 - 0
driver_test.go

@@ -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