3 namespace Doctrine\Tests\DBAL\Functional;
5 use \Doctrine\DBAL\Schema\Table;
6 use \Doctrine\DBAL\Schema\Column;
7 use \Doctrine\DBAL\Types\Type;
9 class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase
11 public function setUp()
15 $this->_conn->exec($this->_conn->getDatabasePlatform()->getDropTableSQL("nontemporary"));
16 } catch(\Exception $e) {
21 public function tearDown()
25 $tempTable = $this->_conn->getDatabasePlatform()->getTemporaryTableName("temporary");
26 $this->_conn->exec($this->_conn->getDatabasePlatform()->getDropTemporaryTableSQL($tempTable));
27 } catch(\Exception $e) { }
35 public function testDropTemporaryTableNotAutoCommitTransaction()
37 $platform = $this->_conn->getDatabasePlatform();
38 $columnDefinitions = array("id" => array("type" => Type::getType("integer"), "notnull" => true));
39 $tempTable = $platform->getTemporaryTableName("temporary");
41 $createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' ('
42 . $platform->getColumnDeclarationListSQL($columnDefinitions) . ')';
43 $this->_conn->executeUpdate($createTempTableSQL);
45 $table = new Table("nontemporary");
46 $table->addColumn("id", "integer");
47 $table->setPrimaryKey(array('id'));
49 foreach ($platform->getCreateTableSQL($table) AS $sql) {
50 $this->_conn->executeQuery($sql);
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));
58 $this->_conn->rollback();
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.");
68 public function testCreateTemporaryTableNotAutoCommitTransaction()
70 $platform = $this->_conn->getDatabasePlatform();
71 $columnDefinitions = array("id" => array("type" => Type::getType("integer"), "notnull" => true));
72 $tempTable = $platform->getTemporaryTableName("temporary");
74 $createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' ('
75 . $platform->getColumnDeclarationListSQL($columnDefinitions) . ')';
77 $table = new Table("nontemporary");
78 $table->addColumn("id", "integer");
79 $table->setPrimaryKey(array('id'));
81 foreach ($platform->getCreateTableSQL($table) AS $sql) {
82 $this->_conn->executeQuery($sql);
85 $this->_conn->beginTransaction();
86 $this->_conn->insert("nontemporary", array("id" => 1));
88 $this->_conn->exec($createTempTableSQL);
89 $this->_conn->insert("nontemporary", array("id" => 2));
91 $this->_conn->rollback();
94 $this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable));
95 } catch(\Exception $e) {
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.");