瀏覽代碼

Avoid phantom nil values

Julien Schmidt 12 年之前
父節點
當前提交
1a23242996
共有 2 個文件被更改,包括 11 次插入1 次删除
  1. 10 0
      driver_test.go
  2. 1 1
      utils.go

+ 10 - 0
driver_test.go

@@ -613,6 +613,16 @@ func TestNULL(t *testing.T) {
 			dbt.Error("Unexpected NullString value:" + ns.String + " (should be `1`)")
 		}
 
+		// bytes
+		// Check input==output with input!=nil
+		b := []byte("")
+		if err = dbt.db.QueryRow("SELECT ?", b).Scan(&b); err != nil {
+			dbt.Fatal(err)
+		}
+		if b == nil {
+			dbt.Error("nil echo from non-nil input")
+		}
+
 		// Insert NULL
 		dbt.mustExec("CREATE TABLE test (dummmy1 int, value int, dummy2 int)")
 

+ 1 - 1
utils.go

@@ -349,7 +349,7 @@ func readLengthEnodedString(b []byte) ([]byte, bool, int, error) {
 	// Get length
 	num, isNull, n := readLengthEncodedInteger(b)
 	if num < 1 {
-		return nil, isNull, n, nil
+		return b[n:n], isNull, n, nil
 	}
 
 	n += int(num)