Skip to content

Commit f1914b4

Browse files
committed
removed TIMESTAMP tests (still tested in TZ conversion)
1 parent 589fef4 commit f1914b4

File tree

3 files changed

+19
-29
lines changed

3 files changed

+19
-29
lines changed

const.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ package mysql
1111
const (
1212
minProtocolVersion byte = 10
1313
maxPacketSize = 1<<24 - 1
14+
timeFormat = "2006-01-02 15:04:05.999999"
1415
)
1516

1617
// MySQL constants documentation:

driver_test.go

+18-26
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,6 @@ func (t timeTest) genQuery(dbtype string, mode timeMode) string {
373373
} else {
374374
inner = `"%s"`
375375
}
376-
if len(dbtype) >= 9 && dbtype[:9] == "TIMESTAMP" {
377-
return `SELECT timestampadd(second,0,cast(` + inner + ` as DATETIME` + dbtype[9:] + `))`
378-
}
379376
return `SELECT cast(` + inner + ` as ` + dbtype + `)`
380377
}
381378

@@ -453,7 +450,6 @@ func TestDateTime(t *testing.T) {
453450
// NOTE: MySQL rounds DATETIME(x) up - but that's not included in the tests
454451
format := "2006-01-02 15:04:05.999999"
455452
t0 := time.Time{}
456-
ts0 := time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC)
457453
tstr0 := "0000-00-00 00:00:00.000000"
458454
testcases := []timeTests{
459455
{"DATE", format[:10], []timeTest{
@@ -504,44 +500,29 @@ func TestDateTime(t *testing.T) {
504500
{s: "!838:59:58.999999"},
505501
{t: t0, s: tstr0[11:]},
506502
}},
507-
{"TIMESTAMP", format[:19], []timeTest{
508-
{t: afterTime(ts0, "12345s")},
509-
{t: ts0, s: "1970-01-01 00:00:00"},
510-
}},
511-
{"TIMESTAMP(0)", format[:19], []timeTest{
512-
{t: afterTime(ts0, "12345s")},
513-
{t: ts0, s: "1970-01-01 00:00:00"},
514-
}},
515-
{"TIMESTAMP(1)", format[:21], []timeTest{
516-
{t: afterTime(ts0, "12345600ms")},
517-
{t: ts0, s: "1970-01-01 00:00:00.0"},
518-
}},
519-
{"TIMESTAMP(6)", format, []timeTest{
520-
{t: afterTime(ts0, "1234567890123000ns")},
521-
{t: ts0, s: "1970-01-01 00:00:00.000000"},
522-
}},
523503
}
524504
dsns := []string{
525505
dsn + "&parseTime=true",
526506
dsn + "&parseTime=false",
527507
}
528508
for _, testdsn := range dsns {
529509
runTests(t, testdsn, func(dbt *DBTest) {
530-
var withFrac, allowsZero bool
510+
microsecsSupported := false
511+
zeroDateSupported := false
531512
var rows *sql.Rows
532513
var err error
533514
rows, err = dbt.db.Query(`SELECT cast("00:00:00.1" as TIME(1)) = "00:00:00.1"`)
534515
if err == nil {
535-
rows.Scan(&withFrac)
516+
rows.Scan(&microsecsSupported)
536517
rows.Close()
537518
}
538519
rows, err = dbt.db.Query(`SELECT cast("0000-00-00" as DATE) = "0000-00-00"`)
539520
if err == nil {
540-
rows.Scan(&allowsZero)
521+
rows.Scan(&zeroDateSupported)
541522
rows.Close()
542523
}
543524
for _, setups := range testcases {
544-
if t := setups.dbtype; !withFrac && t[len(t)-1:] == ")" {
525+
if t := setups.dbtype; !microsecsSupported && t[len(t)-1:] == ")" {
545526
// skip fractional second tests if unsupported by server
546527
continue
547528
}
@@ -556,7 +537,7 @@ func TestDateTime(t *testing.T) {
556537
// fix setup.s - remove the "!"
557538
setup.s = setup.s[1:]
558539
}
559-
if !allowsZero && setup.s == tstr0[:len(setup.s)] {
540+
if !zeroDateSupported && setup.s == tstr0[:len(setup.s)] {
560541
// skip disallowed 0000-00-00 date
561542
continue
562543
}
@@ -917,6 +898,17 @@ func TestFoundRows(t *testing.T) {
917898
func TestStrict(t *testing.T) {
918899
// ALLOW_INVALID_DATES to get rid of stricter modes - we want to test for warnings, not errors
919900
relaxedDsn := dsn + "&sql_mode=ALLOW_INVALID_DATES"
901+
// make sure the MySQL version is recent enough with a separate connection
902+
// before running the test
903+
conn, err := MySQLDriver{}.Open(relaxedDsn)
904+
if conn != nil {
905+
conn.Close()
906+
}
907+
if me, ok := err.(*MySQLError); ok && me.Number == 1231 {
908+
// Error 1231: Variable 'sql_mode' can't be set to the value of 'ALLOW_INVALID_DATES'
909+
// => skip test, MySQL server version is too old
910+
return
911+
}
920912
runTests(t, relaxedDsn, func(dbt *DBTest) {
921913
dbt.mustExec("CREATE TABLE test (a TINYINT NOT NULL, b CHAR(4))")
922914

@@ -1107,7 +1099,7 @@ func TestCollation(t *testing.T) {
11071099
"latin1_general_ci",
11081100
"binary",
11091101
"utf8_unicode_ci",
1110-
"utf8mb4_general_ci",
1102+
"cp1257_bin",
11111103
}
11121104

11131105
for _, collation := range testCollations {

utils.go

-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ var (
2929
errInvalidDSNNoSlash = errors.New("Invalid DSN: Missing the slash separating the database name")
3030
)
3131

32-
// timeFormat must not be changed
33-
const timeFormat = "2006-01-02 15:04:05.999999"
34-
3532
func init() {
3633
tlsConfigRegister = make(map[string]*tls.Config)
3734
}

0 commit comments

Comments
 (0)