Commit dae94de9 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge branch 'DDC-1337' into 2.1.x

parents aafe60e6 38d10b9e
...@@ -276,7 +276,7 @@ class Connection implements DriverConnection ...@@ -276,7 +276,7 @@ class Connection implements DriverConnection
/** /**
* Gets the DBAL driver instance. * Gets the DBAL driver instance.
* *
* @return Doctrine\DBAL\Driver * @return \Doctrine\DBAL\Driver
*/ */
public function getDriver() public function getDriver()
{ {
...@@ -286,7 +286,7 @@ class Connection implements DriverConnection ...@@ -286,7 +286,7 @@ class Connection implements DriverConnection
/** /**
* Gets the Configuration used by the Connection. * Gets the Configuration used by the Connection.
* *
* @return Doctrine\DBAL\Configuration * @return \Doctrine\DBAL\Configuration
*/ */
public function getConfiguration() public function getConfiguration()
{ {
...@@ -296,7 +296,7 @@ class Connection implements DriverConnection ...@@ -296,7 +296,7 @@ class Connection implements DriverConnection
/** /**
* Gets the EventManager used by the Connection. * Gets the EventManager used by the Connection.
* *
* @return Doctrine\Common\EventManager * @return \Doctrine\Common\EventManager
*/ */
public function getEventManager() public function getEventManager()
{ {
...@@ -306,7 +306,7 @@ class Connection implements DriverConnection ...@@ -306,7 +306,7 @@ class Connection implements DriverConnection
/** /**
* Gets the DatabasePlatform for the connection. * Gets the DatabasePlatform for the connection.
* *
* @return Doctrine\DBAL\Platforms\AbstractPlatform * @return \Doctrine\DBAL\Platforms\AbstractPlatform
*/ */
public function getDatabasePlatform() public function getDatabasePlatform()
{ {
...@@ -316,7 +316,7 @@ class Connection implements DriverConnection ...@@ -316,7 +316,7 @@ class Connection implements DriverConnection
/** /**
* Gets the ExpressionBuilder for the connection. * Gets the ExpressionBuilder for the connection.
* *
* @return Doctrine\DBAL\Query\ExpressionBuilder * @return \Doctrine\DBAL\Query\ExpressionBuilder
*/ */
public function getExpressionBuilder() public function getExpressionBuilder()
{ {
......
...@@ -830,7 +830,8 @@ abstract class AbstractPlatform ...@@ -830,7 +830,8 @@ abstract class AbstractPlatform
/** /**
* Drop a Table * Drop a Table
* *
* @throws \InvalidArgumentException
* @param Table|string $table * @param Table|string $table
* @return string * @return string
*/ */
...@@ -838,11 +839,24 @@ abstract class AbstractPlatform ...@@ -838,11 +839,24 @@ abstract class AbstractPlatform
{ {
if ($table instanceof \Doctrine\DBAL\Schema\Table) { if ($table instanceof \Doctrine\DBAL\Schema\Table) {
$table = $table->getQuotedName($this); $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; 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 * Drop index from a table
* *
......
...@@ -610,23 +610,6 @@ class MySqlPlatform extends AbstractPlatform ...@@ -610,23 +610,6 @@ class MySqlPlatform extends AbstractPlatform
{ {
return 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY'; 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) public function getSetTransactionIsolationSQL($level)
{ {
...@@ -686,4 +669,25 @@ class MySqlPlatform extends AbstractPlatform ...@@ -686,4 +669,25 @@ class MySqlPlatform extends AbstractPlatform
{ {
return 'Doctrine\DBAL\Platforms\Keywords\MySQLKeywords'; 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 ...@@ -7,12 +7,12 @@ class DbalFunctionalTestCase extends DbalTestCase
/** /**
* Shared connection when a TestCase is run alone (outside of it's functional suite) * 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; private static $_sharedConn;
/** /**
* @var Doctrine\DBAL\Connection * @var \Doctrine\DBAL\Connection
*/ */
protected $_conn; 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