| Total Complexity | 56 |
| Total Lines | 1376 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like TestCommandTrait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TestCommandTrait, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | trait TestCommandTrait |
||
| 28 | { |
||
| 29 | public function testConstruct(): void |
||
| 30 | { |
||
| 31 | $db = $this->getConnection(); |
||
|
|
|||
| 32 | |||
| 33 | /* null */ |
||
| 34 | $command = $db->createCommand(); |
||
| 35 | |||
| 36 | $this->assertNull($command->getSql()); |
||
| 37 | |||
| 38 | /* string */ |
||
| 39 | $sql = 'SELECT * FROM customer'; |
||
| 40 | |||
| 41 | $command = $db->createCommand($sql); |
||
| 42 | |||
| 43 | $this->assertEquals($sql, $command->getSql()); |
||
| 44 | } |
||
| 45 | |||
| 46 | public function testGetSetSql(): void |
||
| 47 | { |
||
| 48 | $db = $this->getConnection(); |
||
| 49 | |||
| 50 | $sql = 'SELECT * FROM customer'; |
||
| 51 | |||
| 52 | $command = $db->createCommand($sql); |
||
| 53 | |||
| 54 | $this->assertEquals($sql, $command->getSql()); |
||
| 55 | |||
| 56 | $sql2 = 'SELECT * FROM order'; |
||
| 57 | |||
| 58 | $command->setSql($sql2); |
||
| 59 | |||
| 60 | $this->assertEquals($sql2, $command->getSql()); |
||
| 61 | } |
||
| 62 | |||
| 63 | public function testPrepareCancel(): void |
||
| 64 | { |
||
| 65 | $db = $this->getConnection(); |
||
| 66 | |||
| 67 | $command = $db->createCommand('SELECT * FROM {{customer}}'); |
||
| 68 | |||
| 69 | $this->assertNull($command->getPdoStatement()); |
||
| 70 | |||
| 71 | $command->prepare(); |
||
| 72 | |||
| 73 | $this->assertNotNull($command->getPdoStatement()); |
||
| 74 | |||
| 75 | $command->cancel(); |
||
| 76 | |||
| 77 | $this->assertNull($command->getPdoStatement()); |
||
| 78 | } |
||
| 79 | |||
| 80 | public function testExecute(): void |
||
| 81 | { |
||
| 82 | $db = $this->getConnection(true); |
||
| 83 | |||
| 84 | $sql = 'INSERT INTO {{customer}}([[email]], [[name]], [[address]])' |
||
| 85 | . ' VALUES (\'[email protected]\', \'user4\', \'address4\')'; |
||
| 86 | |||
| 87 | $command = $db->createCommand($sql); |
||
| 88 | |||
| 89 | $this->assertEquals(1, $command->execute()); |
||
| 90 | |||
| 91 | $sql = 'SELECT COUNT(*) FROM {{customer}} WHERE [[name]] = \'user4\''; |
||
| 92 | |||
| 93 | $command = $db->createCommand($sql); |
||
| 94 | |||
| 95 | $this->assertEquals(1, $command->queryScalar()); |
||
| 96 | |||
| 97 | $command = $db->createCommand('bad SQL'); |
||
| 98 | |||
| 99 | $this->expectException(Exception::class); |
||
| 100 | |||
| 101 | $command->execute(); |
||
| 102 | } |
||
| 103 | |||
| 104 | public function testQuery(): void |
||
| 105 | { |
||
| 106 | $db = $this->getConnection(true); |
||
| 107 | |||
| 108 | /* query */ |
||
| 109 | $sql = 'SELECT * FROM {{customer}}'; |
||
| 110 | |||
| 111 | $reader = $db->createCommand($sql)->Query(); |
||
| 112 | |||
| 113 | $this->assertInstanceOf(DataReader::class, $reader); |
||
| 114 | |||
| 115 | /* queryAll */ |
||
| 116 | $rows = $db->createCommand('SELECT * FROM {{customer}}')->queryAll(); |
||
| 117 | |||
| 118 | $this->assertCount(3, $rows); |
||
| 119 | |||
| 120 | $row = $rows[2]; |
||
| 121 | |||
| 122 | $this->assertEquals(3, $row['id']); |
||
| 123 | $this->assertEquals('user3', $row['name']); |
||
| 124 | |||
| 125 | $rows = $db->createCommand('SELECT * FROM {{customer}} WHERE [[id]] = 10')->queryAll(); |
||
| 126 | |||
| 127 | $this->assertEquals([], $rows); |
||
| 128 | |||
| 129 | /* queryOne */ |
||
| 130 | $sql = 'SELECT * FROM {{customer}} ORDER BY [[id]]'; |
||
| 131 | |||
| 132 | $row = $db->createCommand($sql)->queryOne(); |
||
| 133 | |||
| 134 | $this->assertEquals(1, $row['id']); |
||
| 135 | $this->assertEquals('user1', $row['name']); |
||
| 136 | |||
| 137 | $sql = 'SELECT * FROM {{customer}} ORDER BY [[id]]'; |
||
| 138 | |||
| 139 | $command = $db->createCommand($sql); |
||
| 140 | |||
| 141 | $command->prepare(); |
||
| 142 | |||
| 143 | $row = $command->queryOne(); |
||
| 144 | |||
| 145 | $this->assertEquals(1, $row['id']); |
||
| 146 | $this->assertEquals('user1', $row['name']); |
||
| 147 | |||
| 148 | $sql = 'SELECT * FROM {{customer}} WHERE [[id]] = 10'; |
||
| 149 | |||
| 150 | $command = $db->createCommand($sql); |
||
| 151 | |||
| 152 | $this->assertFalse($command->queryOne()); |
||
| 153 | |||
| 154 | /* queryColumn */ |
||
| 155 | $sql = 'SELECT * FROM {{customer}}'; |
||
| 156 | |||
| 157 | $column = $db->createCommand($sql)->queryColumn(); |
||
| 158 | |||
| 159 | $this->assertEquals(range(1, 3), $column); |
||
| 160 | |||
| 161 | $command = $db->createCommand('SELECT [[id]] FROM {{customer}} WHERE [[id]] = 10'); |
||
| 162 | |||
| 163 | $this->assertEquals([], $command->queryColumn()); |
||
| 164 | |||
| 165 | /* queryScalar */ |
||
| 166 | $sql = 'SELECT * FROM {{customer}} ORDER BY [[id]]'; |
||
| 167 | |||
| 168 | $this->assertEquals($db->createCommand($sql)->queryScalar(), 1); |
||
| 169 | |||
| 170 | $sql = 'SELECT [[id]] FROM {{customer}} ORDER BY [[id]]'; |
||
| 171 | |||
| 172 | $command = $db->createCommand($sql); |
||
| 173 | |||
| 174 | $command->prepare(); |
||
| 175 | |||
| 176 | $this->assertEquals(1, $command->queryScalar()); |
||
| 177 | |||
| 178 | $command = $db->createCommand('SELECT [[id]] FROM {{customer}} WHERE [[id]] = 10'); |
||
| 179 | |||
| 180 | $this->assertFalse($command->queryScalar()); |
||
| 181 | |||
| 182 | $command = $db->createCommand('bad SQL'); |
||
| 183 | |||
| 184 | $this->expectException(Exception::class); |
||
| 185 | |||
| 186 | $command->Query(); |
||
| 187 | } |
||
| 188 | |||
| 189 | public function testFetchMode(): void |
||
| 190 | { |
||
| 191 | $db = $this->getConnection(); |
||
| 192 | |||
| 193 | /* default: FETCH_ASSOC */ |
||
| 194 | $sql = 'SELECT * FROM {{customer}}'; |
||
| 195 | |||
| 196 | $command = $db->createCommand($sql); |
||
| 197 | |||
| 198 | $result = $command->queryOne(); |
||
| 199 | |||
| 200 | $this->assertTrue(is_array($result) && isset($result['id'])); |
||
| 201 | |||
| 202 | /* FETCH_OBJ, customized via fetchMode property */ |
||
| 203 | $sql = 'SELECT * FROM {{customer}}'; |
||
| 204 | |||
| 205 | $command = $db->createCommand($sql); |
||
| 206 | |||
| 207 | $command->setFetchMode(PDO::FETCH_OBJ); |
||
| 208 | |||
| 209 | $result = $command->queryOne(); |
||
| 210 | |||
| 211 | $this->assertIsObject($result); |
||
| 212 | |||
| 213 | /* FETCH_NUM, customized in query method */ |
||
| 214 | $sql = 'SELECT * FROM {{customer}}'; |
||
| 215 | |||
| 216 | $command = $db->createCommand($sql); |
||
| 217 | |||
| 218 | $result = $command->queryOne(PDO::FETCH_NUM); |
||
| 219 | |||
| 220 | $this->assertTrue(is_array($result) && isset($result[0])); |
||
| 221 | } |
||
| 222 | |||
| 223 | public function testBatchInsert(): void |
||
| 224 | { |
||
| 225 | $db = $this->getConnection(); |
||
| 226 | |||
| 227 | $command = $db->createCommand(); |
||
| 228 | |||
| 229 | $command->batchInsert( |
||
| 230 | '{{customer}}', |
||
| 231 | ['email', 'name', 'address'], |
||
| 232 | [ |
||
| 233 | ['[email protected]', 't1', 't1 address'], |
||
| 234 | ['[email protected]', null, false], |
||
| 235 | ] |
||
| 236 | ); |
||
| 237 | |||
| 238 | $this->assertEquals(2, $command->execute()); |
||
| 239 | |||
| 240 | /** |
||
| 241 | * {@see https://github.com/yiisoft/yii2/issues/11693} |
||
| 242 | */ |
||
| 243 | $command = $this->getConnection()->createCommand(); |
||
| 244 | |||
| 245 | $command->batchInsert( |
||
| 246 | '{{customer}}', |
||
| 247 | ['email', 'name', 'address'], |
||
| 248 | [] |
||
| 249 | ); |
||
| 250 | |||
| 251 | $this->assertEquals(0, $command->execute()); |
||
| 252 | } |
||
| 253 | |||
| 254 | public function testBatchInsertWithYield(): void |
||
| 255 | { |
||
| 256 | $rows = call_user_func(static function () { |
||
| 257 | if (false) { |
||
| 258 | yield []; |
||
| 259 | } |
||
| 260 | }); |
||
| 261 | |||
| 262 | $command = $this->getConnection()->createCommand(); |
||
| 263 | |||
| 264 | $command->batchInsert( |
||
| 265 | '{{customer}}', |
||
| 266 | ['email', 'name', 'address'], |
||
| 267 | $rows |
||
| 268 | ); |
||
| 269 | |||
| 270 | $this->assertEquals(0, $command->execute()); |
||
| 271 | } |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Test batch insert with different data types. |
||
| 275 | * |
||
| 276 | * Ensure double is inserted with `.` decimal separator. |
||
| 277 | * |
||
| 278 | * {@see https://github.com/yiisoft/yii2/issues/6526} |
||
| 279 | */ |
||
| 280 | public function testBatchInsertDataTypesLocale(): void |
||
| 281 | { |
||
| 282 | $locale = setlocale(LC_NUMERIC, 0); |
||
| 283 | |||
| 284 | if (false === $locale) { |
||
| 285 | $this->markTestSkipped('Your platform does not support locales.'); |
||
| 286 | } |
||
| 287 | |||
| 288 | $db = $this->getConnection(); |
||
| 289 | |||
| 290 | try { |
||
| 291 | /* This one sets decimal mark to comma sign */ |
||
| 292 | setlocale(LC_NUMERIC, 'ru_RU.utf8'); |
||
| 293 | |||
| 294 | $cols = ['int_col', 'char_col', 'float_col', 'bool_col']; |
||
| 295 | |||
| 296 | $data = [ |
||
| 297 | [1, 'A', 9.735, true], |
||
| 298 | [2, 'B', -2.123, false], |
||
| 299 | [3, 'C', 2.123, false], |
||
| 300 | ]; |
||
| 301 | |||
| 302 | /* clear data in "type" table */ |
||
| 303 | $db->createCommand()->delete('type')->execute(); |
||
| 304 | |||
| 305 | /* batch insert on "type" table */ |
||
| 306 | $db->createCommand()->batchInsert('type', $cols, $data)->execute(); |
||
| 307 | |||
| 308 | $data = $db->createCommand( |
||
| 309 | 'SELECT int_col, char_col, float_col, bool_col FROM {{type}} WHERE [[int_col]] IN (1,2,3) |
||
| 310 | ORDER BY [[int_col]];' |
||
| 311 | )->queryAll(); |
||
| 312 | |||
| 313 | $this->assertCount(3, $data); |
||
| 314 | $this->assertEquals(1, $data[0]['int_col']); |
||
| 315 | $this->assertEquals(2, $data[1]['int_col']); |
||
| 316 | $this->assertEquals(3, $data[2]['int_col']); |
||
| 317 | |||
| 318 | /* rtrim because Postgres padds the column with whitespace */ |
||
| 319 | $this->assertEquals('A', rtrim($data[0]['char_col'])); |
||
| 320 | $this->assertEquals('B', rtrim($data[1]['char_col'])); |
||
| 321 | $this->assertEquals('C', rtrim($data[2]['char_col'])); |
||
| 322 | $this->assertEquals('9.735', $data[0]['float_col']); |
||
| 323 | $this->assertEquals('-2.123', $data[1]['float_col']); |
||
| 324 | $this->assertEquals('2.123', $data[2]['float_col']); |
||
| 325 | $this->assertEquals('1', $data[0]['bool_col']); |
||
| 326 | $this->assertIsOneOf($data[1]['bool_col'], ['0', false]); |
||
| 327 | $this->assertIsOneOf($data[2]['bool_col'], ['0', false]); |
||
| 328 | } catch (Exception $e) { |
||
| 329 | setlocale(LC_NUMERIC, $locale); |
||
| 330 | |||
| 331 | throw $e; |
||
| 332 | } catch (Throwable $e) { |
||
| 333 | setlocale(LC_NUMERIC, $locale); |
||
| 334 | |||
| 335 | throw $e; |
||
| 336 | } |
||
| 337 | |||
| 338 | setlocale(LC_NUMERIC, $locale); |
||
| 339 | } |
||
| 340 | |||
| 341 | public function testInsert(): void |
||
| 342 | { |
||
| 343 | $db = $this->getConnection(); |
||
| 344 | |||
| 345 | $db->createCommand('DELETE FROM {{customer}}')->execute(); |
||
| 346 | |||
| 347 | $command = $db->createCommand(); |
||
| 348 | |||
| 349 | $command->insert( |
||
| 350 | '{{customer}}', |
||
| 351 | [ |
||
| 352 | 'email' => '[email protected]', |
||
| 353 | 'name' => 'test', |
||
| 354 | 'address' => 'test address', |
||
| 355 | ] |
||
| 356 | )->execute(); |
||
| 357 | |||
| 358 | $this->assertEquals(1, $db->createCommand('SELECT COUNT(*) FROM {{customer}};')->queryScalar()); |
||
| 359 | |||
| 360 | $record = $db->createCommand('SELECT [[email]], [[name]], [[address]] FROM {{customer}}')->queryOne(); |
||
| 361 | |||
| 362 | $this->assertEquals([ |
||
| 363 | 'email' => '[email protected]', |
||
| 364 | 'name' => 'test', |
||
| 365 | 'address' => 'test address', |
||
| 366 | ], $record); |
||
| 367 | } |
||
| 368 | |||
| 369 | /** |
||
| 370 | * verify that {{}} are not going to be replaced in parameters. |
||
| 371 | */ |
||
| 372 | public function testNoTablenameReplacement(): void |
||
| 373 | { |
||
| 374 | $db = $this->getConnection(true); |
||
| 375 | |||
| 376 | $db->createCommand()->insert( |
||
| 377 | '{{customer}}', |
||
| 378 | [ |
||
| 379 | 'name' => 'Some {{weird}} name', |
||
| 380 | 'email' => '[email protected]', |
||
| 381 | 'address' => 'Some {{%weird}} address', |
||
| 382 | ] |
||
| 383 | )->execute(); |
||
| 384 | |||
| 385 | if ($db->getDriverName() === 'pgsql') { |
||
| 386 | $customerId = $db->getLastInsertID('public.customer_id_seq'); |
||
| 387 | } else { |
||
| 388 | $customerId = $db->getLastInsertID(); |
||
| 389 | } |
||
| 390 | |||
| 391 | $customer = $db->createCommand('SELECT * FROM {{customer}} WHERE id=' . $customerId)->queryOne(); |
||
| 392 | |||
| 393 | $this->assertEquals('Some {{weird}} name', $customer['name']); |
||
| 394 | $this->assertEquals('Some {{%weird}} address', $customer['address']); |
||
| 395 | |||
| 396 | $db->createCommand()->update( |
||
| 397 | '{{customer}}', |
||
| 398 | [ |
||
| 399 | 'name' => 'Some {{updated}} name', |
||
| 400 | 'address' => 'Some {{%updated}} address', |
||
| 401 | ], |
||
| 402 | ['id' => $customerId] |
||
| 403 | )->execute(); |
||
| 404 | |||
| 405 | $customer = $db->createCommand('SELECT * FROM {{customer}} WHERE id=' . $customerId)->queryOne(); |
||
| 406 | |||
| 407 | $this->assertEquals('Some {{updated}} name', $customer['name']); |
||
| 408 | $this->assertEquals('Some {{%updated}} address', $customer['address']); |
||
| 409 | } |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Test INSERT INTO ... SELECT SQL statement. |
||
| 413 | */ |
||
| 414 | public function testInsertSelect(): void |
||
| 415 | { |
||
| 416 | $db = $this->getConnection(); |
||
| 417 | |||
| 418 | $db->createCommand('DELETE FROM {{customer}}')->execute(); |
||
| 419 | |||
| 420 | $command = $db->createCommand(); |
||
| 421 | |||
| 422 | $command->insert( |
||
| 423 | '{{customer}}', |
||
| 424 | [ |
||
| 425 | 'email' => '[email protected]', |
||
| 426 | 'name' => 'test', |
||
| 427 | 'address' => 'test address', |
||
| 428 | ] |
||
| 429 | )->execute(); |
||
| 430 | |||
| 431 | $query = new Query($db); |
||
| 432 | |||
| 433 | $query->select( |
||
| 434 | [ |
||
| 435 | '{{customer}}.[[email]] as name', |
||
| 436 | '[[name]] as email', |
||
| 437 | '[[address]]', |
||
| 438 | ] |
||
| 439 | ) |
||
| 440 | ->from('{{customer}}') |
||
| 441 | ->where([ |
||
| 442 | 'and', |
||
| 443 | ['<>', 'name', 'foo'], |
||
| 444 | ['status' => [0, 1, 2, 3]], |
||
| 445 | ]); |
||
| 446 | |||
| 447 | $command = $db->createCommand(); |
||
| 448 | |||
| 449 | $command->insert( |
||
| 450 | '{{customer}}', |
||
| 451 | $query |
||
| 452 | )->execute(); |
||
| 453 | |||
| 454 | $this->assertEquals(2, $db->createCommand('SELECT COUNT(*) FROM {{customer}}')->queryScalar()); |
||
| 455 | |||
| 456 | $record = $db->createCommand('SELECT [[email]], [[name]], [[address]] FROM {{customer}}')->queryAll(); |
||
| 457 | |||
| 458 | $this->assertEquals([ |
||
| 459 | [ |
||
| 460 | 'email' => '[email protected]', |
||
| 461 | 'name' => 'test', |
||
| 462 | 'address' => 'test address', |
||
| 463 | ], |
||
| 464 | [ |
||
| 465 | 'email' => 'test', |
||
| 466 | 'name' => '[email protected]', |
||
| 467 | 'address' => 'test address', |
||
| 468 | ], |
||
| 469 | ], $record); |
||
| 470 | } |
||
| 471 | |||
| 472 | /** |
||
| 473 | * Test INSERT INTO ... SELECT SQL statement with alias syntax. |
||
| 474 | */ |
||
| 475 | public function testInsertSelectAlias(): void |
||
| 476 | { |
||
| 477 | $db = $this->getConnection(); |
||
| 478 | |||
| 479 | $db->createCommand('DELETE FROM {{customer}}')->execute(); |
||
| 480 | |||
| 481 | $command = $db->createCommand(); |
||
| 482 | |||
| 483 | $command->insert( |
||
| 484 | '{{customer}}', |
||
| 485 | [ |
||
| 486 | 'email' => '[email protected]', |
||
| 487 | 'name' => 'test', |
||
| 488 | 'address' => 'test address', |
||
| 489 | ] |
||
| 490 | )->execute(); |
||
| 491 | |||
| 492 | $query = new Query($db); |
||
| 493 | |||
| 494 | $query->select( |
||
| 495 | [ |
||
| 496 | 'email' => '{{customer}}.[[email]]', |
||
| 497 | 'address' => 'name', |
||
| 498 | 'name' => 'address', |
||
| 499 | ] |
||
| 500 | ) |
||
| 501 | ->from('{{customer}}') |
||
| 502 | ->where([ |
||
| 503 | 'and', |
||
| 504 | ['<>', 'name', 'foo'], |
||
| 505 | ['status' => [0, 1, 2, 3]], |
||
| 506 | ]); |
||
| 507 | |||
| 508 | $command = $db->createCommand(); |
||
| 509 | |||
| 510 | $command->insert( |
||
| 511 | '{{customer}}', |
||
| 512 | $query |
||
| 513 | )->execute(); |
||
| 514 | |||
| 515 | $this->assertEquals(2, $db->createCommand('SELECT COUNT(*) FROM {{customer}}')->queryScalar()); |
||
| 516 | |||
| 517 | $record = $db->createCommand('SELECT [[email]], [[name]], [[address]] FROM {{customer}}')->queryAll(); |
||
| 518 | |||
| 519 | $this->assertEquals([ |
||
| 520 | [ |
||
| 521 | 'email' => '[email protected]', |
||
| 522 | 'name' => 'test', |
||
| 523 | 'address' => 'test address', |
||
| 524 | ], |
||
| 525 | [ |
||
| 526 | 'email' => '[email protected]', |
||
| 527 | 'name' => 'test address', |
||
| 528 | 'address' => 'test', |
||
| 529 | ], |
||
| 530 | ], $record); |
||
| 531 | } |
||
| 532 | |||
| 533 | public function testInsertExpression(): void |
||
| 534 | { |
||
| 535 | $db = $this->getConnection(); |
||
| 536 | |||
| 537 | $db->createCommand('DELETE FROM {{order_with_null_fk}}')->execute(); |
||
| 538 | |||
| 539 | switch ($db->getDriverName()) { |
||
| 540 | case 'pgsql': |
||
| 541 | $expression = "EXTRACT(YEAR FROM TIMESTAMP 'now')"; |
||
| 542 | break; |
||
| 543 | case 'mysql': |
||
| 544 | $expression = 'YEAR(NOW())'; |
||
| 545 | break; |
||
| 546 | case 'sqlite': |
||
| 547 | $expression = "strftime('%Y')"; |
||
| 548 | break; |
||
| 549 | case 'sqlsrv': |
||
| 550 | $expression = 'YEAR(GETDATE())'; |
||
| 551 | } |
||
| 552 | |||
| 553 | $command = $db->createCommand(); |
||
| 554 | |||
| 555 | $command->insert( |
||
| 556 | '{{order_with_null_fk}}', |
||
| 557 | [ |
||
| 558 | 'created_at' => new Expression($expression), |
||
| 559 | 'total' => 1, |
||
| 560 | ] |
||
| 561 | )->execute(); |
||
| 562 | |||
| 563 | $this->assertEquals(1, $db->createCommand('SELECT COUNT(*) FROM {{order_with_null_fk}}')->queryScalar()); |
||
| 564 | |||
| 565 | $record = $db->createCommand('SELECT [[created_at]] FROM {{order_with_null_fk}}')->queryOne(); |
||
| 566 | |||
| 567 | $this->assertEquals([ |
||
| 568 | 'created_at' => date('Y'), |
||
| 569 | ], $record); |
||
| 570 | } |
||
| 571 | |||
| 572 | public function testsInsertQueryAsColumnValue(): void |
||
| 618 | } |
||
| 619 | |||
| 620 | public function testCreateTable(): void |
||
| 621 | { |
||
| 622 | $db = $this->getConnection(); |
||
| 623 | |||
| 624 | if ($db->getSchema()->getTableSchema('testCreateTable') !== null) { |
||
| 625 | $db->createCommand()->dropTable('testCreateTable')->execute(); |
||
| 626 | } |
||
| 627 | |||
| 628 | $db->createCommand()->createTable( |
||
| 629 | 'testCreateTable', |
||
| 630 | ['id' => Schema::TYPE_PK, 'bar' => Schema::TYPE_INTEGER] |
||
| 631 | )->execute(); |
||
| 632 | |||
| 633 | $db->createCommand()->insert('testCreateTable', ['bar' => 1])->execute(); |
||
| 634 | |||
| 635 | $records = $db->createCommand('SELECT [[id]], [[bar]] FROM {{testCreateTable}};')->queryAll(); |
||
| 636 | |||
| 637 | $this->assertEquals([ |
||
| 638 | ['id' => 1, 'bar' => 1], |
||
| 639 | ], $records); |
||
| 640 | } |
||
| 641 | |||
| 642 | public function testDropTable(): void |
||
| 643 | { |
||
| 644 | $db = $this->getConnection(); |
||
| 645 | |||
| 646 | $tableName = 'type'; |
||
| 647 | |||
| 648 | $this->assertNotNull($db->getSchema()->getTableSchema($tableName)); |
||
| 649 | |||
| 650 | $db->createCommand()->dropTable($tableName)->execute(); |
||
| 651 | |||
| 652 | $this->assertNull($db->getSchema()->getTableSchema($tableName)); |
||
| 653 | } |
||
| 654 | |||
| 655 | public function testTruncateTable(): void |
||
| 656 | { |
||
| 657 | $db = $this->getConnection(); |
||
| 658 | |||
| 659 | $rows = $db->createCommand('SELECT * FROM {{animal}}')->queryAll(); |
||
| 660 | |||
| 661 | $this->assertCount(2, $rows); |
||
| 662 | |||
| 663 | $db->createCommand()->truncateTable('animal')->execute(); |
||
| 664 | |||
| 665 | $rows = $db->createCommand('SELECT * FROM {{animal}}')->queryAll(); |
||
| 666 | |||
| 667 | $this->assertCount(0, $rows); |
||
| 668 | } |
||
| 669 | |||
| 670 | public function testRenameTable(): void |
||
| 688 | } |
||
| 689 | |||
| 690 | protected function performAndCompareUpsertResult(ConnectionInterface $db, array $data): void |
||
| 691 | { |
||
| 692 | $params = $data['params']; |
||
| 693 | $expected = $data['expected'] ?? $params[1]; |
||
| 694 | |||
| 711 | } |
||
| 712 | |||
| 713 | public function testAddDropForeignKey(): void |
||
| 714 | { |
||
| 715 | $db = $this->getConnection(); |
||
| 716 | |||
| 717 | $tableName = 'test_fk'; |
||
| 718 | $name = 'test_fk_constraint'; |
||
| 719 | |||
| 720 | $schema = $db->getSchema(); |
||
| 721 | |||
| 722 | if ($schema->getTableSchema($tableName) !== null) { |
||
| 723 | $db->createCommand()->dropTable($tableName)->execute(); |
||
| 724 | } |
||
| 725 | |||
| 726 | $db->createCommand()->createTable($tableName, [ |
||
| 727 | 'int1' => 'integer not null unique', |
||
| 728 | 'int2' => 'integer not null unique', |
||
| 729 | 'int3' => 'integer not null unique', |
||
| 730 | 'int4' => 'integer not null unique', |
||
| 731 | 'unique ([[int1]], [[int2]])', |
||
| 732 | 'unique ([[int3]], [[int4]])', |
||
| 733 | ])->execute(); |
||
| 734 | |||
| 735 | $this->assertEmpty($schema->getTableForeignKeys($tableName, true)); |
||
| 736 | |||
| 737 | $db->createCommand()->addForeignKey($name, $tableName, ['int1'], $tableName, ['int3'])->execute(); |
||
| 738 | |||
| 739 | $this->assertEquals(['int1'], $schema->getTableForeignKeys($tableName, true)[0]->getColumnNames()); |
||
| 740 | $this->assertEquals(['int3'], $schema->getTableForeignKeys($tableName, true)[0]->getForeignColumnNames()); |
||
| 741 | |||
| 742 | $db->createCommand()->dropForeignKey($name, $tableName)->execute(); |
||
| 743 | |||
| 744 | $this->assertEmpty($schema->getTableForeignKeys($tableName, true)); |
||
| 745 | |||
| 746 | $db->createCommand()->addForeignKey( |
||
| 747 | $name, |
||
| 748 | $tableName, |
||
| 749 | ['int1', 'int2'], |
||
| 750 | $tableName, |
||
| 751 | ['int3', 'int4'] |
||
| 752 | )->execute(); |
||
| 753 | |||
| 754 | $this->assertEquals( |
||
| 755 | ['int1', 'int2'], |
||
| 756 | $schema->getTableForeignKeys($tableName, true)[0]->getColumnNames() |
||
| 757 | ); |
||
| 758 | $this->assertEquals( |
||
| 759 | ['int3', 'int4'], |
||
| 760 | $schema->getTableForeignKeys($tableName, true)[0]->getForeignColumnNames() |
||
| 761 | ); |
||
| 762 | } |
||
| 763 | |||
| 764 | public function testCreateDropIndex(): void |
||
| 765 | { |
||
| 766 | $db = $this->getConnection(); |
||
| 767 | |||
| 768 | $tableName = 'test_idx'; |
||
| 769 | $name = 'test_idx_constraint'; |
||
| 770 | |||
| 771 | $schema = $db->getSchema(); |
||
| 772 | |||
| 773 | if ($schema->getTableSchema($tableName) !== null) { |
||
| 774 | $db->createCommand()->dropTable($tableName)->execute(); |
||
| 775 | } |
||
| 776 | |||
| 777 | $db->createCommand()->createTable($tableName, [ |
||
| 778 | 'int1' => 'integer not null', |
||
| 779 | 'int2' => 'integer not null', |
||
| 780 | ])->execute(); |
||
| 781 | |||
| 782 | $this->assertEmpty($schema->getTableIndexes($tableName, true)); |
||
| 783 | |||
| 784 | $db->createCommand()->createIndex($name, $tableName, ['int1'])->execute(); |
||
| 785 | |||
| 786 | $this->assertEquals(['int1'], $schema->getTableIndexes($tableName, true)[0]->getColumnNames()); |
||
| 787 | $this->assertFalse($schema->getTableIndexes($tableName, true)[0]->isUnique()); |
||
| 788 | |||
| 789 | $db->createCommand()->dropIndex($name, $tableName)->execute(); |
||
| 790 | |||
| 791 | $this->assertEmpty($schema->getTableIndexes($tableName, true)); |
||
| 792 | |||
| 793 | $db->createCommand()->createIndex($name, $tableName, ['int1', 'int2'])->execute(); |
||
| 794 | |||
| 795 | $this->assertEquals(['int1', 'int2'], $schema->getTableIndexes($tableName, true)[0]->getColumnNames()); |
||
| 796 | $this->assertFalse($schema->getTableIndexes($tableName, true)[0]->isUnique()); |
||
| 797 | |||
| 798 | $db->createCommand()->dropIndex($name, $tableName)->execute(); |
||
| 799 | |||
| 800 | $this->assertEmpty($schema->getTableIndexes($tableName, true)); |
||
| 801 | $this->assertEmpty($schema->getTableIndexes($tableName, true)); |
||
| 802 | |||
| 803 | $db->createCommand()->createIndex($name, $tableName, ['int1'], true)->execute(); |
||
| 804 | |||
| 805 | $this->assertEquals(['int1'], $schema->getTableIndexes($tableName, true)[0]->getColumnNames()); |
||
| 806 | $this->assertTrue($schema->getTableIndexes($tableName, true)[0]->isUnique()); |
||
| 807 | |||
| 808 | $db->createCommand()->dropIndex($name, $tableName)->execute(); |
||
| 809 | |||
| 810 | $this->assertEmpty($schema->getTableIndexes($tableName, true)); |
||
| 811 | |||
| 812 | $db->createCommand()->createIndex($name, $tableName, ['int1', 'int2'], true)->execute(); |
||
| 813 | |||
| 814 | $this->assertEquals(['int1', 'int2'], $schema->getTableIndexes($tableName, true)[0]->getColumnNames()); |
||
| 815 | $this->assertTrue($schema->getTableIndexes($tableName, true)[0]->isUnique()); |
||
| 816 | } |
||
| 817 | |||
| 818 | public function testAddDropUnique(): void |
||
| 819 | { |
||
| 820 | $db = $this->getConnection(); |
||
| 821 | |||
| 822 | $tableName = 'test_uq'; |
||
| 823 | $name = 'test_uq_constraint'; |
||
| 824 | |||
| 825 | $schema = $db->getSchema(); |
||
| 826 | |||
| 827 | if ($schema->getTableSchema($tableName) !== null) { |
||
| 828 | $db->createCommand()->dropTable($tableName)->execute(); |
||
| 829 | } |
||
| 830 | |||
| 831 | $db->createCommand()->createTable($tableName, [ |
||
| 832 | 'int1' => 'integer not null', |
||
| 833 | 'int2' => 'integer not null', |
||
| 834 | ])->execute(); |
||
| 835 | |||
| 836 | $this->assertEmpty($schema->getTableUniques($tableName, true)); |
||
| 837 | |||
| 838 | $db->createCommand()->addUnique($name, $tableName, ['int1'])->execute(); |
||
| 839 | |||
| 840 | $this->assertEquals(['int1'], $schema->getTableUniques($tableName, true)[0]->getColumnNames()); |
||
| 841 | |||
| 842 | $db->createCommand()->dropUnique($name, $tableName)->execute(); |
||
| 843 | |||
| 844 | $this->assertEmpty($schema->getTableUniques($tableName, true)); |
||
| 845 | |||
| 846 | $db->createCommand()->addUnique($name, $tableName, ['int1', 'int2'])->execute(); |
||
| 847 | |||
| 848 | $this->assertEquals(['int1', 'int2'], $schema->getTableUniques($tableName, true)[0]->getColumnNames()); |
||
| 849 | } |
||
| 850 | |||
| 851 | public function testIntegrityViolation(): void |
||
| 852 | { |
||
| 853 | $this->expectException(IntegrityException::class); |
||
| 854 | |||
| 855 | $db = $this->getConnection(); |
||
| 856 | |||
| 857 | $sql = 'INSERT INTO {{profile}}([[id]], [[description]]) VALUES (123, \'duplicate\')'; |
||
| 858 | |||
| 859 | $command = $db->createCommand($sql); |
||
| 860 | |||
| 861 | $command->execute(); |
||
| 862 | $command->execute(); |
||
| 863 | } |
||
| 864 | |||
| 865 | public function testLastInsertId(): void |
||
| 866 | { |
||
| 867 | $db = $this->getConnection(true); |
||
| 868 | |||
| 869 | $sql = 'INSERT INTO {{profile}}([[description]]) VALUES (\'non duplicate\')'; |
||
| 870 | |||
| 871 | $command = $db->createCommand($sql); |
||
| 872 | |||
| 873 | $command->execute(); |
||
| 874 | |||
| 875 | $this->assertEquals(3, $db->getSchema()->getLastInsertID()); |
||
| 876 | } |
||
| 877 | |||
| 878 | public function testQueryCache(): void |
||
| 879 | { |
||
| 880 | $db = $this->getConnection(); |
||
| 881 | |||
| 882 | $db->setEnableQueryCache(true); |
||
| 883 | $db->setQueryCache($this->cache); |
||
| 884 | |||
| 885 | $command = $db->createCommand('SELECT [[name]] FROM {{customer}} WHERE [[id]] = :id'); |
||
| 886 | |||
| 887 | $this->assertEquals('user1', $command->bindValue(':id', 1)->queryScalar()); |
||
| 888 | |||
| 889 | $update = $db->createCommand('UPDATE {{customer}} SET [[name]] = :name WHERE [[id]] = :id'); |
||
| 890 | |||
| 891 | $update->bindValues([':id' => 1, ':name' => 'user11'])->execute(); |
||
| 892 | |||
| 893 | $this->assertEquals('user11', $command->bindValue(':id', 1)->queryScalar()); |
||
| 894 | |||
| 895 | $db->cache(function (ConnectionInterface $db) use ($command, $update) { |
||
| 896 | $this->assertEquals('user2', $command->bindValue(':id', 2)->queryScalar()); |
||
| 897 | |||
| 898 | $update->bindValues([':id' => 2, ':name' => 'user22'])->execute(); |
||
| 899 | |||
| 900 | $this->assertEquals('user2', $command->bindValue(':id', 2)->queryScalar()); |
||
| 901 | |||
| 902 | $db->noCache(function () use ($command) { |
||
| 903 | $this->assertEquals('user22', $command->bindValue(':id', 2)->queryScalar()); |
||
| 904 | }); |
||
| 905 | |||
| 906 | $this->assertEquals('user2', $command->bindValue(':id', 2)->queryScalar()); |
||
| 907 | }, 10); |
||
| 908 | |||
| 909 | $db->setEnableQueryCache(false); |
||
| 910 | |||
| 911 | $db->cache(function () use ($command, $update) { |
||
| 912 | $this->assertEquals('user22', $command->bindValue(':id', 2)->queryScalar()); |
||
| 913 | $update->bindValues([':id' => 2, ':name' => 'user2'])->execute(); |
||
| 914 | $this->assertEquals('user2', $command->bindValue(':id', 2)->queryScalar()); |
||
| 915 | }, 10); |
||
| 916 | |||
| 917 | $db->setEnableQueryCache(true); |
||
| 918 | |||
| 919 | $command = $db->createCommand('SELECT [[name]] FROM {{customer}} WHERE [[id]] = :id')->cache(); |
||
| 920 | |||
| 921 | $this->assertEquals('user11', $command->bindValue(':id', 1)->queryScalar()); |
||
| 922 | |||
| 923 | $update->bindValues([':id' => 1, ':name' => 'user1'])->execute(); |
||
| 924 | |||
| 925 | $this->assertEquals('user11', $command->bindValue(':id', 1)->queryScalar()); |
||
| 926 | $this->assertEquals('user1', $command->noCache()->bindValue(':id', 1)->queryScalar()); |
||
| 927 | |||
| 928 | $command = $db->createCommand('SELECT [[name]] FROM {{customer}} WHERE [[id]] = :id'); |
||
| 929 | |||
| 930 | $db->cache(function () use ($command) { |
||
| 931 | $this->assertEquals('user11', $command->bindValue(':id', 1)->queryScalar()); |
||
| 932 | $this->assertEquals('user1', $command->noCache()->bindValue(':id', 1)->queryScalar()); |
||
| 933 | }, 10); |
||
| 934 | } |
||
| 935 | |||
| 936 | public function testColumnCase(): void |
||
| 937 | { |
||
| 938 | $db = $this->getConnection(); |
||
| 939 | |||
| 940 | $this->assertEquals(PDO::CASE_NATURAL, $db->getSlavePdo()->getAttribute(PDO::ATTR_CASE)); |
||
| 941 | |||
| 942 | $sql = 'SELECT [[customer_id]], [[total]] FROM {{order}}'; |
||
| 943 | |||
| 944 | $rows = $db->createCommand($sql)->queryAll(); |
||
| 945 | |||
| 946 | $this->assertTrue(isset($rows[0])); |
||
| 947 | $this->assertTrue(isset($rows[0]['customer_id'])); |
||
| 948 | $this->assertTrue(isset($rows[0]['total'])); |
||
| 949 | |||
| 950 | $db->getSlavePdo()->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); |
||
| 951 | |||
| 952 | $rows = $db->createCommand($sql)->queryAll(); |
||
| 953 | |||
| 954 | $this->assertTrue(isset($rows[0])); |
||
| 955 | $this->assertTrue(isset($rows[0]['customer_id'])); |
||
| 956 | $this->assertTrue(isset($rows[0]['total'])); |
||
| 957 | |||
| 958 | $db->getSlavePdo()->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER); |
||
| 959 | |||
| 960 | $rows = $db->createCommand($sql)->queryAll(); |
||
| 961 | |||
| 962 | $this->assertTrue(isset($rows[0])); |
||
| 963 | $this->assertTrue(isset($rows[0]['CUSTOMER_ID'])); |
||
| 964 | $this->assertTrue(isset($rows[0]['TOTAL'])); |
||
| 965 | } |
||
| 966 | |||
| 967 | public function testTransaction(): void |
||
| 968 | { |
||
| 969 | $db = $this->getConnection(); |
||
| 970 | |||
| 971 | $this->assertNull($db->getTransaction()); |
||
| 972 | |||
| 973 | $command = $db->createCommand("INSERT INTO {{profile}}([[description]]) VALUES('command transaction')"); |
||
| 974 | |||
| 975 | $this->invokeMethod($command, 'requireTransaction'); |
||
| 976 | |||
| 977 | $command->execute(); |
||
| 978 | |||
| 979 | $this->assertNull($db->getTransaction()); |
||
| 980 | $this->assertEquals( |
||
| 981 | 1, |
||
| 982 | $db->createCommand( |
||
| 983 | "SELECT COUNT(*) FROM {{profile}} WHERE [[description]] = 'command transaction'" |
||
| 984 | )->queryScalar() |
||
| 985 | ); |
||
| 986 | } |
||
| 987 | |||
| 988 | public function testRetryHandler(): void |
||
| 989 | { |
||
| 990 | $db = $this->getConnection(); |
||
| 991 | |||
| 992 | $this->assertNull($db->getTransaction()); |
||
| 993 | |||
| 994 | $db->createCommand("INSERT INTO {{profile}}([[description]]) VALUES('command retry')")->execute(); |
||
| 995 | |||
| 996 | $this->assertNull($db->getTransaction()); |
||
| 997 | $this->assertEquals( |
||
| 998 | 1, |
||
| 999 | $db->createCommand( |
||
| 1000 | "SELECT COUNT(*) FROM {{profile}} WHERE [[description]] = 'command retry'" |
||
| 1001 | )->queryScalar() |
||
| 1002 | ); |
||
| 1003 | |||
| 1004 | $attempts = null; |
||
| 1005 | $hitHandler = false; |
||
| 1006 | $hitCatch = false; |
||
| 1007 | |||
| 1008 | $command = $db->createCommand( |
||
| 1009 | "INSERT INTO {{profile}}([[id]], [[description]]) VALUES(1, 'command retry')" |
||
| 1010 | ); |
||
| 1011 | |||
| 1012 | $this->invokeMethod( |
||
| 1013 | $command, |
||
| 1014 | 'setRetryHandler', |
||
| 1015 | [static function ($exception, $attempt) use (&$attempts, &$hitHandler) { |
||
| 1016 | $attempts = $attempt; |
||
| 1017 | $hitHandler = true; |
||
| 1018 | |||
| 1019 | return $attempt <= 2; |
||
| 1020 | }] |
||
| 1021 | ); |
||
| 1022 | |||
| 1023 | try { |
||
| 1024 | $command->execute(); |
||
| 1025 | } catch (Exception $e) { |
||
| 1026 | $hitCatch = true; |
||
| 1027 | $this->assertInstanceOf(IntegrityException::class, $e); |
||
| 1028 | } |
||
| 1029 | |||
| 1030 | $this->assertNull($db->getTransaction()); |
||
| 1031 | $this->assertSame(3, $attempts); |
||
| 1032 | $this->assertTrue($hitHandler); |
||
| 1033 | $this->assertTrue($hitCatch); |
||
| 1034 | } |
||
| 1035 | |||
| 1036 | public function testCreateView(): void |
||
| 1037 | { |
||
| 1038 | $db = $this->getConnection(); |
||
| 1039 | |||
| 1040 | $subquery = (new Query($db)) |
||
| 1041 | ->select('bar') |
||
| 1042 | ->from('testCreateViewTable') |
||
| 1043 | ->where(['>', 'bar', '5']); |
||
| 1044 | |||
| 1045 | if ($db->getSchema()->getTableSchema('testCreateView') !== null) { |
||
| 1046 | $db->createCommand()->dropView('testCreateView')->execute(); |
||
| 1047 | } |
||
| 1048 | |||
| 1049 | if ($db->getSchema()->getTableSchema('testCreateViewTable')) { |
||
| 1050 | $db->createCommand()->dropTable('testCreateViewTable')->execute(); |
||
| 1051 | } |
||
| 1052 | |||
| 1053 | $db->createCommand()->createTable('testCreateViewTable', [ |
||
| 1054 | 'id' => Schema::TYPE_PK, |
||
| 1055 | 'bar' => Schema::TYPE_INTEGER, |
||
| 1056 | ])->execute(); |
||
| 1057 | |||
| 1058 | $db->createCommand()->insert('testCreateViewTable', ['bar' => 1])->execute(); |
||
| 1059 | $db->createCommand()->insert('testCreateViewTable', ['bar' => 6])->execute(); |
||
| 1060 | $db->createCommand()->createView('testCreateView', $subquery)->execute(); |
||
| 1061 | |||
| 1062 | $records = $db->createCommand('SELECT [[bar]] FROM {{testCreateView}};')->queryAll(); |
||
| 1063 | |||
| 1064 | $this->assertEquals([['bar' => 6]], $records); |
||
| 1065 | } |
||
| 1066 | |||
| 1067 | public function testDropView(): void |
||
| 1068 | { |
||
| 1069 | $db = $this->getConnection(); |
||
| 1070 | |||
| 1071 | /* since it already exists in the fixtures */ |
||
| 1072 | $viewName = 'animal_view'; |
||
| 1073 | |||
| 1074 | $this->assertNotNull($db->getSchema()->getTableSchema($viewName)); |
||
| 1075 | |||
| 1076 | $db->createCommand()->dropView($viewName)->execute(); |
||
| 1077 | |||
| 1078 | $this->assertNull($db->getSchema()->getTableSchema($viewName)); |
||
| 1079 | } |
||
| 1080 | |||
| 1081 | public function batchInsertSqlProviderTrait(): array |
||
| 1082 | { |
||
| 1083 | return [ |
||
| 1084 | 'issue11242' => [ |
||
| 1085 | 'type', |
||
| 1086 | ['int_col', 'float_col', 'char_col'], |
||
| 1087 | [['', '', 'Kyiv {{city}}, Ukraine']], |
||
| 1088 | /** |
||
| 1089 | * {@see https://github.com/yiisoft/yii2/issues/11242} |
||
| 1090 | * |
||
| 1091 | * Make sure curly bracelets (`{{..}}`) in values will not be escaped |
||
| 1092 | */ |
||
| 1093 | 'expected' => "INSERT INTO `type` (`int_col`, `float_col`, `char_col`)" |
||
| 1094 | . " VALUES (NULL, NULL, 'Kyiv {{city}}, Ukraine')" |
||
| 1095 | ], |
||
| 1096 | 'wrongBehavior' => [ |
||
| 1097 | '{{%type}}', |
||
| 1098 | ['{{%type}}.[[int_col]]', '[[float_col]]', 'char_col'], |
||
| 1099 | [['', '', 'Kyiv {{city}}, Ukraine']], |
||
| 1100 | /** |
||
| 1101 | * Test covers potentially wrong behavior and marks it as expected!. |
||
| 1102 | * |
||
| 1103 | * In case table name or table column is passed with curly or square bracelets, QueryBuilder can not |
||
| 1104 | * determine the table schema and typecast values properly. |
||
| 1105 | * TODO: make it work. Impossible without BC breaking for public methods. |
||
| 1106 | */ |
||
| 1107 | 'expected' => "INSERT INTO `type` (`type`.`int_col`, `float_col`, `char_col`)" |
||
| 1108 | . " VALUES ('', '', 'Kyiv {{city}}, Ukraine')" |
||
| 1109 | ], |
||
| 1110 | 'batchInsert binds params from expression' => [ |
||
| 1111 | '{{%type}}', |
||
| 1112 | ['int_col'], |
||
| 1113 | /** |
||
| 1114 | * This example is completely useless. This feature of batchInsert is intended to be used with complex |
||
| 1115 | * expression objects, such as JsonExpression. |
||
| 1116 | */ |
||
| 1117 | [[new Expression(':qp1', [':qp1' => 42])]], |
||
| 1118 | 'expected' => 'INSERT INTO `type` (`int_col`) VALUES (:qp1)', |
||
| 1119 | 'expectedParams' => [':qp1' => 42] |
||
| 1120 | ], |
||
| 1121 | ]; |
||
| 1122 | } |
||
| 1123 | |||
| 1124 | public function bindParamsNonWhereProviderTrait(): array |
||
| 1125 | { |
||
| 1126 | return [ |
||
| 1127 | ['SELECT SUBSTR(name, :len) FROM {{customer}} WHERE [[email]] = :email GROUP BY SUBSTR(name, :len)'], |
||
| 1128 | ['SELECT SUBSTR(name, :len) FROM {{customer}} WHERE [[email]] = :email ORDER BY SUBSTR(name, :len)'], |
||
| 1129 | ['SELECT SUBSTR(name, :len) FROM {{customer}} WHERE [[email]] = :email'] |
||
| 1130 | ]; |
||
| 1131 | } |
||
| 1132 | |||
| 1133 | public function getRawSqlProviderTrait(): array |
||
| 1174 | ], |
||
| 1175 | ]; |
||
| 1176 | } |
||
| 1177 | |||
| 1178 | public function invalidSelectColumnsProviderTrait(): array |
||
| 1184 | ]; |
||
| 1185 | } |
||
| 1186 | |||
| 1187 | public function upsertProviderTrait(): array |
||
| 1403 | ], |
||
| 1404 | ], |
||
| 1405 | ], |
||
| 1406 | ]; |
||
| 1407 | } |
||
| 1408 | } |
||
| 1409 |