@@ -1006,3 +1006,184 @@ func (_ *testDecodeSuite) TestTableMapOptMetaPrimaryKey(c *C) {
1006
1006
}
1007
1007
1008
1008
}
1009
+
1010
+ func (_ * testDecodeSuite ) TestTableMapHelperMaps (c * C ) {
1011
+
1012
+ /*
1013
+ CREATE TABLE `_types` (
1014
+ `b_bit` bit(64) NOT NULL DEFAULT b'0',
1015
+
1016
+ `n_boolean` boolean not null default '0',
1017
+ `n_tinyint` tinyint not null default '0',
1018
+ `n_smallint` smallint not null default '0',
1019
+ `n_mediumint` mediumint not null default '0',
1020
+ `n_int` int not null default '0',
1021
+ `n_bigint` bigint not null default '0',
1022
+ `n_decimal` decimal(65,30) not null default '0',
1023
+ `n_float` float not null default '0',
1024
+ `n_double` double not null default '0',
1025
+
1026
+ `nu_tinyint` tinyint unsigned not null default '0',
1027
+ `nu_smallint` smallint unsigned not null default '0',
1028
+ `nu_mediumint` mediumint unsigned not null default '0',
1029
+ `nu_int` int unsigned not null default '0',
1030
+ `nu_bigint` bigint unsigned not null default '0',
1031
+ `nu_decimal` decimal(65,30) unsigned not null default '0',
1032
+ `nu_float` float unsigned not null default '0',
1033
+ `nu_double` double unsigned not null default '0',
1034
+
1035
+ `t_year` year default null,
1036
+ `t_date` date default null,
1037
+ `t_time` time default null,
1038
+ `t_ftime` time(6) default null,
1039
+ `t_datetime` datetime default null,
1040
+ `t_fdatetime` datetime(6) default null,
1041
+ `t_timestamp` timestamp default current_timestamp,
1042
+ `t_ftimestamp` timestamp(6) default current_timestamp(6),
1043
+
1044
+ `c_char` char(255) collate gbk_chinese_ci not null default '', -- collate id: 28
1045
+ `c_varchar` varchar(255) not null default '',
1046
+ `c_binary` binary(64) not null default '',
1047
+ `c_varbinary` varbinary(64) not null default '',
1048
+ `c_tinyblob` tinyblob,
1049
+ `c_blob` blob,
1050
+ `c_mediumblob` mediumblob,
1051
+ `c_longblob` longblob,
1052
+ `c_tinytext` tinytext,
1053
+ `c_text` text,
1054
+ `c_mediumtext` mediumtext,
1055
+ `c_longtext` longtext,
1056
+
1057
+ `e_enum` enum('a','b') default 'a',
1058
+ `s_set` set('1','2') default '1',
1059
+ `g_geometry` geometry default null,
1060
+ `j_json` json default null,
1061
+
1062
+ `s_set2` set('3','4') collate gbk_chinese_ci default '4',
1063
+ `e_enum2` enum('c','d') collate gbk_chinese_ci default 'd',
1064
+ `g_geometrycollection` geometrycollection default null,
1065
+ `g_multipolygon` multipolygon default null,
1066
+ `g_multilinestring` multilinestring default null,
1067
+ `g_multipoint` multipoint default null,
1068
+ `g_polygon` polygon default null,
1069
+ `g_linestring` linestring default null,
1070
+ `g_point` point default null
1071
+ );
1072
+ */
1073
+
1074
+ unsignedMap := map [int ]bool {}
1075
+ for i := 1 ; i <= 9 ; i ++ {
1076
+ unsignedMap [i ] = false
1077
+ }
1078
+ for i := 10 ; i <= 17 ; i ++ {
1079
+ unsignedMap [i ] = true
1080
+ }
1081
+
1082
+ // collation id | collatation
1083
+ // 28 | gbk_chinese_ci
1084
+ // 46 | utf8mb4_bin
1085
+ // 63 | binary
1086
+ // 224 | utf8mb4_unicode_ci
1087
+ mysqlCollationMap := map [int ]uint64 {
1088
+ 26 : 28 , 27 : 224 , 28 : 63 , 29 : 63 , // (var)char/(var)binary
1089
+ 30 : 63 , 31 : 63 , 32 : 63 , 33 : 63 , // blobs
1090
+ 34 : 224 , 35 : 224 , 36 : 224 , 37 : 224 , // texts
1091
+ }
1092
+ // NOTE: mariadb treat json/geometry as character fields
1093
+ mariadbCollationMap := map [int ]uint64 {
1094
+ 26 : 28 , 27 : 224 , 28 : 63 , 29 : 63 , // (var)char/(var)binary
1095
+ 30 : 63 , 31 : 63 , 32 : 63 , 33 : 63 , // blobs
1096
+ 34 : 224 , 35 : 224 , 36 : 224 , 37 : 224 , // texts
1097
+ 40 : 63 , // geometry
1098
+ 41 : 46 , // json
1099
+ 44 : 63 , 45 : 63 , 46 : 63 , 47 : 63 , 48 : 63 , 49 : 63 , 50 : 63 , // geometry
1100
+ }
1101
+
1102
+ enumSetCollationMap := map [int ]uint64 {
1103
+ 38 : 224 , 39 : 224 , 42 : 28 , 43 : 28 ,
1104
+ }
1105
+
1106
+ enumStrValueMap := map [int ][]string {
1107
+ 38 : []string {"a" , "b" },
1108
+ 43 : []string {"c" , "d" },
1109
+ }
1110
+
1111
+ setStrValueMap := map [int ][]string {
1112
+ 39 : []string {"1" , "2" },
1113
+ 42 : []string {"3" , "4" },
1114
+ }
1115
+
1116
+ geometryTypeMap := map [int ]uint64 {
1117
+ 40 : 0 ,
1118
+ 44 : 7 , 45 : 6 , 46 : 5 , 47 : 4 , 48 : 3 , 49 : 2 , 50 : 1 ,
1119
+ }
1120
+
1121
+ testcases := []struct {
1122
+ flavor string
1123
+ data []byte
1124
+ unsignedMap map [int ]bool
1125
+ collationMap map [int ]uint64
1126
+ enumSetCollationMap map [int ]uint64
1127
+ enumStrValueMap map [int ][]string
1128
+ setStrValueMap map [int ][]string
1129
+ geometryTypeMap map [int ]uint64
1130
+ }{
1131
+ {
1132
+ flavor : "mysql" , // mysql 8.0
1133
+ data : []byte ("e\x00 \x00 \x00 \x00 \x00 \x01 \x00 \x04 test\x00 \x06 _types\x00 3\x10 \x01 \x01 \x02 \t \x03 \b \xf6 \x04 \x05 \x01 \x02 \t \x03 \b \xf6 \x04 \x05 \r \n \x13 \x13 \x12 \x12 \x11 \x11 \xfe \x0f \xfe \x0f \xfc \xfc \xfc \xfc \xfc \xfc \xfc \xfc \xfe \xfe \xff \xf5 \xfe \xfe \xff \xff \xff \xff \xff \xff \xff 1\x00 \b A\x1e \x04 \b A\x1e \x04 \b \x00 \x06 \x00 \x06 \x00 \x06 \xee \xfe \xfc \x03 \xfe @@\x00 \x01 \x02 \x03 \x04 \x01 \x02 \x03 \x04 \xf7 \x01 \xf8 \x01 \x04 \x04 \xf8 \x01 \xf7 \x01 \x04 \x04 \x04 \x04 \x04 \x04 \x04 \x00 \x00 \xfc \xc3 \xff \xff \a \x01 \x03 \x00 \u007f \x80 \x03 \f \x1c \xe0 ??????\xe0 \xe0 \xe0 \xe0 \a \b \x00 \a \x06 \x05 \x04 \x03 \x02 \x01 \x04 \xfc \x05 \x02 \x05 b_bit\t n_boolean\t n_tinyint\n n_smallint\v n_mediumint\x05 n_int\b n_bigint\t n_decimal\a n_float\b n_double\n nu_tinyint\v nu_smallint\f nu_mediumint\x06 nu_int\t nu_bigint\n nu_decimal\b nu_float\t nu_double\x06 t_year\x06 t_date\x06 t_time\a t_ftime\n t_datetime\v t_fdatetime\v t_timestamp\f t_ftimestamp\x06 c_char\t c_varchar\b c_binary\v c_varbinary\n c_tinyblob\x06 c_blob\f c_mediumblob\n c_longblob\n c_tinytext\x06 c_text\f c_mediumtext\n c_longtext\x06 e_enum\x05 s_set\n g_geometry\x06 j_json\x06 s_set2\a e_enum2\x14 g_geometrycollection\x0e g_multipolygon\x11 g_multilinestring\f g_multipoint\t g_polygon\f g_linestring\a g_point\v \x04 \xe0 \xe0 \x1c \x1c \x05 \n \x02 \x01 1\x01 2\x02 \x01 3\x01 4\x06 \n \x02 \x01 a\x01 b\x02 \x01 c\x01 d" ),
1134
+ unsignedMap : unsignedMap ,
1135
+ collationMap : mysqlCollationMap ,
1136
+ enumSetCollationMap : enumSetCollationMap ,
1137
+ enumStrValueMap : enumStrValueMap ,
1138
+ setStrValueMap : setStrValueMap ,
1139
+ geometryTypeMap : geometryTypeMap ,
1140
+ },
1141
+ {
1142
+ flavor : "mariadb" , // mariadb 10.5
1143
+ data : []byte ("\x1e \x00 \x00 \x00 \x00 \x00 \x01 \x00 \x04 test\x00 \x06 _types\x00 3\x10 \x01 \x01 \x02 \t \x03 \b \xf6 \x04 \x05 \x01 \x02 \t \x03 \b \xf6 \x04 \x05 \r \n \x13 \x13 \x12 \x12 \x11 \x11 \xfe \x0f \xfe \x0f \xfc \xfc \xfc \xfc \xfc \xfc \xfc \xfc \xfe \xfe \xff \xfc \xfe \xfe \xff \xff \xff \xff \xff \xff \xff 1\x00 \b A\x1e \x04 \b A\x1e \x04 \b \x00 \x06 \x00 \x06 \x00 \x06 \xee \xfe \xfc \x03 \xfe @@\x00 \x01 \x02 \x03 \x04 \x01 \x02 \x03 \x04 \xf7 \x01 \xf8 \x01 \x04 \x04 \xf8 \x01 \xf7 \x01 \x04 \x04 \x04 \x04 \x04 \x04 \x04 \x00 \x00 \xfc \xc0 \xff \xff \a \x01 \x03 \x00 \u007f \xc0 \x02 \x0f ?\x00 \x1c \x01 \xe0 \b \xe0 \t \xe0 \n \xe0 \v \xe0 \r .\a \b \x00 \a \x06 \x05 \x04 \x03 \x02 \x01 \x04 \xfc \x05 \x02 \x05 b_bit\t n_boolean\t n_tinyint\n n_smallint\v n_mediumint\x05 n_int\b n_bigint\t n_decimal\a n_float\b n_double\n nu_tinyint\v nu_smallint\f nu_mediumint\x06 nu_int\t nu_bigint\n nu_decimal\b nu_float\t nu_double\x06 t_year\x06 t_date\x06 t_time\a t_ftime\n t_datetime\v t_fdatetime\v t_timestamp\f t_ftimestamp\x06 c_char\t c_varchar\b c_binary\v c_varbinary\n c_tinyblob\x06 c_blob\f c_mediumblob\n c_longblob\n c_tinytext\x06 c_text\f c_mediumtext\n c_longtext\x06 e_enum\x05 s_set\n g_geometry\x06 j_json\x06 s_set2\a e_enum2\x14 g_geometrycollection\x0e g_multipolygon\x11 g_multilinestring\f g_multipoint\t g_polygon\f g_linestring\a g_point\v \x04 \xe0 \xe0 \x1c \x1c \x05 \n \x02 \x01 1\x01 2\x02 \x01 3\x01 4\x06 \n \x02 \x01 a\x01 b\x02 \x01 c\x01 d" ),
1144
+ unsignedMap : unsignedMap ,
1145
+ collationMap : mariadbCollationMap ,
1146
+ enumSetCollationMap : enumSetCollationMap ,
1147
+ enumStrValueMap : enumStrValueMap ,
1148
+ setStrValueMap : setStrValueMap ,
1149
+ geometryTypeMap : geometryTypeMap ,
1150
+ },
1151
+ {
1152
+ flavor : "mysql" , // mysql 5.7
1153
+ data : []byte ("q\x00 \x00 \x00 \x00 \x00 \x01 \x00 \x04 test\x00 \x06 _types\x00 3\x10 \x01 \x01 \x02 \t \x03 \b \xf6 \x04 \x05 \x01 \x02 \t \x03 \b \xf6 \x04 \x05 \r \n \x13 \x13 \x12 \x12 \x11 \x11 \xfe \x0f \xfe \x0f \xfc \xfc \xfc \xfc \xfc \xfc \xfc \xfc \xfe \xfe \xff \xf5 \xfe \xfe \xff \xff \xff \xff \xff \xff \xff 1\x00 \b A\x1e \x04 \b A\x1e \x04 \b \x00 \x06 \x00 \x06 \x00 \x06 \xee \xfe \xfc \x03 \xfe @@\x00 \x01 \x02 \x03 \x04 \x01 \x02 \x03 \x04 \xf7 \x01 \xf8 \x01 \x04 \x04 \xf8 \x01 \xf7 \x01 \x04 \x04 \x04 \x04 \x04 \x04 \x04 \x00 \x00 \xfc \xc0 \xff \xff \a " ),
1154
+ unsignedMap : nil ,
1155
+ collationMap : nil ,
1156
+ enumSetCollationMap : nil ,
1157
+ enumStrValueMap : nil ,
1158
+ setStrValueMap : nil ,
1159
+ geometryTypeMap : nil ,
1160
+ },
1161
+ {
1162
+ flavor : "mariadb" , // mariadb 10.4
1163
+ data : []byte ("\x1a \x00 \x00 \x00 \x00 \x00 \x01 \x00 \x04 test\x00 \x06 _types\x00 3\x10 \x01 \x01 \x02 \t \x03 \b \xf6 \x04 \x05 \x01 \x02 \t \x03 \b \xf6 \x04 \x05 \r \n \x13 \x13 \x12 \x12 \x11 \x11 \xfe \x0f \xfe \x0f \xfc \xfc \xfc \xfc \xfc \xfc \xfc \xfc \xfe \xfe \xff \xfc \xfe \xfe \xff \xff \xff \xff \xff \xff \xff 1\x00 \b A\x1e \x04 \b A\x1e \x04 \b \x00 \x06 \x00 \x06 \x00 \x06 \xee \xfe \xfc \x03 \xfe @@\x00 \x01 \x02 \x03 \x04 \x01 \x02 \x03 \x04 \xf7 \x01 \xf8 \x01 \x04 \x04 \xf8 \x01 \xf7 \x01 \x04 \x04 \x04 \x04 \x04 \x04 \x04 \x00 \x00 \xfc \xc0 \xff \xff \a " ),
1164
+ unsignedMap : nil ,
1165
+ collationMap : nil ,
1166
+ enumSetCollationMap : nil ,
1167
+ enumStrValueMap : nil ,
1168
+ setStrValueMap : nil ,
1169
+ geometryTypeMap : nil ,
1170
+ },
1171
+ }
1172
+
1173
+ for _ , tc := range testcases {
1174
+
1175
+ tableMapEvent := new (TableMapEvent )
1176
+ tableMapEvent .flavor = tc .flavor
1177
+ tableMapEvent .tableIDSize = 6
1178
+ err := tableMapEvent .Decode (tc .data )
1179
+ c .Assert (err , IsNil )
1180
+ c .Assert (tableMapEvent .UnsignedMap (), DeepEquals , tc .unsignedMap )
1181
+ c .Assert (tableMapEvent .CollationMap (), DeepEquals , tc .collationMap )
1182
+ c .Assert (tableMapEvent .EnumSetCollationMap (), DeepEquals , tc .enumSetCollationMap )
1183
+ c .Assert (tableMapEvent .EnumStrValueMap (), DeepEquals , tc .enumStrValueMap )
1184
+ c .Assert (tableMapEvent .SetStrValueMap (), DeepEquals , tc .setStrValueMap )
1185
+ c .Assert (tableMapEvent .GeometryTypeMap (), DeepEquals , tc .geometryTypeMap )
1186
+
1187
+ }
1188
+
1189
+ }
0 commit comments