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

Method run

driver_test.go:843–904  ·  view source on GitHub ↗
(dbt *DBTest, dbtype, tlayout string, mode timeMode)

Source from the content-addressed store, hash-verified

841}
842
843func (t timeTest) run(dbt *DBTest, dbtype, tlayout string, mode timeMode) {
844 var rows *sql.Rows
845 query := t.genQuery(dbtype, mode)
846 switch mode {
847 case binaryString:
848 rows = dbt.mustQuery(query, t.s)
849 case binaryTime:
850 rows = dbt.mustQuery(query, t.t)
851 case textString:
852 query = fmt.Sprintf(query, t.s)
853 rows = dbt.mustQuery(query)
854 default:
855 panic("unsupported mode")
856 }
857 defer rows.Close()
858 var err error
859 if !rows.Next() {
860 err = rows.Err()
861 if err == nil {
862 err = fmt.Errorf("no data")
863 }
864 dbt.Errorf("%s [%s]: %s", dbtype, mode, err)
865 return
866 }
867 var dst any
868 err = rows.Scan(&dst)
869 if err != nil {
870 dbt.Errorf("%s [%s]: %s", dbtype, mode, err)
871 return
872 }
873 switch val := dst.(type) {
874 case []uint8:
875 str := string(val)
876 if str == t.s {
877 return
878 }
879 if mode.Binary() && dbtype == "DATETIME" && len(str) == 26 && str[:19] == t.s {
880 // a fix mainly for TravisCI:
881 // accept full microsecond resolution in result for DATETIME columns
882 // where the binary protocol was used
883 return
884 }
885 dbt.Errorf("%s [%s] to string: expected %q, got %q",
886 dbtype, mode,
887 t.s, str,
888 )
889 case time.Time:
890 if val == t.t {
891 return
892 }
893 dbt.Errorf("%s [%s] to string: expected %q, got %q",
894 dbtype, mode,
895 t.s, val.Format(tlayout),
896 )
897 default:
898 fmt.Printf("%#v\n", []any{dbtype, tlayout, mode, t.s, t.t})
899 dbt.Errorf("%s [%s]: unhandled type %T (is '%v')",
900 dbtype, mode,

Callers 1

TestDateTimeFunction · 0.80

Calls 6

genQueryMethod · 0.95
mustQueryMethod · 0.80
ScanMethod · 0.80
BinaryMethod · 0.80
CloseMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected