1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
|
#
# WL#12370 : Helper file that calls the test UDFs
#
# Create the tables to test
CREATE TABLE test.country (utf varchar(40) CHARACTER SET utf8mb4,
cp12 varchar(40) CHARACTER SET cp1251,
lt1 VARCHAR(40) CHARACTER SET latin1);
# We are storing the HEX values of the non-ASCII characters as some
# editors may misinterpret the non-ASCII chars while reading/displaying them.
# Here are the actual string and their HEX code in their respective charset.
#
# ???? E0A4ADE0A4BEE0A4B0E0A4A4 utf8mb4
# ???????? C1FAEBE3E0F0E8FF cp1251
# sterreich D6737465727265696368 latin1
# ?????? D0A0D0BED181D181D0B8D18F utf8mb4
# ?????? D1F0E1E8BCE0 cp1251
# Belgi 42656C6769EB latin1
# India 496E646961 utf8mb4
# ??????? F3EAF0E0BFEDE0 cp1251
# Romnia 526F6DE26E6961 latin1
INSERT INTO test.country(utf, cp12, lt1) VALUES
(UNHEX('E0A4ADE0A4BEE0A4B0E0A4A4'), UNHEX('C1FAEBE3E0F0E8FF'),
UNHEX('D6737465727265696368')),
(UNHEX('D0A0D0BED181D181D0B8D18F'), UNHEX('D1F0E1E8BCE0'),
UNHEX('42656C6769EB')),
(UNHEX('496E646961'), UNHEX('F3EAF0E0BFEDE0'), UNHEX('526F6DE26E6961'));
CREATE TABLE test.names(utf_name varchar(40), eng_name varchar(40))
CHARACTER SET utf8mb4;
# The column 'utf_name' are stored in the utf8mb4 charset
# Following strings are stored in the table.
# ???? E0A4ADE0A4BEE0A4B0E0A4A4
# ???????? D091D18AD0BBD0B3D0B0D180D0B8D18F
# sterreich C396737465727265696368
# ?????? D0A0D0BED181D181D0B8D18F
# ?????? D0A1D180D0B1D0B8D198D0B0
# Belgi 42656C6769C3AB
# ??????? D183D0BAD180D0B0D197D0BDD0B0
# Romnia 526F6DC3A26E6961
INSERT INTO test.names(utf_name, eng_name) VALUES
(UNHEX('E0A4ADE0A4BEE0A4B0E0A4A4'), 'India'),
(UNHEX('D091D18AD0BBD0B3D0B0D180D0B8D18F'), 'Bulgaria'),
(UNHEX('C396737465727265696368'), 'Austria'),
(UNHEX('D0A0D0BED181D181D0B8D18F'), 'Russia'),
(UNHEX('D0A1D180D0B1D0B8D198D0B0'), 'Serbia'),
(UNHEX('42656C6769C3AB'), 'Belgium'),
(UNHEX('D183D0BAD180D0B0D197D0BDD0B0'), 'Ukraine'),
(UNHEX('526F6DC3A26E6961'), 'Romania');
--echo #------------------------------------------------------------------------
--echo # Tests that fetch the charset of second argument and apply that to the
--echo # return value. This UDF returns first argument.
--echo #------------------------------------------------------------------------
--echo #
--echo # 1.1 Without conversion the return values of UDF should not match with
--echo # ut8mb4 values.
SELECT HEX(utf_name) AS utf8_hex, HEX(lt1) as latin1_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_result_charset(lt1, lt1)) = HEX(utf_name) ORDER BY eng_name;
--echo
SELECT HEX(utf_name) AS utf8_hex, HEX(cp12) as cp1251_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_result_charset(cp12, cp12)) = HEX(utf_name) ORDER BY eng_name;
--echo #
--echo # 1.2 After conversion the return values should match with ut8mb4 values
--echo #
SELECT HEX(utf_name) AS utf8_hex, HEX(lt1) as latin1_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_result_charset(lt1, utf)) = HEX(utf_name) ORDER BY eng_name;
--echo
SELECT HEX(utf_name) AS utf8_hex, HEX(cp12) as cp1251_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_result_charset(cp12, utf)) = HEX(utf_name) ORDER BY eng_name;
--echo #
--echo # 1.3 Check the charset of the return value.
--echo #
SELECT CHARSET(test_result_charset(cp12, cp12))FROM test.country;
SELECT CHARSET(test_result_charset(lt1, lt1))FROM test.country;
--echo # Should be changed to ut8mb4 charset
SELECT CHARSET(test_result_charset(cp12, utf))FROM test.country;
SELECT CHARSET(test_result_charset(lt1, utf))FROM test.country;
--echo #------------------------------------------------------------------------
--echo # Tests that fetch the collation of second argument and apply that to the
--echo # return value. This UDF returns first argument.
--echo #------------------------------------------------------------------------
--echo #
--echo # 2.1 Without conversion the return values of UDF should not match with
--echo # ut8mb4 values.
SELECT HEX(utf_name) AS utf8_hex, HEX(lt1) as lt1_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_result_collation(lt1, lt1)) = HEX(utf_name) ORDER BY eng_name;
--echo
SELECT HEX(utf_name) AS utf8_hex, HEX(cp12) as cp12_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_result_collation(cp12, cp12)) = HEX(utf_name) ORDER BY eng_name;
--echo #
--echo # 2.2 After conversion the return values should match with ut8mb4 values
--echo #
SELECT HEX(utf_name) AS utf8_hex, HEX(lt1) as lt1_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_result_collation(lt1, utf)) = HEX(utf_name) ORDER BY eng_name;
--echo
SELECT HEX(utf_name) AS utf8_hex, HEX(cp12) as cp12_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_result_collation(cp12, utf)) = HEX(utf_name) ORDER BY eng_name;
--echo
--echo # 2.3 Check the charset of the value returned by the UDF
--echo #
SELECT CHARSET(test_result_collation(cp12, cp12)) from test.country;
SELECT CHARSET(test_result_collation(lt1, lt1)) from test.country;
--echo # Should be changed to utf8mb4 charset
SELECT CHARSET(test_result_collation(cp12, utf)) from test.country;
SELECT CHARSET(test_result_collation(lt1, utf)) from test.country;
--echo # 2.6 Check the collation of the value returned by the UDF
SELECT COLLATION(test_result_collation(cp12, cp12)) from test.country;
SELECT COLLATION(test_result_collation(lt1, lt1)) from test.country;
--echo # Should be changed to default utf8mb4 collation.
SELECT COLLATION(test_result_collation(cp12, utf)) from test.country;
SELECT COLLATION(test_result_collation(lt1, utf)) from test.country;
--echo
--echo #------------------------------------------------------------------------
--echo # Tests that fetch charset of second argument, apply that to first
--echo # argument and return the same.
--echo #------------------------------------------------------------------------
--echo #
--echo # 3.1 Without conversion the return values of UDF should not match with
--echo # ut8mb4 values.
SELECT HEX(utf_name) AS utf8_hex, HEX(lt1) as lt1_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_args_charset(lt1, lt1)) = HEX(utf_name) ORDER BY eng_name;
--echo
SELECT HEX(utf_name) AS utf8_hex, HEX(cp12) as cp12_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_args_charset(cp12, cp12)) = HEX(utf_name) ORDER BY eng_name;
--echo #
--echo # 3.2 After conversion the return values should match with ut8mb4 values
--echo #
SELECT HEX(utf_name) AS utf8_hex, HEX(lt1) as lt1_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_args_charset(lt1, utf)) = HEX(utf_name) ORDER BY eng_name;
--echo
SELECT HEX(utf_name) AS utf8_hex, HEX(cp12) as cp12_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_args_charset(cp12, utf)) = HEX(utf_name) ORDER BY eng_name;
--echo
--echo # 3.3 Check that charset of returning value is same as
--echo # default(i.e. binary)
SELECT CHARSET(test_args_charset(cp12, utf)) from test.country;
SELECT CHARSET(test_args_charset(lt1, utf)) from test.country;
--echo
--echo #------------------------------------------------------------------------
--echo # Tests that fetch collation of second argument, apply that to first
--echo # argument and return the same.
--echo #------------------------------------------------------------------------
--echo #
--echo # 4.1 Without conversion the return values of UDF should not match with
--echo # ut8mb4 values.
SELECT HEX(utf_name) AS utf8_hex, HEX(lt1) as lt1_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_args_collation(lt1, lt1)) = HEX(utf_name) ORDER BY eng_name;
--echo
SELECT HEX(utf_name) AS utf8_hex, HEX(cp12) as cp12_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_args_collation(cp12, cp12)) = HEX(utf_name) ORDER BY eng_name;
--echo #
--echo # 4.2 After conversion the return values should match with ut8mb4 values
--echo #
SELECT HEX(utf_name) AS utf8_hex, HEX(lt1) as lt1_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_args_collation(lt1, utf)) = HEX(utf_name) ORDER BY eng_name;
--echo
SELECT HEX(utf_name) AS utf8_hex, HEX(cp12) as cp12_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_args_collation(cp12, utf)) = HEX(utf_name) ORDER BY eng_name;
--echo
--echo # 4.3 Check that charset of returning value is same as
--echo # default(i.e. binary)
SELECT CHARSET(test_args_collation(cp12, utf)) from test.country;
SELECT CHARSET(test_args_collation(lt1, utf)) from test.country;
--echo
--echo # 4.4 Check that collation of returning value is same as default
--echo #
SELECT CHARSET(test_args_collation(cp12, utf)) from test.country;
SELECT CHARSET(test_args_collation(lt1, utf)) from test.country;
--echo #------------------------------------------------------------------------
--echo # Tests that check the Charset conversion happens through constant value.
--echo # UDFs pick the first argument as return value.
--echo #------------------------------------------------------------------------
# Specify the charset name of return value. UDF converts the charset
# of returned value as specified by the user.
--echo #
--echo # 5.1 Without conversion the return values of UDF should not match with
--echo # ut8mb4 values.
SELECT HEX(utf_name) AS utf8_hex, HEX(lt1) as lt1_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_result_charset_with_value(lt1, 'latin1')) = HEX(utf_name)
ORDER BY eng_name;
--echo
SELECT HEX(utf_name) AS utf8_hex, HEX(cp12) as cp12_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_result_charset_with_value(cp12, 'cp1251')) = HEX(utf_name)
ORDER BY eng_name;
--echo #
--echo # 5.2 After conversion the return values should match with ut8mb4 values
--echo #
SELECT HEX(utf_name) AS utf8_hex, HEX(lt1) as lt1_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_result_charset_with_value(lt1, 'utf8mb4')) = HEX(utf_name)
ORDER BY eng_name;
--echo
SELECT HEX(utf_name) AS utf8_hex, HEX(cp12) as cp12_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_result_charset_with_value(cp12, 'utf8mb4')) = HEX(utf_name)
ORDER BY eng_name;
--echo #
--echo # 5.3 Check the charset of the return value.
--echo #
SELECT CHARSET(test_result_charset_with_value(cp12, 'cp1251'))FROM test.country;
SELECT CHARSET(test_result_charset_with_value(lt1, 'latin1'))FROM test.country;
--echo # Should be changed to ut8mb4 charset
SELECT CHARSET(test_result_charset_with_value(cp12, 'utf8mb4'))FROM test.country;
SELECT CHARSET(test_result_charset_with_value(lt1, 'utf8mb4'))FROM test.country;
--echo #------------------------------------------------------------------------
--echo # Tests that check the Charset conversion happens through constant value.
--echo # We specify the collation name of return value. UDF converts the return
--echo # value into the valid charset for that collation.
--echo # This UDF picks the first argument as return value.
--echo #------------------------------------------------------------------------
--echo #
--echo # 5.4 After conversion the return values should match with ut8mb4 values
--echo #
SELECT HEX(utf_name) AS utf8_hex, HEX(lt1) as lt1_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_result_collation_with_value(lt1, 'utf8mb4_0900_ai_ci')) =
HEX(utf_name) ORDER BY eng_name;
--echo #
--echo # 5.5 First column has charset as 'cp1251' that is changed to 'utf8mb4'
--echo #
SELECT CHARSET(test_result_collation_with_value(cp12, 'utf8mb4_0900_ai_ci')) FROM test.country;
SELECT CHARSET(test_result_collation_with_value(cp12, 'utf8mb4_0900_bin')) FROM test.country;
SELECT CHARSET(test_result_collation_with_value(cp12, 'utf8mb4_general_ci')) FROM test.country;
--echo #
--echo # 5.6 Collation of the return string is also updated as specified
--echo #
SELECT COLLATION(test_result_collation_with_value(cp12, 'utf8mb4_0900_ai_ci')) FROM test.country;
SELECT COLLATION(test_result_collation_with_value(cp12, 'utf8mb4_0900_bin')) FROM test.country;
SELECT COLLATION(test_result_collation_with_value(cp12, 'utf8mb4_general_ci')) FROM test.country;
--echo #------------------------------------------------------------------------
--echo # Tests that check the Charset conversion happens through constant value.
--echo # We specify the collation name of first argument. UDF returns converted
--echo # first argument value into the valid charset for that collation.
--echo #------------------------------------------------------------------------
--echo
--echo #
--echo # 6.1 After conversion the return values should match with ut8mb4 values
--echo #
SELECT HEX(utf_name) AS utf8_hex, HEX(lt1) as lt1_hex, eng_name
FROM test.names INNER JOIN test.country ON
HEX(test_args_collation_with_value(lt1, 'utf8mb4_0900_ai_ci')) =
HEX(utf_name) ORDER BY eng_name;
--echo # 6.2 Convert the charset of first argument according to second arg
SELECT CHARSET(test_args_collation_with_value(cp12, 'utf8mb4_0900_ai_ci')) FROM test.country;
SELECT CHARSET(test_args_collation_with_value(cp12, 'utf8mb4_0900_bin')) FROM test.country;
SELECT CHARSET(test_args_collation_with_value(cp12, 'utf8mb4_general_ci')) FROM test.country;
--echo # 6.3 Check the collation of converted charset
# By default collation of return value remains 'binary'
SELECT COLLATION(test_args_collation_with_value(cp12, 'utf8mb4_0900_ai_ci')) FROM test.country;
SELECT COLLATION(test_args_collation_with_value(cp12, 'utf8mb4_0900_bin')) FROM test.country;
SELECT COLLATION(test_args_collation_with_value(cp12, 'utf8mb4_general_ci')) FROM test.country;
--echo #------------------------------------------------------------------------
--echo # Negative test scenarios
--echo #------------------------------------------------------------------------
--error ER_DA_UDF_INVALID_CHARSET
SELECT test_result_charset_with_value(cp12, 'utf8mb4_invalid') FROM test.country;
--error ER_DA_UDF_INVALID_CHARSET
SELECT test_args_charset_with_value(cp12, 'utf8mb4_invalid') FROM test.country;
--error ER_DA_UDF_INVALID_COLLATION
SELECT test_result_collation_with_value(cp12, 'utf8mb4_invalid') FROM test.country;
--error ER_DA_UDF_INVALID_CHARSET
SELECT test_result_charset_with_value(cp12, '') FROM test.country;
SELECT test_args_charset_with_value('', 'utf8mb4') FROM test.country;
--error ER_DA_UDF_INVALID_CHARSET
SELECT test_args_charset_with_value(utf, '') FROM test.country;
--error ER_DA_UDF_INVALID_COLLATION
SELECT test_result_collation_with_value('cp12', '') FROM test.country;
--echo # cleanup
DROP TABLE test.country;
DROP TABLE test.names;
|