diff --git a/doc/changes/changes_1.0.9.md b/doc/changes/changes_1.0.9.md index 1e5a1ce..98b0ed6 100644 --- a/doc/changes/changes_1.0.9.md +++ b/doc/changes/changes_1.0.9.md @@ -7,7 +7,13 @@ Code name: Fix reading int values This release fixes an issue when calling `rows.Scan(&result)` with an int value. This failed for large values like 100000000 with the following error: ``` -sql: Scan error on column index 0, name "100000000": converting driver.Value type float64 ("1e+08") to a int64: invalid syntax +sql: Scan error on column index 0, name "COL": converting driver.Value type float64 ("1e+08") to a int64: invalid syntax +``` + +Please note that reading non-integer numbers like `1.1` into a `int64` variable will still fail with the following error message: + +``` +sql: Scan error on column index 0, name "COL": converting driver.Value type string ("1.1") to a int64: invalid syntax ``` The release also now returns the correct error from `rows.Err()`. Before, this only returned `driver.ErrBadConn`. diff --git a/itest/integration_test.go b/itest/integration_test.go index c0296ac..f6d9fe7 100644 --- a/itest/integration_test.go +++ b/itest/integration_test.go @@ -338,6 +338,8 @@ func (suite *IntegrationTestSuite) TestPreparedStatementArgsConverted() { int64TestCase(-1, "DECIMAL(18,0)", -1), int64TestCase(1.1, "DECIMAL(18,0)", 1), int64TestCase(-1.1, "DECIMAL(18,0)", -1), + int64TestCase(1.1, "DECIMAL(18,2)", 1), + int64TestCase(-1.1, "DECIMAL(18,2)", -1), int64TestCase(100000000, "DECIMAL(18,0)", 100000000), int64TestCase(-100000000, "DECIMAL(18,0)", -100000000), int64TestCase(100000000, "DECIMAL(18,2)", 100000000), @@ -435,14 +437,14 @@ func (suite *IntegrationTestSuite) TestPreparedStatementArgsConversionFails() { func (suite *IntegrationTestSuite) TestScanTypeUnsupported() { for i, testCase := range []struct { - testDescription string - sqlValue any - sqlType string - scanDest any - expectedError string + sqlValue any + sqlType string + scanDest any + expectedError string }{ - {"timestamp", time.Date(2024, time.June, 18, 17, 22, 13, 123456789, time.UTC), "TIMESTAMP", new(time.Time), `sql: Scan error on column index 0, name "COL": unsupported Scan, storing driver.Value type string into type *time.Time`}, - {"timestamp with local time zone", time.Date(2024, time.June, 18, 17, 22, 13, 123456789, time.UTC), "TIMESTAMP WITH LOCAL TIME ZONE", new(time.Time), `sql: Scan error on column index 0, name "COL": unsupported Scan, storing driver.Value type string into type *time.Time`}, + {1.1, "DECIMAL(4,2)", new(int64), `converting driver.Value type string ("1.1") to a int64: invalid syntax`}, + {time.Date(2024, time.June, 18, 17, 22, 13, 123456789, time.UTC), "TIMESTAMP", new(time.Time), `unsupported Scan, storing driver.Value type string into type *time.Time`}, + {time.Date(2024, time.June, 18, 17, 22, 13, 123456789, time.UTC), "TIMESTAMP WITH LOCAL TIME ZONE", new(time.Time), `unsupported Scan, storing driver.Value type string into type *time.Time`}, } { database := suite.openConnection(suite.createDefaultConfig().Autocommit(false)) schemaName := "DATATYPE_TEST" @@ -450,7 +452,7 @@ func (suite *IntegrationTestSuite) TestScanTypeUnsupported() { onError(err) defer suite.cleanup(database, schemaName) - suite.Run(fmt.Sprintf("Scan fails %02d %s: %s", i, testCase.testDescription, testCase.sqlType), func() { + suite.Run(fmt.Sprintf("Scan fails %02d %s", i, testCase.sqlType), func() { tableName := fmt.Sprintf("%s.TAB_%d", schemaName, i) _, err = database.Exec(fmt.Sprintf("CREATE TABLE %s (col %s)", tableName, testCase.sqlType)) onError(err) @@ -463,7 +465,7 @@ func (suite *IntegrationTestSuite) TestScanTypeUnsupported() { defer rows.Close() suite.True(rows.Next(), "should have one row") err = rows.Scan(testCase.scanDest) - suite.EqualError(err, testCase.expectedError) + suite.EqualError(err, `sql: Scan error on column index 0, name "COL": `+testCase.expectedError) }) } }