@@ -21,6 +21,7 @@ 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 ;
@@ -45,7 +46,7 @@ package struct ProtocolPrepared
45
46
import std.datetime ;
46
47
import std.variant ;
47
48
import mysql.types;
48
-
49
+
49
50
static ubyte [] makeBitmap (in Variant [] inParams)
50
51
{
51
52
size_t bml = (inParams.length+ 7 )/ 8 ;
@@ -451,7 +452,7 @@ package struct ProtocolPrepared
451
452
Variant [] inParams, ParameterSpecialization[] psa)
452
453
{
453
454
conn.autoPurge();
454
-
455
+
455
456
ubyte [] packet;
456
457
conn.resetPacket();
457
458
771
772
}
772
773
773
774
conn.autoPurge();
774
-
775
+
775
776
conn.resetPacket();
776
777
777
778
ubyte [] header;
810
811
// Request a conventional maximum packet length.
811
812
1. packInto(packet[8 .. 12 ]);
812
813
813
- packet ~= 33 ; // Set UTF-8 as default charSet
814
+ packet ~= getDefaultCollation(conn._serverVersion);
814
815
815
816
// There's a statutory block of zero bytes here - fill them in.
816
817
foreach (i; 0 .. 23 )
@@ -967,7 +968,7 @@ package(mysql) SvrCapFlags setClientFlags(SvrCapFlags serverCaps, SvrCapFlags ca
967
968
// didn't supply it
968
969
cCaps |= SvrCapFlags.PROTOCOL41 ;
969
970
cCaps |= SvrCapFlags.SECURE_CONNECTION ;
970
-
971
+
971
972
return cCaps;
972
973
}
973
974
@@ -998,7 +999,7 @@ package(mysql) PreparedServerInfo performRegister(Connection conn, const(char[])
998
999
scope (failure) conn.kill();
999
1000
1000
1001
PreparedServerInfo info;
1001
-
1002
+
1002
1003
conn.sendCmd(CommandType.STMT_PREPARE , sql);
1003
1004
conn._fieldCount = 0 ;
1004
1005
@@ -1112,3 +1113,30 @@ package(mysql) void enableMultiStatements(Connection conn, bool on)
1112
1113
auto packet = conn.getPacket();
1113
1114
enforce! MYXProtocol(packet[0 ] == 254 && packet.length == 5 , " Unexpected response to SET_OPTION command" );
1114
1115
}
1116
+
1117
+ private ubyte getDefaultCollation (string serverVersion)
1118
+ {
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 );
1142
+ }
0 commit comments