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

Function TestTimestampMicros

driver_test.go:1023–1074  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1021}
1022
1023func TestTimestampMicros(t *testing.T) {
1024 format := "2006-01-02 15:04:05.999999"
1025 f0 := format[:19]
1026 f1 := format[:21]
1027 f6 := format[:26]
1028 runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) {
1029 // check if microseconds are supported.
1030 // Do not use timestamp(x) for that check - before 5.5.6, x would mean display width
1031 // and not precision.
1032 // Se last paragraph at http://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html
1033 microsecsSupported := false
1034 if rows, err := dbt.db.Query(`SELECT cast("00:00:00.1" as TIME(1)) = "00:00:00.1"`); err == nil {
1035 rows.Scan(&microsecsSupported)
1036 rows.Close()
1037 }
1038 if !microsecsSupported {
1039 // skip test
1040 return
1041 }
1042 _, err := dbt.db.Exec(`
1043 CREATE TABLE ` + tbl + ` (
1044 value0 TIMESTAMP NOT NULL DEFAULT '` + f0 + `',
1045 value1 TIMESTAMP(1) NOT NULL DEFAULT '` + f1 + `',
1046 value6 TIMESTAMP(6) NOT NULL DEFAULT '` + f6 + `'
1047 )`,
1048 )
1049 if err != nil {
1050 dbt.Error(err)
1051 }
1052 defer dbt.mustExec("DROP TABLE IF EXISTS " + tbl)
1053 dbt.mustExec("INSERT INTO "+tbl+" SET value0=?, value1=?, value6=?", f0, f1, f6)
1054 var res0, res1, res6 string
1055 rows := dbt.mustQuery("SELECT * FROM " + tbl)
1056 defer rows.Close()
1057 if !rows.Next() {
1058 dbt.Errorf("test contained no selectable values")
1059 }
1060 err = rows.Scan(&res0, &res1, &res6)
1061 if err != nil {
1062 dbt.Error(err)
1063 }
1064 if res0 != f0 {
1065 dbt.Errorf("expected %q, got %q", f0, res0)
1066 }
1067 if res1 != f1 {
1068 dbt.Errorf("expected %q, got %q", f1, res1)
1069 }
1070 if res6 != f6 {
1071 dbt.Errorf("expected %q, got %q", f6, res6)
1072 }
1073 })
1074}
1075
1076func TestNULL(t *testing.T) {
1077 runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) {

Callers

nothing calls this directly

Calls 9

runTestsParallelFunction · 0.85
ScanMethod · 0.80
mustExecMethod · 0.80
mustQueryMethod · 0.80
QueryMethod · 0.45
CloseMethod · 0.45
ExecMethod · 0.45
ErrorMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected