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