File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ import std.conv;
25
25
import std.digest.sha ;
26
26
import std.exception ;
27
27
import std.range ;
28
+ import std.regex ;
29
+ import std.typecons ;
28
30
import std.variant ;
29
31
30
32
import mysql.connection;
810
812
// Request a conventional maximum packet length.
811
813
1. packInto(packet[8 .. 12 ]);
812
814
813
- packet ~= 33 ; // Set UTF-8 as default charSet
815
+ packet ~= getDefaultCollation(conn._serverVersion);
814
816
815
817
// There's a statutory block of zero bytes here - fill them in.
816
818
foreach (i; 0 .. 23 )
@@ -1112,3 +1114,17 @@ package(mysql) void enableMultiStatements(Connection conn, bool on)
1112
1114
auto packet = conn.getPacket();
1113
1115
enforce! MYXProtocol(packet[0 ] == 254 && packet.length == 5 , " Unexpected response to SET_OPTION command" );
1114
1116
}
1117
+
1118
+ private ubyte getDefaultCollation (string serverVersion)
1119
+ {
1120
+ static re = ctRegex! ` ^(\d{1,2})\.(\d{1,2})\.(\d{1,3})(.*)` ;
1121
+ auto captured = serverVersion.matchFirst(re);
1122
+ auto major = captured[1 ].to! ushort ;
1123
+ auto minor = captured[2 ].to! ushort ;
1124
+ auto patch = captured[3 ].to! ushort ;
1125
+ auto mysqlServerVersion = tuple(major, minor, patch);
1126
+
1127
+ if (mysqlServerVersion >= tuple(5 ,5 ,3 )) // MySQL >= 5.5.3 supports utf8mb4
1128
+ return 45 ; // Set utf8mb4_general_ci as default
1129
+ return 33 ; // Set utf8_general_ci as default
1130
+ }
You can’t perform that action at this time.
0 commit comments