Skip to content

Commit 13661cd

Browse files
committed
add test to compare textRows and binaryRows
1 parent 248fcf1 commit 13661cd

File tree

1 file changed

+52
-21
lines changed

1 file changed

+52
-21
lines changed

driver_test.go

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,29 +148,18 @@ func runTests(t *testing.T, dsn string, tests ...func(dbt *DBTest)) {
148148
defer db2.Close()
149149
}
150150

151-
dsn3 := dsn + "&multiStatements=true"
152-
var db3 *sql.DB
153-
if _, err := ParseDSN(dsn3); err != errInvalidDSNUnsafeCollation {
154-
db3, err = sql.Open("mysql", dsn3)
155-
if err != nil {
156-
t.Fatalf("error connecting: %s", err.Error())
157-
}
158-
defer db3.Close()
159-
}
160-
161-
dbt := &DBTest{t, db}
162-
dbt2 := &DBTest{t, db2}
163-
dbt3 := &DBTest{t, db3}
164151
for _, test := range tests {
165-
test(dbt)
166-
dbt.db.Exec("DROP TABLE IF EXISTS test")
152+
t.Run("default", func(t *testing.T) {
153+
dbt := &DBTest{t, db}
154+
test(dbt)
155+
dbt.db.Exec("DROP TABLE IF EXISTS test")
156+
})
167157
if db2 != nil {
168-
test(dbt2)
169-
dbt2.db.Exec("DROP TABLE IF EXISTS test")
170-
}
171-
if db3 != nil {
172-
test(dbt3)
173-
dbt3.db.Exec("DROP TABLE IF EXISTS test")
158+
t.Run("interpolateParams", func(t *testing.T) {
159+
dbt2 := &DBTest{t, db2}
160+
test(dbt2)
161+
dbt2.db.Exec("DROP TABLE IF EXISTS test")
162+
})
174163
}
175164
}
176165
}
@@ -316,6 +305,48 @@ func TestCRUD(t *testing.T) {
316305
})
317306
}
318307

308+
// TestNumbers test that selecting numeric columns.
309+
// Both of textRows and binaryRows should return same type and value.
310+
func TestNumbersToAny(t *testing.T) {
311+
runTests(t, dsn, func(dbt *DBTest) {
312+
dbt.mustExec("CREATE TABLE `test` (id INT PRIMARY KEY, b BOOL, i8 TINYINT, " +
313+
"i16 SMALLINT, i32 INT, i64 BIGINT, f32 FLOAT, f64 DOUBLE)")
314+
dbt.mustExec("INSERT INTO `test` VALUES (1, true, 127, 32767, 2147483647, 9223372036854775807, 1.25, 2.5)")
315+
316+
// Use binaryRows for intarpolateParams=false and textRows for intarpolateParams=true.
317+
rows := dbt.mustQuery("SELECT b, i8, i16, i32, i64, f32, f64 FROM `test` WHERE id=?", 1)
318+
if !rows.Next() {
319+
dbt.Fatal("no data")
320+
}
321+
var b, i8, i16, i32, i64, f32, f64 any
322+
err := rows.Scan(&b, &i8, &i16, &i32, &i64, &f32, &f64)
323+
if err != nil {
324+
dbt.Fatal(err)
325+
}
326+
if b.(int64) != 1 {
327+
dbt.Errorf("b != 1")
328+
}
329+
if i8.(int64) != 127 {
330+
dbt.Errorf("i8 != 127")
331+
}
332+
if i16.(int64) != 32767 {
333+
dbt.Errorf("i16 != 32767")
334+
}
335+
if i32.(int64) != 2147483647 {
336+
dbt.Errorf("i32 != 2147483647")
337+
}
338+
if i64.(int64) != 9223372036854775807 {
339+
dbt.Errorf("i64 != 9223372036854775807")
340+
}
341+
if f32.(float32) != 1.25 {
342+
dbt.Errorf("f32 != 1.25")
343+
}
344+
if f64.(float64) != 2.5 {
345+
dbt.Errorf("f64 != 2.5")
346+
}
347+
})
348+
}
349+
319350
func TestMultiQuery(t *testing.T) {
320351
runTestsWithMultiStatement(t, dsn, func(dbt *DBTest) {
321352
// Create Table

0 commit comments

Comments
 (0)