@@ -21,12 +21,11 @@ Next tasks for this sub-package's cleanup:
21
21
module mysql.protocol.comms ;
22
22
23
23
import std.algorithm ;
24
+ import std.array ;
24
25
import std.conv ;
25
26
import std.digest.sha ;
26
27
import std.exception ;
27
28
import std.range ;
28
- import std.regex ;
29
- import std.typecons ;
30
29
import std.variant ;
31
30
32
31
import mysql.connection;
@@ -47,7 +46,7 @@ package struct ProtocolPrepared
47
46
import std.datetime ;
48
47
import std.variant ;
49
48
import mysql.types;
50
-
49
+
51
50
static ubyte [] makeBitmap (in Variant [] inParams)
52
51
{
53
52
size_t bml = (inParams.length+ 7 )/ 8 ;
@@ -453,7 +452,7 @@ package struct ProtocolPrepared
453
452
Variant [] inParams, ParameterSpecialization[] psa)
454
453
{
455
454
conn.autoPurge();
456
-
455
+
457
456
ubyte [] packet;
458
457
conn.resetPacket();
459
458
773
772
}
774
773
775
774
conn.autoPurge();
776
-
775
+
777
776
conn.resetPacket();
778
777
779
778
ubyte [] header;
@@ -969,7 +968,7 @@ package(mysql) SvrCapFlags setClientFlags(SvrCapFlags serverCaps, SvrCapFlags ca
969
968
// didn't supply it
970
969
cCaps |= SvrCapFlags.PROTOCOL41 ;
971
970
cCaps |= SvrCapFlags.SECURE_CONNECTION ;
972
-
971
+
973
972
return cCaps;
974
973
}
975
974
@@ -1000,7 +999,7 @@ package(mysql) PreparedServerInfo performRegister(Connection conn, const(char[])
1000
999
scope (failure) conn.kill();
1001
1000
1002
1001
PreparedServerInfo info;
1003
-
1002
+
1004
1003
conn.sendCmd(CommandType.STMT_PREPARE , sql);
1005
1004
conn._fieldCount = 0 ;
1006
1005
@@ -1117,14 +1116,27 @@ package(mysql) void enableMultiStatements(Connection conn, bool on)
1117
1116
1118
1117
private ubyte getDefaultCollation (string serverVersion)
1119
1118
{
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
1119
+ // MySQL >= 5.5.3 supports utf8mb4
1120
+ const v = serverVersion
1121
+ .splitter(' .' )
1122
+ .map! (a => a.parse! ushort )
1123
+ .array;
1124
+
1125
+ if (v[0 ] < 5 )
1126
+ return 33 ; // Set utf8_general_ci as default
1127
+ if (v[1 ] < 5 )
1128
+ return 33 ; // Set utf8_general_ci as default
1129
+ if (v[2 ] < 3 )
1130
+ return 33 ; // Set utf8_general_ci as default
1131
+
1132
+ return 45 ; // Set utf8mb4_general_ci as default
1133
+ }
1134
+
1135
+ unittest
1136
+ {
1137
+ assert (getDefaultCollation(" 5.5.3" ) == 45 );
1138
+ assert (getDefaultCollation(" 5.5.2" ) == 33 );
1139
+
1140
+ // MariaDB: https://mariadb.com/kb/en/connection/#initial-handshake-packet
1141
+ assert (getDefaultCollation(" 5.5.5-10.0.7-MariaDB" ) == 45 );
1130
1142
}
0 commit comments