Skip to content

Commit 8441731

Browse files
committed
added new TIMESTAMP test
1 parent f1914b4 commit 8441731

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

driver_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,58 @@ func TestDateTime(t *testing.T) {
552552
}
553553
}
554554

555+
func TestTimestampMicros(t *testing.T) {
556+
format := "2006-01-02 15:04:05.999999"
557+
f0 := format[:19]
558+
f1 := format[:21]
559+
f6 := format[:26]
560+
runTests(t, dsn, func(dbt *DBTest) {
561+
// check if microseconds are supported.
562+
// Do not use timestamp(x) for that check - before 5.5.6, x would mean display width
563+
// and not precision.
564+
// Se last paragraph at http://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html
565+
microsecsSupported := false
566+
if rows, err := dbt.db.Query(`SELECT cast("00:00:00.1" as TIME(1)) = "00:00:00.1"`); err == nil {
567+
rows.Scan(&microsecsSupported)
568+
rows.Close()
569+
}
570+
if !microsecsSupported {
571+
// skip test
572+
return
573+
}
574+
_, err := dbt.db.Exec(`
575+
CREATE TABLE test (
576+
value0 TIMESTAMP NOT NULL DEFAULT '` + f0 + `',
577+
value1 TIMESTAMP(1) NOT NULL DEFAULT '` + f1 + `',
578+
value6 TIMESTAMP(6) NOT NULL DEFAULT '` + f6 + `'
579+
)`,
580+
)
581+
if err != nil {
582+
dbt.Error(err)
583+
}
584+
defer dbt.mustExec("DROP TABLE IF EXISTS test")
585+
dbt.mustExec("INSERT INTO test SET value0=?, value1=?, value6=?", f0, f1, f6)
586+
var res0, res1, res6 string
587+
rows := dbt.mustQuery("SELECT * FROM test")
588+
if !rows.Next() {
589+
dbt.Errorf("test contained no selectable values")
590+
}
591+
err = rows.Scan(&res0, &res1, &res6)
592+
if err != nil {
593+
dbt.Error(err)
594+
}
595+
if res0 != f0 {
596+
dbt.Errorf("expected %q, got %q", f0, res0)
597+
}
598+
if res1 != f1 {
599+
dbt.Errorf("expected %q, got %q", f1, res1)
600+
}
601+
if res6 != f6 {
602+
dbt.Errorf("expected %q, got %q", f6, res6)
603+
}
604+
})
605+
}
606+
555607
func TestNULL(t *testing.T) {
556608
runTests(t, dsn, func(dbt *DBTest) {
557609
nullStmt, err := dbt.db.Prepare("SELECT NULL")

0 commit comments

Comments
 (0)