Browse Source

NULL insertion fix

Julien Schmidt 13 years ago
parent
commit
dba7a5bc1e
2 changed files with 21 additions and 3 deletions
  1. 18 0
      driver_test.go
  2. 3 3
      packets.go

+ 18 - 0
driver_test.go

@@ -481,6 +481,24 @@ func TestNULL(t *testing.T) {
 	} else if ns.String != `1` {
 		t.Error("Unexpected NullString value:" + ns.String + " (should be `1`)")
 	}
+
+	// Insert NULL
+	mustExec(t, db, "CREATE TABLE test (dummmy1 int, value int, dummy2 int)")
+
+	mustExec(t, db, ("INSERT INTO test VALUES (?, ?, ?)"), 1, nil, 2)
+
+	var out interface{}
+	rows := mustQuery(t, db, ("SELECT * FROM test"))
+	if rows.Next() {
+		rows.Scan(&out)
+		if out != nil {
+			t.Errorf("%v != nil", out)
+		}
+	} else {
+		t.Error("no data")
+	}
+
+	mustExec(t, db, "DROP TABLE IF EXISTS test")
 }
 
 // Special cases

+ 3 - 3
packets.go

@@ -671,17 +671,17 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
 		pos := 14 + ((stmt.paramCount + 7) >> 3)
 		// Convert bitMask to bytes
 		for i = 14; i < pos; i++ {
-			data[i] = byte(bitMask >> uint(i<<3))
+			data[i] = byte(bitMask >> uint((i-14)<<3))
 		}
 
 		// newParameterBoundFlag 1 [1 byte]
 		data[pos] = 0x01
 		pos++
 
-		// type of parameters [param_count*2 byte]
+		// type of parameters [param_count*2 bytes]
 		pos += copy(data[pos:], paramTypes)
 
-		// values for the parameters [n byte]
+		// values for the parameters [n bytes]
 		for i = range paramValues {
 			pos += copy(data[pos:], paramValues[i])
 		}