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

Handle nil params in ExecuteSql #75

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions executesql.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ func go2SqlDataType(value interface{}) (string, string, error) {

strValue := fmt.Sprintf("%v", value)
switch t := value.(type) {
case nil:
return "nvarchar (1)", "NULL", nil
case bool:
bitStrValue := "0"
if strValue == "true" {
Expand Down
1 change: 1 addition & 0 deletions executesql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func TestGoTo2SqlDataType(t *testing.T) {
checker([]byte{1, 2, 3, 4, 5, 6, 7, 8}, "varbinary (8)", "0x0102030405060708")

checker("", "nvarchar (1)", "''")
checker(nil, "nvarchar (1)", "NULL")
checker(true, "bit", "1")
checker(false, "bit", "0")
}
Expand Down