Skip to content

Commit 63fdbac

Browse files
committed
Adding a test that checks for equality of TIME fields (#139).
1 parent ed7d907 commit 63fdbac

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

driver_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,45 @@ func TestDateTime(t *testing.T) {
514514
}
515515
}
516516

517+
// This tests for https://github.com/go-sql-driver/mysql/pull/140
518+
//
519+
// An extra (invisible) nil byte was being added to the beginning of positive
520+
// time strings.
521+
func TestTime(t *testing.T) {
522+
runTests(t, dsn, func(dbt *DBTest) {
523+
var sTimes = []struct {
524+
value string
525+
fieldType string
526+
}{
527+
{"12:34:56", "TIME"},
528+
{"-12:34:56", "TIME"},
529+
// As described in http://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html
530+
// they *should* work, but only in 5.6+.
531+
// { "12:34:56.789", "TIME(3)" },
532+
// { "-12:34:56.789", "TIME(3)" },
533+
}
534+
535+
for _, sTime := range sTimes {
536+
dbt.db.Exec("DROP TABLE IF EXISTS test")
537+
dbt.mustExec("CREATE TABLE test (id INT, time_field " + sTime.fieldType + ")")
538+
dbt.mustExec("TRUNCATE TABLE test")
539+
dbt.mustExec("INSERT INTO test (id, time_field) VALUES(1, '" + sTime.value + "')")
540+
rows := dbt.mustQuery("SELECT time_field FROM test WHERE id = ?", 1)
541+
if rows.Next() {
542+
var oTime string
543+
rows.Scan(&oTime)
544+
if oTime != sTime.value {
545+
dbt.Error(fmt.Sprintf(`time values differ: got "%s", expecting "%s".`, oTime, sTime.value))
546+
}
547+
} else {
548+
dbt.Error("expecting at least one row.")
549+
}
550+
}
551+
552+
})
553+
554+
}
555+
517556
func TestNULL(t *testing.T) {
518557
runTests(t, dsn, func(dbt *DBTest) {
519558
nullStmt, err := dbt.db.Prepare("SELECT NULL")

0 commit comments

Comments
 (0)