@@ -1631,13 +1631,46 @@ func TestCollation(t *testing.T) {
16311631 }
16321632
16331633 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+
16341661 var got string
16351662 if err := dbt .db .QueryRow ("SELECT @@collation_connection" ).Scan (& got ); err != nil {
16361663 dbt .Fatal (err )
16371664 }
16381665
16391666 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+ }
16411674 }
16421675 })
16431676 }
@@ -1686,16 +1719,16 @@ func TestRawBytesResultExceedsBuffer(t *testing.T) {
16861719}
16871720
16881721func TestTimezoneConversion (t * testing.T ) {
1689- zones := []string {"UTC" , "US/Central " , "US/Pacific " , "Local" }
1722+ zones := []string {"UTC" , "America/New_York " , "Asia/Hong_Kong " , "Local" }
16901723
16911724 // Regression test for timezone handling
16921725 tzTest := func (dbt * DBTest ) {
16931726 // Create table
16941727 dbt .mustExec ("CREATE TABLE test (ts TIMESTAMP)" )
16951728
16961729 // 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 )
16991732 dbt .mustExec ("INSERT INTO test VALUE (?)" , reftime )
17001733
17011734 // Retrieve time from DB
@@ -1714,7 +1747,7 @@ func TestTimezoneConversion(t *testing.T) {
17141747 // Check that dates match
17151748 if reftime .Unix () != dbTime .Unix () {
17161749 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 )
17181751 dbt .Errorf (" Now(UTC)=%v\n " , dbTime )
17191752 }
17201753 }
@@ -3542,6 +3575,15 @@ func TestConnectionAttributes(t *testing.T) {
35423575
35433576 dbt := & DBTest {t , db }
35443577
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+ }
35453587 queryString := "SELECT ATTR_NAME, ATTR_VALUE FROM performance_schema.session_account_connect_attrs WHERE PROCESSLIST_ID = CONNECTION_ID()"
35463588 rows := dbt .mustQuery (queryString )
35473589 defer rows .Close ()
0 commit comments