Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / tests / Doctrine / Tests / DBAL / Functional / TemporaryTableTest.php
1 <?php
2
3 namespace Doctrine\Tests\DBAL\Functional;
4
5 use \Doctrine\DBAL\Schema\Table;
6 use \Doctrine\DBAL\Schema\Column;
7 use \Doctrine\DBAL\Types\Type;
8
9 class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase
10 {
11     public function setUp()
12     {
13         parent::setUp();
14         try {
15             $this->_conn->exec($this->_conn->getDatabasePlatform()->getDropTableSQL("nontemporary"));
16         } catch(\Exception $e) {
17
18         }
19     }
20
21     public function tearDown()
22     {
23         if ($this->_conn) {
24             try {
25                 $tempTable = $this->_conn->getDatabasePlatform()->getTemporaryTableName("temporary");
26                 $this->_conn->exec($this->_conn->getDatabasePlatform()->getDropTemporaryTableSQL($tempTable));
27             } catch(\Exception $e) { }
28         }
29     }
30
31     /**
32      * @group DDC-1337
33      * @return void
34      */
35     public function testDropTemporaryTableNotAutoCommitTransaction()
36     {
37         $platform = $this->_conn->getDatabasePlatform();
38         $columnDefinitions = array("id" => array("type" => Type::getType("integer"), "notnull" => true));
39         $tempTable = $platform->getTemporaryTableName("temporary");
40
41         $createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' ('
42                 . $platform->getColumnDeclarationListSQL($columnDefinitions) . ')';
43         $this->_conn->executeUpdate($createTempTableSQL);
44
45         $table = new Table("nontemporary");
46         $table->addColumn("id", "integer");
47         $table->setPrimaryKey(array('id'));
48
49         foreach ($platform->getCreateTableSQL($table) AS $sql) {
50             $this->_conn->executeQuery($sql);
51         }
52
53         $this->_conn->beginTransaction();
54         $this->_conn->insert("nontemporary", array("id" => 1));
55         $this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable));
56         $this->_conn->insert("nontemporary", array("id" => 2));
57
58         $this->_conn->rollback();
59
60         $rows = $this->_conn->fetchAll('SELECT * FROM nontemporary');
61         $this->assertEquals(array(), $rows, "In an event of an error this result has one row, because of an implicit commit.");
62     }
63
64     /**
65      * @group DDC-1337
66      * @return void
67      */
68     public function testCreateTemporaryTableNotAutoCommitTransaction()
69     {
70         $platform = $this->_conn->getDatabasePlatform();
71         $columnDefinitions = array("id" => array("type" => Type::getType("integer"), "notnull" => true));
72         $tempTable = $platform->getTemporaryTableName("temporary");
73
74         $createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' ('
75                 . $platform->getColumnDeclarationListSQL($columnDefinitions) . ')';
76
77         $table = new Table("nontemporary");
78         $table->addColumn("id", "integer");
79         $table->setPrimaryKey(array('id'));
80
81         foreach ($platform->getCreateTableSQL($table) AS $sql) {
82             $this->_conn->executeQuery($sql);
83         }
84
85         $this->_conn->beginTransaction();
86         $this->_conn->insert("nontemporary", array("id" => 1));
87
88         $this->_conn->exec($createTempTableSQL);
89         $this->_conn->insert("nontemporary", array("id" => 2));
90
91         $this->_conn->rollback();
92
93         try {
94             $this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable));
95         } catch(\Exception $e) {
96
97         }
98
99         $rows = $this->_conn->fetchAll('SELECT * FROM nontemporary');
100         $this->assertEquals(array(), $rows, "In an event of an error this result has one row, because of an implicit commit.");
101     }
102 }