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

database/sql: convert null values to []byte as nil #2788

Closed
gopherbot opened this issue Jan 26, 2012 · 6 comments
Closed

database/sql: convert null values to []byte as nil #2788

gopherbot opened this issue Jan 26, 2012 · 6 comments
Milestone

Comments

@gopherbot
Copy link

by jamespcooper:

What steps will reproduce the problem?

add this test to database/sql/sql_test.go

func TestNullByteSlice(t *testing.T) {
    db := newTestDB(t, "")
    defer closeDB(t, db)
    exec(t, db, "CREATE|t|id=int32,name=string")
    exec(t, db, "INSERT|t|id=10,name=?", nil)

    var name []byte
    err := db.QueryRow("SELECT|t|name|id=?", 10).Scan(&name)
    if err != nil {
        t.Fatal(err)
    }
    if name != nil {
        t.Fatal("name []byte should be nil for null column value, got: %v", name)
    }

    exec(t, db, "INSERT|t|id=10,name=?", "bob")
    err = db.QueryRow("SELECT|t|name|id=?", 10).Scan(&name)
    if err != nil {
        t.Fatal(err)
    }
    if string(name) != "bob" {
        t.Fatal("name []byte should be bob, got: %s", string(name))
    }
}


What is the expected output?
Passing test

What do you see instead?

--- FAIL: sql.TestNullByteSlice (0.00 seconds)
    sql_test.go:354: sql: Scan error on column index 0: unsupported driver -> Scan pair: <nil> -> *[]uint8
FAIL


Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
Mac OS 10.6.8

Which revision are you using?  (hg identify)
7de66de3961c+ tip

Please provide any additional information below.
This is a follow up to #2699.  We decided to not introduce a NullBytes struct, but we
probably need to modify  convert.go's  convertAssign() to handle this case
@bradfitz
Copy link
Contributor

Comment 1:

Sounds good.  You want to take this on, James?

Owner changed to builder@golang.org.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Jan 26, 2012

Comment 2:

Labels changed: added priority-go1, removed priority-triage.

@gopherbot
Copy link
Author

Comment 3 by jamespcooper:

Yep, I'll give this a go

@gopherbot
Copy link
Author

Comment 4 by jamespcooper:

CL submitted for this issue:
http://golang.org/cl/5577054

@bradfitz
Copy link
Contributor

Comment 5:

Cool, thanks!
Btw, I think your emails to golang-dev are being moderated again. Sorry, Google Groups
has a bug and doesn't let us whitelist somebody for moderation unless they're a member
of the list.  Could you join that group, even if you set it to "No Email" mode?  Then
you have a row in their database where we can set the whitelisted bit.
Thanks!

Owner changed to @bradfitz.

@bradfitz
Copy link
Contributor

Comment 6:

This issue was closed by revision 2a22f35.

Status changed to Fixed.

@rsc rsc added this to the Go1 milestone Apr 10, 2015
@rsc rsc removed the priority-go1 label Apr 10, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants