-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
[]byte{} should be converted to empty BLOB instead of NULL, []byte{} != nil in go.
I use following table to reproduce my issue.
CREATE TABLE test (
field BLOB NOT NULL
);Following code will report NOT NULL constraint failed error, but it's ok to execute INSERT INTO test (field) VALUES ('') in command line tool.
_, err := db.Exec(`INSERT INTO test (field) VALUES (?)`, []byte{})
// err = "NOT NULL constraint failed"https://github.com/mattn/go-sqlite3/blob/master/sqlite3.go#L776 calls sqlite3_bind_blob with buffer=nil when len(buffer) = 0, but according to Sqlite C Interface, it shouldn't.
If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16() or sqlite3_bind_blob() is a NULL pointer then the fourth parameter is ignored and the end result is the same as sqlite3_bind_null().
Maybe we should make([]byte, 1) then pass its address and length=0 to sqlite3_bind_blob.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels