@@ -26,6 +26,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
26
26
*/
27
27
28
28
#include "my_test.h"
29
+ #ifdef _WIN32
30
+ #include <fileapi.h>
31
+ #else
32
+ #include <sys/types.h>
33
+ #include <sys/stat.h>
34
+ #endif
29
35
30
36
static int test_conc66 (MYSQL * my )
31
37
{
@@ -1589,6 +1595,102 @@ static int test_conc327(MYSQL *unused __attribute__((unused)))
1589
1595
}
1590
1596
#endif
1591
1597
1598
+ static int test_conc396 (MYSQL * unused __attribute__((unused )))
1599
+ {
1600
+ MYSQL * mysql ;
1601
+ FILE * fp1 , * fp2 , * fp3 ;
1602
+ char cnf_file1 [FN_REFLEN + 10 ];
1603
+ char cnf_dir [FN_REFLEN + 10 ];
1604
+ char cnf_file2 [FN_REFLEN + 30 ];
1605
+ char cnf_file3 [FN_REFLEN + 30 ];
1606
+ char tmp_dir [FN_REFLEN + 1 ];
1607
+ const char * env = getenv ("MYSQL_TMP_DIR" );
1608
+ fp1 = fp2 = fp3 = NULL ;
1609
+
1610
+
1611
+ if (env ) {
1612
+ strncpy (tmp_dir , env , FN_REFLEN + 1 );
1613
+ }
1614
+ else {
1615
+ #ifdef _WIN32
1616
+ GetTempPath (FN_REFLEN + 1 , tmp_dir );
1617
+ #else
1618
+ strncpy (tmp_dir , "/tmp" , FN_REFLEN + 1 );
1619
+ #endif
1620
+ }
1621
+
1622
+ snprintf (cnf_file1 , FN_REFLEN + 10 , "%s%cfoo.cnf" , tmp_dir , FN_LIBCHAR );
1623
+ snprintf (cnf_dir , FN_REFLEN + 10 , "%s%cconf.d" , tmp_dir , FN_LIBCHAR );
1624
+ snprintf (cnf_file2 , FN_REFLEN + 30 , "%s%cconfig_a.cnf" , cnf_dir , FN_LIBCHAR );
1625
+ snprintf (cnf_file3 , FN_REFLEN + 30 , "%s%cconfig_b.cnf" , cnf_dir , FN_LIBCHAR );
1626
+
1627
+ #ifdef _WIN32
1628
+ CreateDirectory (cnf_dir , NULL );
1629
+ #else
1630
+ mkdir (cnf_dir , 0777 );
1631
+ #endif
1632
+
1633
+ mysql = mysql_init (NULL );
1634
+
1635
+ fp1 = fopen (cnf_file1 , "w" );
1636
+ FAIL_IF (!fp1 , "fopen" );
1637
+ fprintf (fp1 , "[client]\n!includedir %s\n" , cnf_dir );
1638
+ fclose (fp1 );
1639
+
1640
+ /* config_b is alphabetically later, so it should take precendence. */
1641
+ fp2 = fopen (cnf_file2 , "w" );
1642
+ FAIL_IF (!fp2 , "fopen" );
1643
+ fprintf (fp2 , "[client]\ndefault-character-set = latin2\n" );
1644
+ fclose (fp2 );
1645
+
1646
+ fp3 = fopen (cnf_file3 , "w" );
1647
+ FAIL_IF (!fp3 , "fopen" );
1648
+ fprintf (fp3 , "[client]\ndefault-character-set = utf8mb3\n" );
1649
+ fclose (fp3 );
1650
+
1651
+ mysql_options (mysql , MYSQL_READ_DEFAULT_FILE , cnf_file1 );
1652
+ my_test_connect (mysql , hostname , username , password ,
1653
+ schema , port , socketname , 0 , 1 );
1654
+
1655
+ remove (cnf_file1 );
1656
+ remove (cnf_file2 );
1657
+ remove (cnf_file3 );
1658
+
1659
+ FAIL_IF (strcmp (mysql_character_set_name (mysql ), "utf8mb3" ), "expected charset utf8mb3" );
1660
+
1661
+ mysql_close (mysql );
1662
+ mysql = mysql_init (NULL );
1663
+
1664
+ fp1 = fopen (cnf_file1 , "w" );
1665
+ FAIL_IF (!fp1 , "fopen" );
1666
+ fprintf (fp1 , "[client]\n!includedir %s\n" , cnf_dir );
1667
+ fclose (fp1 );
1668
+
1669
+ fp2 = fopen (cnf_file2 , "w" );
1670
+ FAIL_IF (!fp2 , "fopen" );
1671
+ fprintf (fp2 , "[client]\ndefault-character-set = utf8mb3\n" );
1672
+ fclose (fp2 );
1673
+
1674
+ fp3 = fopen (cnf_file3 , "w" );
1675
+ FAIL_IF (!fp3 , "fopen" );
1676
+ fprintf (fp3 , "[client]\ndefault-character-set = latin2\n" );
1677
+ fclose (fp3 );
1678
+
1679
+ mysql_options (mysql , MYSQL_READ_DEFAULT_FILE , cnf_file1 );
1680
+ my_test_connect (mysql , hostname , username , password ,
1681
+ schema , port , socketname , 0 , 1 );
1682
+
1683
+ remove (cnf_file1 );
1684
+ remove (cnf_file2 );
1685
+ remove (cnf_file3 );
1686
+
1687
+ FAIL_IF (strcmp (mysql_character_set_name (mysql ), "latin2" ), "expected charset latin2" );
1688
+
1689
+ mysql_close (mysql );
1690
+
1691
+ return OK ;
1692
+ }
1693
+
1592
1694
static int test_conc332 (MYSQL * unused __attribute__((unused )))
1593
1695
{
1594
1696
int rc ;
@@ -2045,7 +2147,7 @@ static int test_conn_str_1(MYSQL *my __attribute__((unused)))
2045
2147
if (!(fp = fopen ("./conc274.cnf" , "w" )))
2046
2148
return FAIL ;
2047
2149
2048
- sprintf (conn_str , "connection=host=%s;user=%s;password=%s ;port=%d;ssl_enforce=1;socket=%s" ,
2150
+ sprintf (conn_str , "connection=host=%s;user=%s;password={%s} ;port=%d;ssl_enforce=1;socket=%s" ,
2049
2151
hostname ? hostname : "localhost" , username ? username : "" ,
2050
2152
password ? password : "" , ssl_port , socketname ? socketname : "" );
2051
2153
@@ -2084,7 +2186,7 @@ static int test_conc365(MYSQL *my __attribute__((unused)))
2084
2186
char tmp [1024 ];
2085
2187
2086
2188
snprintf (tmp , sizeof (tmp ) - 1 ,
2087
- "host=127.0.0.1:3300,%s;user=%s;password=%s ;port=%d;socket=%s;tls_fp=%s" ,
2189
+ "host=127.0.0.1:3300,%s;user=%s;password={%s} ;port=%d;socket=%s;tls_fp=%s" ,
2088
2190
hostname ? hostname : "localhost" , username ? username : "" , password ? password : "" ,
2089
2191
port , socketname ? socketname : "" , fingerprint [0 ] ? fingerprint : "" );
2090
2192
@@ -2140,12 +2242,12 @@ static int test_conc365_reconnect(MYSQL *my)
2140
2242
if (IS_SKYSQL (hostname ))
2141
2243
{
2142
2244
snprintf (tmp , sizeof (tmp ) - 1 ,
2143
- "host=127.0.0.1:3300,%s;user=%s;password=%s ;port=%d;socket=%s;ssl_enforce=1;tls_fp=%s" ,
2245
+ "host=127.0.0.1:3300,%s;user=%s;password={%s} ;port=%d;socket=%s;ssl_enforce=1;tls_fp=%s" ,
2144
2246
hostname ? hostname : "localhost" , username ? username : "" , password ? password : "" ,
2145
2247
ssl_port , socketname ? socketname : "" , fingerprint [0 ] ? fingerprint : "" );
2146
2248
} else {
2147
2249
snprintf (tmp , sizeof (tmp ) - 1 ,
2148
- "host=127.0.0.1:3300,%s;user=%s;password=%s ;port=%d;socket=%s;tls_fp=%s" ,
2250
+ "host=127.0.0.1:3300,%s;user=%s;password={%s} ;port=%d;socket=%s;tls_fp=%s" ,
2149
2251
hostname ? hostname : "localhost" , username ? username : "" , password ? password : "" ,
2150
2252
port , socketname ? socketname : "" , fingerprint [0 ] ? fingerprint :"" );
2151
2253
}
@@ -2432,6 +2534,7 @@ struct my_tests_st my_tests[] = {
2432
2534
{"test_conc327" , test_conc327 , TEST_CONNECTION_DEFAULT , 0 , NULL , NULL },
2433
2535
{"test_conc317" , test_conc317 , TEST_CONNECTION_DEFAULT , 0 , NULL , NULL },
2434
2536
#endif
2537
+ {"test_conc396" , test_conc396 , TEST_CONNECTION_DEFAULT , 0 , NULL , NULL },
2435
2538
{"test_conc315" , test_conc315 , TEST_CONNECTION_NEW , 0 , NULL , NULL },
2436
2539
{"test_expired_pw" , test_expired_pw , TEST_CONNECTION_DEFAULT , 0 , NULL , NULL },
2437
2540
{"test_conc276" , test_conc276 , TEST_CONNECTION_NONE , 0 , NULL , NULL },
0 commit comments