From 1805f425ada8184b53175fd166b5fec7c02850a4 Mon Sep 17 00:00:00 2001 From: Daniel Theophanes Date: Fri, 26 Apr 2019 11:09:51 -0700 Subject: database/sql: check if src is nil before converting to string A nil src (NULL database value) will result in a "nil" string, which will never parse correctly in a ParseInt or similar numeric conversion. The resulting error is confusing. Check for a nil src prior to converting the value to string if the resulting string will be parsed after that. Closes #31274 Change-Id: I90f12cceff00fbbfdd3e343b04fa7e2596390e6d Reviewed-on: https://go-review.googlesource.com/c/go/+/174177 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/database/sql/sql_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/database/sql/sql_test.go') diff --git a/src/database/sql/sql_test.go b/src/database/sql/sql_test.go index c07c5d3bd2..cc30ad3daa 100644 --- a/src/database/sql/sql_test.go +++ b/src/database/sql/sql_test.go @@ -1401,7 +1401,7 @@ func TestInvalidNilValues(t *testing.T) { { name: "int", input: &date2, - expectedError: `sql: Scan error on column index 0, name "bdate": converting driver.Value type ("") to a int: invalid syntax`, + expectedError: `sql: Scan error on column index 0, name "bdate": converting NULL to int is unsupported`, }, } -- cgit v1.3