github.com/dolthub/go-mysql-server@v0.18.0/enginetest/queries/collation_coercion.go (about) 1 // Copyright 2023 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package queries 16 17 import ( 18 "github.com/dolthub/go-mysql-server/sql" 19 ) 20 21 // CollationCoercionTest is used to test the resulting collation and coercion of a SQL expression 22 type CollationCoercionTest struct { 23 Parameters string 24 Collation sql.CollationID 25 Coercibility int64 26 Error bool 27 } 28 29 // CollationCoercionSetup is the setup that is run before every CollationCoercionTest 30 var CollationCoercionSetup = []string{ 31 `SET CHARACTER SET "utf8mb4";`, 32 `SET collation_connection = "utf8mb4_0900_bin";`, 33 `SET character_set_results = "binary";`, 34 `CREATE TABLE temp_tbl (v1 VARCHAR(200) COLLATE utf8mb4_0900_bin, 35 v2 VARCHAR(200) COLLATE utf8mb4_0900_as_cs DEFAULT 'z', 36 v3 VARCHAR(200) COLLATE utf8mb4_0900_ai_ci, 37 v4 VARCHAR(200) COLLATE utf8mb3_bin, 38 v5 VARCHAR(200) COLLATE utf8mb3_general_ci, 39 v6 VARCHAR(200) COLLATE latin1_bin, 40 v7 VARCHAR(200) COLLATE latin1_general_ci, 41 v8 VARBINARY(200));`, 42 `INSERT INTO temp_tbl VALUES ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h');`, 43 } 44 45 var CollationCoercionTests = []CollationCoercionTest{ 46 { 47 Parameters: `'26:27:28'`, 48 Collation: sql.Collation_utf8mb4_0900_bin, 49 Coercibility: 4, 50 }, 51 { 52 Parameters: `'str' COLLATE utf8mb4_bin`, 53 Collation: sql.Collation_utf8mb4_bin, 54 Coercibility: 0, 55 }, 56 { 57 Parameters: `1001`, 58 Collation: sql.Collation_binary, 59 Coercibility: 5, 60 }, 61 { 62 Parameters: `2002.5`, 63 Collation: sql.Collation_binary, 64 Coercibility: 5, 65 }, 66 { 67 Parameters: `CONVERT('2020-02-20 20:20:20', DATETIME)`, 68 Collation: sql.Collation_binary, 69 Coercibility: 5, 70 }, 71 { 72 Parameters: `CONVERT('2020-02-20', DATE)`, 73 Collation: sql.Collation_binary, 74 Coercibility: 5, 75 }, 76 { 77 Parameters: `CONVERT('23:24:25', TIME)`, 78 Collation: sql.Collation_binary, 79 Coercibility: 5, 80 }, 81 { 82 Parameters: `CONVERT('34', BINARY)`, 83 Collation: sql.Collation_binary, 84 Coercibility: 2, 85 }, 86 { 87 Parameters: `CONVERT('34', SIGNED)`, 88 Collation: sql.Collation_binary, 89 Coercibility: 5, 90 }, 91 { 92 Parameters: `CONVERT('34', UNSIGNED)`, 93 Collation: sql.Collation_binary, 94 Coercibility: 5, 95 }, 96 { 97 Parameters: `CONVERT('[1]', JSON)`, 98 Collation: sql.Collation_utf8mb4_bin, 99 Coercibility: 2, 100 }, 101 { 102 Parameters: `CURDATE()`, 103 Collation: sql.Collation_binary, 104 Coercibility: 5, 105 }, 106 { 107 Parameters: `CURRENT_USER()`, 108 Collation: sql.Collation_utf8_general_ci, 109 Coercibility: 3, 110 }, 111 { 112 Parameters: `FALSE`, 113 Collation: sql.Collation_binary, 114 Coercibility: 5, 115 }, 116 { 117 Parameters: `TRUE`, 118 Collation: sql.Collation_binary, 119 Coercibility: 5, 120 }, 121 { 122 Parameters: `NOW()`, 123 Collation: sql.Collation_binary, 124 Coercibility: 5, 125 }, 126 { 127 Parameters: `NULL`, 128 Collation: sql.Collation_binary, 129 Coercibility: 6, 130 }, 131 { 132 Parameters: `UUID()`, 133 Collation: sql.Collation_utf8_general_ci, 134 Coercibility: 4, 135 }, 136 { 137 Parameters: `v1`, 138 Collation: sql.Collation_utf8mb4_0900_bin, 139 Coercibility: 2, 140 }, 141 { 142 Parameters: `v1 COLLATE utf8mb4_0900_bin`, 143 Collation: sql.Collation_utf8mb4_0900_bin, 144 Coercibility: 0, 145 }, 146 { 147 Parameters: `v2`, 148 Collation: sql.Collation_utf8mb4_0900_as_cs, 149 Coercibility: 2, 150 }, 151 { 152 Parameters: `v2 COLLATE utf8mb4_0900_as_cs`, 153 Collation: sql.Collation_utf8mb4_0900_as_cs, 154 Coercibility: 0, 155 }, 156 { 157 Parameters: `v3`, 158 Collation: sql.Collation_utf8mb4_0900_ai_ci, 159 Coercibility: 2, 160 }, 161 { 162 Parameters: `v3 COLLATE utf8mb4_0900_ai_ci`, 163 Collation: sql.Collation_utf8mb4_0900_ai_ci, 164 Coercibility: 0, 165 }, 166 { 167 Parameters: `v4`, 168 Collation: sql.Collation_utf8_bin, 169 Coercibility: 2, 170 }, 171 { 172 Parameters: `v4 COLLATE utf8mb3_bin`, 173 Collation: sql.Collation_utf8_bin, 174 Coercibility: 0, 175 }, 176 { 177 Parameters: `v5`, 178 Collation: sql.Collation_utf8_general_ci, 179 Coercibility: 2, 180 }, 181 { 182 Parameters: `v5 COLLATE utf8mb3_general_ci`, 183 Collation: sql.Collation_utf8_general_ci, 184 Coercibility: 0, 185 }, 186 { 187 Parameters: `v6`, 188 Collation: sql.Collation_latin1_bin, 189 Coercibility: 2, 190 }, 191 { 192 Parameters: `v6 COLLATE latin1_bin`, 193 Collation: sql.Collation_latin1_bin, 194 Coercibility: 0, 195 }, 196 { 197 Parameters: `v7`, 198 Collation: sql.Collation_latin1_general_ci, 199 Coercibility: 2, 200 }, 201 { 202 Parameters: `v7 COLLATE latin1_general_ci`, 203 Collation: sql.Collation_latin1_general_ci, 204 Coercibility: 0, 205 }, 206 { 207 Parameters: `v8`, 208 Collation: sql.Collation_binary, 209 Coercibility: 2, 210 }, 211 { 212 Parameters: `v8 COLLATE 'binary'`, 213 Collation: sql.Collation_binary, 214 Coercibility: 0, 215 }, 216 { 217 Parameters: `!('26:27:28')`, 218 Collation: sql.Collation_binary, 219 Coercibility: 5, 220 }, 221 { 222 Parameters: `!('str' COLLATE utf8mb4_bin)`, 223 Collation: sql.Collation_binary, 224 Coercibility: 5, 225 }, 226 { 227 Parameters: `-(CONVERT('2020-02-20', DATE))`, 228 Collation: sql.Collation_binary, 229 Coercibility: 5, 230 }, 231 { 232 Parameters: `-(CONVERT('34', BINARY))`, 233 Collation: sql.Collation_binary, 234 Coercibility: 5, 235 }, 236 { 237 Parameters: `-(v6)`, 238 Collation: sql.Collation_binary, 239 Coercibility: 5, 240 }, 241 { 242 Parameters: `NOT('{"a": 1, "b": {"c": 30}}')`, 243 Collation: sql.Collation_binary, 244 Coercibility: 5, 245 }, 246 { 247 Parameters: `CURRENT_TIME() != '26:27:28'`, 248 Collation: sql.Collation_binary, 249 Coercibility: 5, 250 }, 251 { 252 Parameters: `v4 != '26:27:28'`, 253 Collation: sql.Collation_binary, 254 Coercibility: 5, 255 }, 256 { 257 Parameters: `FALSE * '26:27:28'`, 258 Collation: sql.Collation_binary, 259 Coercibility: 5, 260 }, 261 { 262 Parameters: `FALSE * '26:27:28'`, 263 Collation: sql.Collation_binary, 264 Coercibility: 5, 265 }, 266 { 267 Parameters: `v5 + '26:27:28'`, 268 Collation: sql.Collation_binary, 269 Coercibility: 5, 270 }, 271 { 272 Parameters: `v5 COLLATE utf8mb3_general_ci + '26:27:28'`, 273 Collation: sql.Collation_binary, 274 Coercibility: 5, 275 }, 276 { 277 Parameters: `v6 + '26:27:28'`, 278 Collation: sql.Collation_binary, 279 Coercibility: 5, 280 }, 281 { 282 Parameters: `v6 COLLATE latin1_bin + '26:27:28'`, 283 Collation: sql.Collation_binary, 284 Coercibility: 5, 285 }, 286 { 287 Parameters: `'str' - CURRENT_TIME()`, 288 Collation: sql.Collation_binary, 289 Coercibility: 5, 290 }, 291 { 292 Parameters: `v2 / 1001`, 293 Collation: sql.Collation_binary, 294 Coercibility: 5, 295 }, 296 { 297 Parameters: `v2 COLLATE utf8mb4_0900_as_cs / 1001`, 298 Collation: sql.Collation_binary, 299 Coercibility: 5, 300 }, 301 { 302 Parameters: `1001 < CONVERT('34', CHAR)`, 303 Collation: sql.Collation_binary, 304 Coercibility: 5, 305 }, 306 { 307 Parameters: `2002.5 < CONVERT('34', CHAR)`, 308 Collation: sql.Collation_binary, 309 Coercibility: 5, 310 }, 311 { 312 Parameters: `1001 <= RAND()`, 313 Collation: sql.Collation_binary, 314 Coercibility: 5, 315 }, 316 { 317 Parameters: `2002.5 <= RAND()`, 318 Collation: sql.Collation_binary, 319 Coercibility: 5, 320 }, 321 { 322 Parameters: `CONVERT('23:24:25', TIME) DIV NOW()`, 323 Collation: sql.Collation_binary, 324 Coercibility: 5, 325 }, 326 { 327 Parameters: `NULLIF('str' COLLATE utf8mb4_bin, '26:27:28')`, 328 Collation: sql.Collation_utf8mb4_bin, 329 Coercibility: 0, 330 }, 331 { 332 Parameters: `NULLIF('{"a": 1, "b": {"c": 30}}', '26:27:28')`, 333 Collation: sql.Collation_utf8mb4_0900_bin, 334 Coercibility: 4, 335 }, 336 { 337 Parameters: `REPEAT(v1, 1001)`, 338 Collation: sql.Collation_utf8mb4_0900_bin, 339 Coercibility: 2, 340 }, 341 { 342 Parameters: `SUBSTR(v6, CONVERT('2020-02-20 20:20:20', DATETIME))`, 343 Collation: sql.Collation_latin1_bin, 344 Coercibility: 2, 345 }, 346 { 347 Parameters: `SUBSTR(v6 COLLATE latin1_bin, CONVERT('2020-02-20 20:20:20', DATETIME))`, 348 Collation: sql.Collation_latin1_bin, 349 Coercibility: 0, 350 }, 351 }