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