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;
2525import std.digest.sha ;
2626import std.exception ;
2727import std.range ;
28+ import std.regex ;
29+ import std.typecons ;
2830import std.variant ;
2931
3032import mysql.connection;
810812 // Request a conventional maximum packet length.
811813 1. packInto(packet[8 .. 12 ]);
812814
813- packet ~= 33 ; // Set UTF-8 as default charSet
815+ packet ~= getDefaultCollation(conn._serverVersion);
814816
815817 // There's a statutory block of zero bytes here - fill them in.
816818 foreach (i; 0 .. 23 )
@@ -1112,3 +1114,17 @@ package(mysql) void enableMultiStatements(Connection conn, bool on)
11121114 auto packet = conn.getPacket();
11131115 enforce! MYXProtocol(packet[0 ] == 254 && packet.length == 5 , " Unexpected response to SET_OPTION command" );
11141116}
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