Skip to content

Add nil check in bind and a test #583

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

Merged
merged 2 commits into from
May 31, 2018

Conversation

lucasmrod
Copy link
Contributor

This is the fix for #542.

There are extensive tests in the existing TestNilAndEmptyBytes, but we cannot test the change in there because of how sqlite3_column_blob() works: "The return value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer." -> this means that both NULL and zero-length blob map to a nil byte slice. So... I ended up adding a separate test TestInsertNilByteSlice to check that storing a nil byte slice is now storing a NULL.

@coveralls
Copy link

coveralls commented May 31, 2018

Coverage Status

Coverage increased (+0.08%) to 61.161% when pulling 140b805 on lucasmrod:bug/#542-nil-byte-slice-to-null-blob into 5a7d2e2 on mattn:master.

var nilSlice []byte
if _, err := db.Exec("insert into blob_not_null (b) values (?)", nilSlice); err == nil {
t.Fatal("didn't expect INSERT to 'not null' column with a nil []byte slice to work")
}
Copy link
Owner

@mattn mattn May 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add test inserting 0 length slice too?

@mattn mattn merged commit 6d0b39d into mattn:master May 31, 2018
@mattn
Copy link
Owner

mattn commented May 31, 2018

Thank you!

@gjrtimmer
Copy link
Collaborator

@lucasmrod Thanks, great work

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

Successfully merging this pull request may close these issues.

4 participants