@@ -1631,13 +1631,46 @@ func TestCollation(t *testing.T) {
1631
1631
}
1632
1632
1633
1633
runTests (t , tdsn , func (dbt * DBTest ) {
1634
+ // see https://mariadb.com/kb/en/setting-character-sets-and-collations/#changing-default-collation
1635
+ // when character_set_collations is set for the charset, it overrides the default collation
1636
+ // so we need to check if the default collation is overridden
1637
+ forceExpected := expected
1638
+ var defaultCollations string
1639
+ err := dbt .db .QueryRow ("SELECT @@character_set_collations" ).Scan (& defaultCollations )
1640
+ if err == nil {
1641
+ // Query succeeded, need to check if we should override expected collation
1642
+ collationMap := make (map [string ]string )
1643
+ pairs := strings .Split (defaultCollations , "," )
1644
+ for _ , pair := range pairs {
1645
+ parts := strings .Split (pair , "=" )
1646
+ if len (parts ) == 2 {
1647
+ collationMap [parts [0 ]] = parts [1 ]
1648
+ }
1649
+ }
1650
+
1651
+ // Get charset prefix from expected collation
1652
+ parts := strings .Split (expected , "_" )
1653
+ if len (parts ) > 0 {
1654
+ charset := parts [0 ]
1655
+ if newCollation , ok := collationMap [charset ]; ok {
1656
+ forceExpected = newCollation
1657
+ }
1658
+ }
1659
+ }
1660
+
1634
1661
var got string
1635
1662
if err := dbt .db .QueryRow ("SELECT @@collation_connection" ).Scan (& got ); err != nil {
1636
1663
dbt .Fatal (err )
1637
1664
}
1638
1665
1639
1666
if got != expected {
1640
- dbt .Fatalf ("expected connection collation %s but got %s" , expected , got )
1667
+ if forceExpected != expected {
1668
+ if got != forceExpected {
1669
+ dbt .Fatalf ("expected forced connection collation %s but got %s" , forceExpected , got )
1670
+ }
1671
+ } else {
1672
+ dbt .Fatalf ("expected connection collation %s but got %s" , expected , got )
1673
+ }
1641
1674
}
1642
1675
})
1643
1676
}
@@ -1686,16 +1719,16 @@ func TestRawBytesResultExceedsBuffer(t *testing.T) {
1686
1719
}
1687
1720
1688
1721
func TestTimezoneConversion (t * testing.T ) {
1689
- zones := []string {"UTC" , "US/Central " , "US/Pacific " , "Local" }
1722
+ zones := []string {"UTC" , "America/New_York " , "Asia/Hong_Kong " , "Local" }
1690
1723
1691
1724
// Regression test for timezone handling
1692
1725
tzTest := func (dbt * DBTest ) {
1693
1726
// Create table
1694
1727
dbt .mustExec ("CREATE TABLE test (ts TIMESTAMP)" )
1695
1728
1696
1729
// Insert local time into database (should be converted)
1697
- usCentral , _ := time .LoadLocation ("US/Central " )
1698
- reftime := time .Date (2014 , 05 , 30 , 18 , 03 , 17 , 0 , time .UTC ).In (usCentral )
1730
+ newYorkTz , _ := time .LoadLocation ("America/New_York " )
1731
+ reftime := time .Date (2014 , 05 , 30 , 18 , 03 , 17 , 0 , time .UTC ).In (newYorkTz )
1699
1732
dbt .mustExec ("INSERT INTO test VALUE (?)" , reftime )
1700
1733
1701
1734
// Retrieve time from DB
@@ -1714,7 +1747,7 @@ func TestTimezoneConversion(t *testing.T) {
1714
1747
// Check that dates match
1715
1748
if reftime .Unix () != dbTime .Unix () {
1716
1749
dbt .Errorf ("times do not match.\n " )
1717
- dbt .Errorf (" Now(%v)=%v\n " , usCentral , reftime )
1750
+ dbt .Errorf (" Now(%v)=%v\n " , newYorkTz , reftime )
1718
1751
dbt .Errorf (" Now(UTC)=%v\n " , dbTime )
1719
1752
}
1720
1753
}
@@ -3542,6 +3575,15 @@ func TestConnectionAttributes(t *testing.T) {
3542
3575
3543
3576
dbt := & DBTest {t , db }
3544
3577
3578
+ var varName string
3579
+ var varValue string
3580
+ err := dbt .db .QueryRow ("SHOW VARIABLES LIKE 'performance_schema'" ).Scan (& varName , & varValue )
3581
+ if err != nil {
3582
+ t .Fatalf ("error: %s" , err .Error ())
3583
+ }
3584
+ if varValue != "ON" {
3585
+ t .Skipf ("Performance schema is not enabled. skipping" )
3586
+ }
3545
3587
queryString := "SELECT ATTR_NAME, ATTR_VALUE FROM performance_schema.session_account_connect_attrs WHERE PROCESSLIST_ID = CONNECTION_ID()"
3546
3588
rows := dbt .mustQuery (queryString )
3547
3589
defer rows .Close ()
0 commit comments