@@ -26,6 +26,7 @@ import (
2626	"os" 
2727	"reflect" 
2828	"runtime" 
29+ 	"slices" 
2930	"strconv" 
3031	"strings" 
3132	"sync" 
@@ -1609,68 +1610,32 @@ func TestCollation(t *testing.T) {
16091610		t .Skipf ("MySQL server not running on %s" , netAddr )
16101611	}
16111612
1612- 	defaultCollation  :=  "utf8mb4_general_ci" 
1613+ 	// MariaDB may override collation specified by handshake with `character_set_collations` variable. 
1614+ 	// https://mariadb.com/kb/en/setting-character-sets-and-collations/#changing-default-collation 
1615+ 	// https://mariadb.com/kb/en/server-system-variables/#character_set_collations 
1616+ 	// utf8mb4_general_ci, utf8mb3_general_ci will be overridden by default MariaDB. 
1617+ 	// Collations other than charasets default are not overridden. So utf8mb4_unicode_ci is safe. 
16131618	testCollations  :=  []string {
1614- 		"" ,               // do not set 
1615- 		defaultCollation , // driver default 
16161619		"latin1_general_ci" ,
16171620		"binary" ,
16181621		"utf8mb4_unicode_ci" ,
16191622		"cp1257_bin" ,
16201623	}
16211624
16221625	for  _ , collation  :=  range  testCollations  {
1623- 		var  expected , tdsn  string 
1624- 		if  collation  !=  ""  {
1625- 			tdsn  =  dsn  +  "&collation="  +  collation 
1626- 			expected  =  collation 
1627- 		} else  {
1628- 			tdsn  =  dsn 
1629- 			expected  =  defaultCollation 
1630- 		}
1631- 
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- 				}
1626+ 		t .Run (collation , func (t  * testing.T ) {
1627+ 			tdsn  :=  dsn  +  "&collation="  +  collation 
1628+ 			expected  :=  collation 
16491629
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- 					}
1630+ 			runTests (t , tdsn , func (dbt  * DBTest ) {
1631+ 				var  got  string 
1632+ 				if  err  :=  dbt .db .QueryRow ("SELECT @@collation_connection" ).Scan (& got ); err  !=  nil  {
1633+ 					dbt .Fatal (err )
16571634				}
1658- 			}
1659- 
1660- 			var  got  string 
1661- 			if  err  :=  dbt .db .QueryRow ("SELECT @@collation_connection" ).Scan (& got ); err  !=  nil  {
1662- 				dbt .Fatal (err )
1663- 			}
1664- 
1665- 			if  got  !=  expected  {
1666- 				if  forceExpected  !=  expected  {
1667- 					if  got  !=  forceExpected  {
1668- 						dbt .Fatalf ("expected forced connection collation %s but got %s" , forceExpected , got )
1669- 					}
1670- 				} else  {
1635+ 				if  got  !=  expected  {
16711636					dbt .Fatalf ("expected connection collation %s but got %s" , expected , got )
16721637				}
1673- 			}
1638+ 			}) 
16741639		})
16751640	}
16761641}
@@ -1959,7 +1924,7 @@ func TestPreparedManyCols(t *testing.T) {
19591924		rows .Close ()
19601925
19611926		// Create 0byte string which we can't send via STMT_LONG_DATA. 
1962- 		for  i  :=  0 ;  i   <   numParams ;  i ++  {
1927+ 		for  i  :=  range   numParams  {
19631928			params [i ] =  "" 
19641929		}
19651930		rows , err  =  stmt .Query (params ... )
@@ -2004,7 +1969,7 @@ func TestConcurrent(t *testing.T) {
20041969			})
20051970		}
20061971
2007- 		for  i  :=  0 ;  i   <   max ;  i ++  {
1972+ 		for  i  :=  range   max  {
20081973			go  func (id  int ) {
20091974				defer  wg .Done ()
20101975
@@ -2388,7 +2353,7 @@ func TestPing(t *testing.T) {
23882353			q .Close ()
23892354
23902355			// Verify that Ping() clears both fields. 
2391- 			for  i   :=   0 ;  i   <   2 ;  i ++  {
2356+ 			for  range   2  {
23922357				if  err  :=  c .Ping (ctx ); err  !=  nil  {
23932358					dbt .fail ("Pinger" , "Ping" , err )
23942359				}
@@ -2591,7 +2556,7 @@ func TestMultiResultSet(t *testing.T) {
25912556			}
25922557			defer  stmt .Close ()
25932558
2594- 			for  j  :=  0 ;  j   <   2 ;  j ++  {
2559+ 			for  j  :=  range   2  {
25952560				rows , err  :=  stmt .Query ()
25962561				if  err  !=  nil  {
25972562					dbt .Fatalf ("%v (i=%d) (j=%d)" , err , i , j )
@@ -2698,7 +2663,7 @@ func TestQueryMultipleResults(t *testing.T) {
26982663			c  :=  conn .(* mysqlConn )
26992664
27002665			// Demonstrate that repeated queries reset the affectedRows 
2701- 			for  i   :=   0 ;  i   <   2 ;  i ++  {
2666+ 			for  range   2  {
27022667				_ , err  :=  qr .Query (` 
27032668				INSERT INTO test (value) VALUES ('a'), ('b'); 
27042669				INSERT INTO test (value) VALUES ('c'), ('d'), ('e'); 
@@ -3326,11 +3291,11 @@ func TestRawBytesAreNotModified(t *testing.T) {
33263291
33273292	runTests (t , dsn , func (dbt  * DBTest ) {
33283293		dbt .mustExec ("CREATE TABLE test (id int, value BLOB) CHARACTER SET utf8" )
3329- 		for  i  :=  0 ;  i   <   insertRows ;  i ++  {
3294+ 		for  i  :=  range   insertRows  {
33303295			dbt .mustExec ("INSERT INTO test VALUES (?, ?)" , i + 1 , sqlBlobs [i & 1 ])
33313296		}
33323297
3333- 		for  i  :=  0 ;  i   <   contextRaceIterations ;  i ++  {
3298+ 		for  i  :=  range   contextRaceIterations  {
33343299			func () {
33353300				ctx , cancel  :=  context .WithCancel (context .Background ())
33363301				defer  cancel ()
@@ -3594,8 +3559,8 @@ func TestConnectionAttributes(t *testing.T) {
35943559		rowsMap [attrName ] =  attrValue 
35953560	}
35963561
3597- 	connAttrs  :=  append ( append ([] string {},  defaultAttrs ... ) , customAttrs ... )
3598- 	expectedAttrValues  :=  append ( append ([] string {},  defaultAttrValues ... ) , customAttrValues ... )
3562+ 	connAttrs  :=  slices . Concat ( defaultAttrs , customAttrs )
3563+ 	expectedAttrValues  :=  slices . Concat ( defaultAttrValues , customAttrValues )
35993564	for  i  :=  range  connAttrs  {
36003565		if  gotValue  :=  rowsMap [connAttrs [i ]]; gotValue  !=  expectedAttrValues [i ] {
36013566			dbt .Errorf ("expected %q, got %q" , expectedAttrValues [i ], gotValue )
@@ -3679,7 +3644,7 @@ func TestIssue1567(t *testing.T) {
36793644			count  =  max 
36803645		}
36813646
3682- 		for  i   :=   0 ;  i   <   count ;  i ++  {
3647+ 		for  range   count  {
36833648			timeout  :=  time .Duration (mrand .Int63n (int64 (rtt )))
36843649			ctx , cancel  :=  context .WithTimeout (context .Background (), timeout )
36853650			dbt .db .PingContext (ctx )
0 commit comments