Commit 38d10b9e authored by Benjamin Eberlei's avatar Benjamin Eberlei

DDC-1337 - MySQL commits transaction on DROP TABLE, need DROP TEMPORARY TABLE....

DDC-1337 - MySQL commits transaction on DROP TABLE, need DROP TEMPORARY TABLE. Added tests, looks like oracle commits transactions on CREATE TEMPORARY TABLE. I dont know how to fix it.
parent aafe60e6
......@@ -276,7 +276,7 @@ class Connection implements DriverConnection
/**
* Gets the DBAL driver instance.
*
* @return Doctrine\DBAL\Driver
* @return \Doctrine\DBAL\Driver
*/
public function getDriver()
{
......@@ -286,7 +286,7 @@ class Connection implements DriverConnection
/**
* Gets the Configuration used by the Connection.
*
* @return Doctrine\DBAL\Configuration
* @return \Doctrine\DBAL\Configuration
*/
public function getConfiguration()
{
......@@ -296,7 +296,7 @@ class Connection implements DriverConnection
/**
* Gets the EventManager used by the Connection.
*
* @return Doctrine\Common\EventManager
* @return \Doctrine\Common\EventManager
*/
public function getEventManager()
{
......@@ -306,7 +306,7 @@ class Connection implements DriverConnection
/**
* Gets the DatabasePlatform for the connection.
*
* @return Doctrine\DBAL\Platforms\AbstractPlatform
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
*/
public function getDatabasePlatform()
{
......@@ -316,7 +316,7 @@ class Connection implements DriverConnection
/**
* Gets the ExpressionBuilder for the connection.
*
* @return Doctrine\DBAL\Query\ExpressionBuilder
* @return \Doctrine\DBAL\Query\ExpressionBuilder
*/
public function getExpressionBuilder()
{
......
......@@ -831,6 +831,7 @@ abstract class AbstractPlatform
/**
* Drop a Table
*
* @throws \InvalidArgumentException
* @param Table|string $table
* @return string
*/
......@@ -838,11 +839,24 @@ abstract class AbstractPlatform
{
if ($table instanceof \Doctrine\DBAL\Schema\Table) {
$table = $table->getQuotedName($this);
} else if(!is_string($table)) {
throw new \InvalidArgumentException('getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
}
return 'DROP TABLE ' . $table;
}
/**
* Get SQL to safely drop a temporary table WITHOUT implicitly committing an open transaction.
*
* @param Table|string $table
* @return string
*/
public function getDropTemporaryTableSQL($table)
{
return $this->getDropTableSQL($table);
}
/**
* Drop index from a table
*
......
......@@ -611,23 +611,6 @@ class MySqlPlatform extends AbstractPlatform
return 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY';
}
/**
* Gets the SQL to drop a table.
*
* @param string $table The name of table to drop.
* @override
*/
public function getDropTableSQL($table)
{
if ($table instanceof \Doctrine\DBAL\Schema\Table) {
$table = $table->getQuotedName($this);
} else if(!is_string($table)) {
throw new \InvalidArgumentException('MysqlPlatform::getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
}
return 'DROP TABLE ' . $table;
}
public function getSetTransactionIsolationSQL($level)
{
return 'SET SESSION TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSQL($level);
......@@ -686,4 +669,25 @@ class MySqlPlatform extends AbstractPlatform
{
return 'Doctrine\DBAL\Platforms\Keywords\MySQLKeywords';
}
/**
* Get SQL to safely drop a temporary table WITHOUT implicitly committing an open transaction.
*
* MySQL commits a transaction implicitly when DROP TABLE is executed, however not
* if DROP TEMPORARY TABLE is executed.
*
* @throws \InvalidArgumentException
* @param $table
* @return string
*/
public function getDropTemporaryTableSQL($table)
{
if ($table instanceof \Doctrine\DBAL\Schema\Table) {
$table = $table->getQuotedName($this);
} else if(!is_string($table)) {
throw new \InvalidArgumentException('getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
}
return 'DROP TEMPORARY TABLE ' . $table;
}
}
<?php
namespace Doctrine\Tests\DBAL\Functional;
use \Doctrine\DBAL\Schema\Table;
use \Doctrine\DBAL\Schema\Column;
use \Doctrine\DBAL\Types\Type;
class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
public function setUp()
{
parent::setUp();
try {
$this->_conn->exec($this->_conn->getDatabasePlatform()->getDropTableSQL("non_temporary"));
} catch(\Exception $e) {
}
}
/**
* @group DDC-1337
* @return void
*/
public function testDropTemporaryTableNotAbortsTransaction()
{
$platform = $this->_conn->getDatabasePlatform();
$columnDefinitions = array("id" => array("type" => Type::getType("integer"), "notnull" => true));
$tempTable = $platform->getTemporaryTableName("temporary");
$tempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' ('
. $platform->getColumnDeclarationListSQL($columnDefinitions) . ')';
$table = new Table("non_temporary");
$table->addColumn("id", "integer");
$this->_conn->getSchemaManager()->createTable($table);
$this->_conn->beginTransaction();
$this->_conn->insert("non_temporary", array("id" => 1));
$this->_conn->exec($tempTableSQL);
$this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable));
$this->_conn->insert("non_temporary", array("id" => 2));
$this->_conn->rollback();
$rows = $this->_conn->fetchAll('SELECT * FROM non_temporary');
$this->assertEquals(array(), $rows);
}
/**
* @group DDC-1337
* @return void
*/
public function testCreateTemporaryTableNotAbortsTransaction()
{
$platform = $this->_conn->getDatabasePlatform();
$columnDefinitions = array("id" => array("type" => Type::getType("integer"), "notnull" => true));
$tempTable = $platform->getTemporaryTableName("temporary");
$tempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' ('
. $platform->getColumnDeclarationListSQL($columnDefinitions) . ')';
$table = new Table("non_temporary");
$table->addColumn("id", "integer");
$this->_conn->getSchemaManager()->createTable($table);
$this->_conn->beginTransaction();
$this->_conn->insert("non_temporary", array("id" => 1));
$this->_conn->exec($tempTableSQL);
$this->_conn->insert("non_temporary", array("id" => 2));
$this->_conn->rollback();
try {
$this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable));
} catch(\Exception $e) {
}
$rows = $this->_conn->fetchAll('SELECT * FROM non_temporary');
$this->assertEquals(array(), $rows);
}
}
\ No newline at end of file
......@@ -7,12 +7,12 @@ class DbalFunctionalTestCase extends DbalTestCase
/**
* Shared connection when a TestCase is run alone (outside of it's functional suite)
*
* @var Doctrine\DBAL\Connection
* @var \Doctrine\DBAL\Connection
*/
private static $_sharedConn;
/**
* @var Doctrine\DBAL\Connection
* @var \Doctrine\DBAL\Connection
*/
protected $_conn;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment