Commit b69b933c authored by Yaacov Akiba Slama's avatar Yaacov Akiba Slama

Add support for NULL values

parent 736c530a
......@@ -10,3 +10,4 @@ Alexander Menzhinsky <[email protected]>
David Skinner <[email protected]>
Jan Mercl <[email protected]>
Steffen Butzer <steffen(dot)[email protected]>
Yaacov Akiba Slama <[email protected]>
\ No newline at end of file
package sqlite
import (
"database/sql"
"testing"
)
func TestNullBinding(t *testing.T) {
db, err := sql.Open("sqlite", "file::memory:")
if err != nil {
t.Errorf("cannot open: %v", err)
return
}
_, err = db.Exec(`
CREATE TABLE table1 (field1 varchar NULL);
INSERT INTO table1 (field1) VALUES (?);
`, sql.NullString{})
if err != nil {
t.Errorf("Error binding null: %v", err)
}
err = db.Close()
if err != nil {
t.Errorf("cannot close: %v", err)
return
}
}
......@@ -916,6 +916,10 @@ func (c *conn) bind(pstmt uintptr, n int, args []driver.NamedValue) (allocs []ui
if p, err = c.bindText(pstmt, i, x.String()); err != nil {
return allocs, err
}
case nil:
if p, err = c.bindNull(pstmt, i); err != nil {
return allocs, err
}
default:
return allocs, fmt.Errorf("sqlite: invalid driver.Value type %T", x)
}
......@@ -926,6 +930,15 @@ func (c *conn) bind(pstmt uintptr, n int, args []driver.NamedValue) (allocs []ui
return allocs, nil
}
// int sqlite3_bind_null(sqlite3_stmt*, int);
func (c *conn) bindNull(pstmt uintptr, idx1 int) (uintptr, error) {
if rc := sqlite3.Xsqlite3_bind_null(c.tls, pstmt, int32(idx1)); rc != sqlite3.SQLITE_OK {
return 0, c.errstr(rc)
}
return 0, nil
}
// int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
func (c *conn) bindText(pstmt uintptr, idx1 int, value string) (uintptr, error) {
p, err := libc.CString(value)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment