Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Jun 27, 2024
1 parent 78377e6 commit ddbaaa1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
8 changes: 7 additions & 1 deletion doc/changes/changes_1.0.9.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
20 changes: 11 additions & 9 deletions itest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -435,22 +437,22 @@ 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"
_, err := database.Exec("CREATE SCHEMA " + schemaName)
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)
Expand All @@ -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)
})
}
}
Expand Down

0 comments on commit ddbaaa1

Please sign in to comment.