@@ -514,6 +514,44 @@ func TestDateTime(t *testing.T) {
514514 }
515515}
516516
517+ // This tests for https://github.com/go-sql-driver/mysql/pull/139
518+ //
519+ // An extra (invisible) nil byte was being added to the beginning of positive
520+ // time strings.
521+ func TestTimeSign (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 ("INSERT INTO test (id, time_field) VALUES(1, '" + sTime .value + "')" )
539+ rows := dbt .mustQuery ("SELECT time_field FROM test WHERE id = ?" , 1 )
540+ if rows .Next () {
541+ var oTime string
542+ rows .Scan (& oTime )
543+ if oTime != sTime .value {
544+ dbt .Errorf (`time values differ: got %q, expected %q.` , oTime , sTime .value )
545+ }
546+ } else {
547+ dbt .Error ("expecting at least one row." )
548+ }
549+ }
550+
551+ })
552+
553+ }
554+
517555func TestNULL (t * testing.T ) {
518556 runTests (t , dsn , func (dbt * DBTest ) {
519557 nullStmt , err := dbt .db .Prepare ("SELECT NULL" )
0 commit comments