doctrine /
dbal
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Tests\Functional; |
||
| 6 | |||
| 7 | use Doctrine\DBAL\Schema\Table; |
||
| 8 | use Doctrine\DBAL\Tests\FunctionalTestCase; |
||
| 9 | use Doctrine\DBAL\Types\Type; |
||
| 10 | use Throwable; |
||
| 11 | |||
| 12 | class TemporaryTableTest extends FunctionalTestCase |
||
| 13 | { |
||
| 14 | protected function setUp() : void |
||
| 15 | { |
||
| 16 | parent::setUp(); |
||
| 17 | try { |
||
| 18 | $this->connection->exec($this->connection->getDatabasePlatform()->getDropTableSQL('nontemporary')); |
||
| 19 | } catch (Throwable $e) { |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
Loading history...
|
|||
| 20 | } |
||
| 21 | } |
||
| 22 | |||
| 23 | protected function tearDown() : void |
||
| 24 | { |
||
| 25 | try { |
||
| 26 | $tempTable = $this->connection->getDatabasePlatform()->getTemporaryTableName('my_temporary'); |
||
| 27 | $this->connection->exec($this->connection->getDatabasePlatform()->getDropTemporaryTableSQL($tempTable)); |
||
| 28 | } catch (Throwable $e) { |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
|
|||
| 29 | } |
||
| 30 | |||
| 31 | parent::tearDown(); |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @group DDC-1337 |
||
| 36 | */ |
||
| 37 | public function testDropTemporaryTableNotAutoCommitTransaction() : void |
||
| 38 | { |
||
| 39 | if ($this->connection->getDatabasePlatform()->getName() === 'sqlanywhere' || |
||
| 40 | $this->connection->getDatabasePlatform()->getName() === 'oracle') { |
||
| 41 | self::markTestSkipped('Test does not work on Oracle and SQL Anywhere.'); |
||
| 42 | } |
||
| 43 | |||
| 44 | $platform = $this->connection->getDatabasePlatform(); |
||
| 45 | $columnDefinitions = [ |
||
| 46 | [ |
||
| 47 | 'name' => 'id', |
||
| 48 | 'type' => Type::getType('integer'), |
||
| 49 | 'notnull' => true, |
||
| 50 | ], |
||
| 51 | ]; |
||
| 52 | |||
| 53 | $tempTable = $platform->getTemporaryTableName('my_temporary'); |
||
| 54 | |||
| 55 | $createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' (' |
||
| 56 | . $platform->getColumnDeclarationListSQL($columnDefinitions) . ')'; |
||
| 57 | $this->connection->executeUpdate($createTempTableSQL); |
||
| 58 | |||
| 59 | $table = new Table('nontemporary'); |
||
| 60 | $table->addColumn('id', 'integer'); |
||
| 61 | $table->setPrimaryKey(['id']); |
||
| 62 | |||
| 63 | $this->connection->getSchemaManager()->createTable($table); |
||
| 64 | |||
| 65 | $this->connection->beginTransaction(); |
||
| 66 | $this->connection->insert('nontemporary', ['id' => 1]); |
||
| 67 | $this->connection->exec($platform->getDropTemporaryTableSQL($tempTable)); |
||
| 68 | $this->connection->insert('nontemporary', ['id' => 2]); |
||
| 69 | |||
| 70 | $this->connection->rollBack(); |
||
| 71 | |||
| 72 | $rows = $this->connection->fetchAll('SELECT * FROM nontemporary'); |
||
| 73 | self::assertEquals([], $rows, 'In an event of an error this result has one row, because of an implicit commit.'); |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @group DDC-1337 |
||
| 78 | */ |
||
| 79 | public function testCreateTemporaryTableNotAutoCommitTransaction() : void |
||
| 80 | { |
||
| 81 | if ($this->connection->getDatabasePlatform()->getName() === 'sqlanywhere' || |
||
| 82 | $this->connection->getDatabasePlatform()->getName() === 'oracle') { |
||
| 83 | self::markTestSkipped('Test does not work on Oracle and SQL Anywhere.'); |
||
| 84 | } |
||
| 85 | |||
| 86 | $platform = $this->connection->getDatabasePlatform(); |
||
| 87 | $columnDefinitions = [ |
||
| 88 | [ |
||
| 89 | 'name' => 'id', |
||
| 90 | 'type' => Type::getType('integer'), |
||
| 91 | 'notnull' => true, |
||
| 92 | ], |
||
| 93 | ]; |
||
| 94 | |||
| 95 | $tempTable = $platform->getTemporaryTableName('my_temporary'); |
||
| 96 | |||
| 97 | $createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' (' |
||
| 98 | . $platform->getColumnDeclarationListSQL($columnDefinitions) . ')'; |
||
| 99 | |||
| 100 | $table = new Table('nontemporary'); |
||
| 101 | $table->addColumn('id', 'integer'); |
||
| 102 | $table->setPrimaryKey(['id']); |
||
| 103 | |||
| 104 | $this->connection->getSchemaManager()->createTable($table); |
||
| 105 | |||
| 106 | $this->connection->beginTransaction(); |
||
| 107 | $this->connection->insert('nontemporary', ['id' => 1]); |
||
| 108 | |||
| 109 | $this->connection->exec($createTempTableSQL); |
||
| 110 | $this->connection->insert('nontemporary', ['id' => 2]); |
||
| 111 | |||
| 112 | $this->connection->rollBack(); |
||
| 113 | |||
| 114 | try { |
||
| 115 | $this->connection->exec($platform->getDropTemporaryTableSQL($tempTable)); |
||
| 116 | } catch (Throwable $e) { |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
|
|||
| 117 | } |
||
| 118 | |||
| 119 | $rows = $this->connection->fetchAll('SELECT * FROM nontemporary'); |
||
| 120 | self::assertEquals([], $rows, 'In an event of an error this result has one row, because of an implicit commit.'); |
||
| 121 | } |
||
| 122 | } |
||
| 123 |