nakagami / firebirdsql

Firebird RDBMS sql driver for Go (golang)
MIT License
229 stars 60 forks source link

Error inserting null values to DB #49

Closed ghost closed 6 years ago

ghost commented 7 years ago

Almost every null value that I try to insert gives an ERROR now. I suggest a new test with every single type of var using "null".

This time u don't even need to ask for an example... Here it go ;)

sqlCreate := `
    CREATE TABLE NullTest (
        id INTEGER generated by default as identity primary key,
        name VARCHAR(60) NOT NULL,
        nullname VARCHAR(10),
        nullDate DATE,
        bug1 SMALLINT,
        bug2 INTEGER
    )
`
_, err := dbconfig.DBConn.Exec(sqlCreate)
if err != nil { fmt.Println(err) }

// FAIL
sqlTest1 := `
    insert into NullTest (name, bug1, bug2)
    values ('Giovanni', ?, ?)
`
_, err = dbconfig.DBConn.Exec(sqlTest1, nil, nil)
if err != nil {
    fmt.Println("Test 1: ", err)
} else { fmt.Println("Test 1: OK") }

// WORK
sqlTest2 := `
    insert into NullTest (name, nullname, nullDate)
    values ('Giovanni', ?, ?)
`
_, err = dbconfig.DBConn.Exec(sqlTest2, nil, nil)
if err != nil {
    fmt.Println("Test 2: ", err)
} else { fmt.Println("Test 2: OK") }

// WORK
var strDate = "2017-10-24"
var nullName *string
sqlTest3 := `
    insert into NullTest (name, nullname, nullDate)
    values ('Giovanni', ?, ?)
`
_, err = dbconfig.DBConn.Exec(sqlTest3, nullName, strDate)
if err != nil {
    fmt.Println("Test 3: ", err)
} else { fmt.Println("Test 3: OK") }

// FAIL
var nullDate *string // Since it's just a "null" value, it should work
sqlTest4 := `
    insert into NullTest (name, nullDate)
    values ('Giovanni', ?)
`
_, err = dbconfig.DBConn.Exec(sqlTest4, nullDate)
//_, err = dbconfig.DBConn.Exec(sqlTest4, nil) // also fails
if err != nil {
    fmt.Println("Test 4: ", err)
} else { fmt.Println("Test 4: OK") }

// WORK
sqlTest5 := `
    insert into NullTest (name, nullDate)
    values ('Giovanni', null)
`
_, err = dbconfig.DBConn.Exec(sqlTest5)
if err != nil {
    fmt.Println("Test 5: ", err)
} else { fmt.Println("Test 5: OK") }

sqlDrop := `
    drop table NullTest
`
dbconfig.DBConn.Exec(sqlDrop)

Thank You again for ur time.

ghost commented 7 years ago

I believe the error is in this piece of code inside "wireprotocol.go": case nil: v = []byte{} blr = []byte{14, 0, 0}

I have no idea how it works, but maybe the values are not correct...