Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nil values not stored in database #15

Open
GoogleCodeExporter opened this issue Oct 26, 2015 · 0 comments
Open

Nil values not stored in database #15

GoogleCodeExporter opened this issue Oct 26, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Create prepared statement
2. Try to bind nil to one of the "?" parameters

What is the expected output? What do you see instead?
Stores "" or "<nil>", instead of null column value.  


Please provide any additional information below.

Seems like a pretty easy fix:

diff -r a88eb4732139 sqlite/sqlite.go
--- a/sqlite/sqlite.go  Wed Nov 02 13:57:15 2011 -0400
+++ b/sqlite/sqlite.go  Mon Jan 09 15:57:50 2012 -0500
@@ -275,6 +275,10 @@

    for i, v := range args {
        var str string
+       var rv C.int
+       if v == nil {
+           rv = C.sqlite3_bind_null(s.stmt, C.int(i+1))
+       } else {
        switch v := v.(type) {
        case []byte:
            var p *byte
@@ -298,8 +302,9 @@
        }

        cstr := C.CString(str)
-       rv := C.my_bind_text(s.stmt, C.int(i+1), cstr, C.int(len(str)))
+           rv = C.my_bind_text(s.stmt, C.int(i+1), cstr, C.int(len(str)))
        C.free(unsafe.Pointer(cstr))
+       }
        if rv != 0 {
            return s.c.error(rv)
        }


Original issue reported on code.google.com by graham.m...@gmail.com on 9 Jan 2012 at 9:00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant