Skip to content

Commit dba7a5b

Browse files
committed
NULL insertion fix
1 parent 6a6eac9 commit dba7a5b

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

Diff for: driver_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,24 @@ func TestNULL(t *testing.T) {
481481
} else if ns.String != `1` {
482482
t.Error("Unexpected NullString value:" + ns.String + " (should be `1`)")
483483
}
484+
485+
// Insert NULL
486+
mustExec(t, db, "CREATE TABLE test (dummmy1 int, value int, dummy2 int)")
487+
488+
mustExec(t, db, ("INSERT INTO test VALUES (?, ?, ?)"), 1, nil, 2)
489+
490+
var out interface{}
491+
rows := mustQuery(t, db, ("SELECT * FROM test"))
492+
if rows.Next() {
493+
rows.Scan(&out)
494+
if out != nil {
495+
t.Errorf("%v != nil", out)
496+
}
497+
} else {
498+
t.Error("no data")
499+
}
500+
501+
mustExec(t, db, "DROP TABLE IF EXISTS test")
484502
}
485503

486504
// Special cases

Diff for: packets.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -671,17 +671,17 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
671671
pos := 14 + ((stmt.paramCount + 7) >> 3)
672672
// Convert bitMask to bytes
673673
for i = 14; i < pos; i++ {
674-
data[i] = byte(bitMask >> uint(i<<3))
674+
data[i] = byte(bitMask >> uint((i-14)<<3))
675675
}
676676

677677
// newParameterBoundFlag 1 [1 byte]
678678
data[pos] = 0x01
679679
pos++
680680

681-
// type of parameters [param_count*2 byte]
681+
// type of parameters [param_count*2 bytes]
682682
pos += copy(data[pos:], paramTypes)
683683

684-
// values for the parameters [n byte]
684+
// values for the parameters [n bytes]
685685
for i = range paramValues {
686686
pos += copy(data[pos:], paramValues[i])
687687
}

0 commit comments

Comments
 (0)