-
Notifications
You must be signed in to change notification settings - Fork 42
Open
Description
When I pass []byte(nil) as an argument to INSERT, unexpected FOREIGN KEY violation happens.
Expected behavior
Row is successfully inserted.
Actual behavior
Error is returned from INSERT: constraint failed: FOREIGN KEY constraint failed (787)
However:
- Using modernc.org/sqlite@v1.36.0 as a driver works fine.
- Using github.com/mattn/go-sqlite3@v1.14.24 as a driver works fine.
- Passing
nil(not[]byte(nil)) works fine. - If foreign key constraints are disabled, the row is inserted successfully and has correct NULL value as parent_id.
Code to reproduce
package main
import (
"database/sql"
"log"
_ "github.com/glebarez/go-sqlite"
)
func main() {
db, err := sql.Open("sqlite", ":memory:?_pragma=foreign_keys(1)&_pragma=busy_timeout(10000)&_pragma=journal_mode(WAL)")
if err != nil {
log.Fatalln(err)
}
defer db.Close()
db.SetMaxOpenConns(1)
db.SetMaxIdleConns(1)
_, err = db.Exec(`CREATE TABLE test(id BLOB NOT NULL PRIMARY KEY, parent_id BLOB DEFAULT NULL REFERENCES test(id))`)
if err != nil {
log.Fatalln(err)
}
log.Println("create table ok")
_, err = db.Exec(`INSERT INTO test(id, parent_id) VALUES (?, ?)`, []byte("abc"), []byte(nil))
if err != nil {
log.Fatalln(err)
}
log.Println("insert ok")
}Metadata
Metadata
Assignees
Labels
No labels