MCPcopy
hub / github.com/go-sql-driver/mysql / TestNumbersToAny

Function TestNumbersToAny

driver_test.go:408–449  ·  view source on GitHub ↗

TestNumbers test that selecting numeric columns. Both of textRows and binaryRows should return same type and value.

(t *testing.T)

Source from the content-addressed store, hash-verified

406// TestNumbers test that selecting numeric columns.
407// Both of textRows and binaryRows should return same type and value.
408func TestNumbersToAny(t *testing.T) {
409 runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) {
410 dbt.mustExec("CREATE TABLE " + tbl + " (id INT PRIMARY KEY, b BOOL, i8 TINYINT, " +
411 "i16 SMALLINT, i32 INT, i64 BIGINT, f32 FLOAT, f64 DOUBLE, iu32 INT UNSIGNED)")
412 dbt.mustExec("INSERT INTO " + tbl + " VALUES (1, true, 127, 32767, 2147483647, 9223372036854775807, 1.25, 2.5, 4294967295)")
413
414 // Use binaryRows for interpolateParams=false and textRows for interpolateParams=true.
415 rows := dbt.mustQuery("SELECT b, i8, i16, i32, i64, f32, f64, iu32 FROM "+tbl+" WHERE id=?", 1)
416 if !rows.Next() {
417 dbt.Fatal("no data")
418 }
419 var b, i8, i16, i32, i64, f32, f64, iu32 any
420 err := rows.Scan(&b, &i8, &i16, &i32, &i64, &f32, &f64, &iu32)
421 if err != nil {
422 dbt.Fatal(err)
423 }
424 if b.(int64) != 1 {
425 dbt.Errorf("b != 1")
426 }
427 if i8.(int64) != 127 {
428 dbt.Errorf("i8 != 127")
429 }
430 if i16.(int64) != 32767 {
431 dbt.Errorf("i16 != 32767")
432 }
433 if i32.(int64) != 2147483647 {
434 dbt.Errorf("i32 != 2147483647")
435 }
436 if i64.(int64) != 9223372036854775807 {
437 dbt.Errorf("i64 != 9223372036854775807")
438 }
439 if f32.(float32) != 1.25 {
440 dbt.Errorf("f32 != 1.25")
441 }
442 if f64.(float64) != 2.5 {
443 dbt.Errorf("f64 != 2.5")
444 }
445 if iu32.(int64) != 4294967295 {
446 dbt.Errorf("iu32 != 4294967295")
447 }
448 })
449}
450
451func TestMultiQuery(t *testing.T) {
452 runTestsWithMultiStatement(t, dsn, func(dbt *DBTest) {

Callers

nothing calls this directly

Calls 5

runTestsParallelFunction · 0.85
mustExecMethod · 0.80
mustQueryMethod · 0.80
ScanMethod · 0.80
NextMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…