Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.1.x PgSql - Same problem with the master #46

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/OCI8/Driver.php
Expand Up @@ -47,7 +47,7 @@ public function connect(array $params, $username = null, $password = null, array
* *
* @return string The DSN. * @return string The DSN.
*/ */
protected function _constructDsn(array $params) private function _constructDsn(array $params)
{ {
$dsn = ''; $dsn = '';
if (isset($params['host'])) { if (isset($params['host'])) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php
Expand Up @@ -26,9 +26,9 @@
*/ */
class OCI8Connection implements \Doctrine\DBAL\Driver\Connection class OCI8Connection implements \Doctrine\DBAL\Driver\Connection
{ {
protected $_dbh; private $_dbh;


protected $_executeMode = OCI_COMMIT_ON_SUCCESS; private $_executeMode = OCI_COMMIT_ON_SUCCESS;


/** /**
* Create a Connection to an Oracle Database using oci8 extension. * Create a Connection to an Oracle Database using oci8 extension.
Expand Down
10 changes: 5 additions & 5 deletions lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
Expand Up @@ -30,15 +30,15 @@
class OCI8Statement implements \Doctrine\DBAL\Driver\Statement class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
{ {
/** Statement handle. */ /** Statement handle. */
protected $_sth; private $_sth;
protected $_executeMode; private $_executeMode;
protected static $_PARAM = ':param'; private static $_PARAM = ':param';
protected static $fetchStyleMap = array( private static $fetchStyleMap = array(
PDO::FETCH_BOTH => OCI_BOTH, PDO::FETCH_BOTH => OCI_BOTH,
PDO::FETCH_ASSOC => OCI_ASSOC, PDO::FETCH_ASSOC => OCI_ASSOC,
PDO::FETCH_NUM => OCI_NUM PDO::FETCH_NUM => OCI_NUM
); );
protected $_paramMap = array(); private $_paramMap = array();


/** /**
* Creates a new OCI8Statement that uses the given connection handle and SQL statement. * Creates a new OCI8Statement that uses the given connection handle and SQL statement.
Expand Down
8 changes: 2 additions & 6 deletions lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php
Expand Up @@ -71,7 +71,7 @@ private function _constructPdoDsn(array $params)
if (isset($params['charset'])) { if (isset($params['charset'])) {
$dsn .= 'charset=' . $params['charset'] . ';'; $dsn .= 'charset=' . $params['charset'] . ';';
} }

return $dsn; return $dsn;
} }


Expand All @@ -93,10 +93,6 @@ public function getName()
public function getDatabase(\Doctrine\DBAL\Connection $conn) public function getDatabase(\Doctrine\DBAL\Connection $conn)
{ {
$params = $conn->getParams(); $params = $conn->getParams();

return $params['dbname'];
if (isset($params['dbname'])) {
return $params['dbname'];
}
return $conn->query('SELECT DATABASE()')->fetchColumn();
} }
} }
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php
Expand Up @@ -37,7 +37,7 @@ private function _constructPdoDsn(array $params)
if (isset($params['host']) && $params['host'] != '') { if (isset($params['host']) && $params['host'] != '') {
$dsn .= 'host=' . $params['host'] . ' '; $dsn .= 'host=' . $params['host'] . ' ';
} }
if (isset($params['port'])) { if (isset($params['port']) && $params['port'] != '') {
$dsn .= 'port=' . $params['port'] . ' '; $dsn .= 'port=' . $params['port'] . ' ';
} }
if (isset($params['dbname'])) { if (isset($params['dbname'])) {
Expand Down
6 changes: 2 additions & 4 deletions lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
Expand Up @@ -607,14 +607,12 @@ protected function doModifyLimitQuery($query, $limit, $offset = null)


// Remove ORDER BY clause from $query // Remove ORDER BY clause from $query
$query = preg_replace('/\s+ORDER BY(.*)/', '', $query); $query = preg_replace('/\s+ORDER BY(.*)/', '', $query);

$query = preg_replace('/^SELECT\s/', '', $query);
// Add ORDER BY clause as an argument for ROW_NUMBER()
$query = "SELECT ROW_NUMBER() OVER ($over) AS \"doctrine_rownum\", * FROM ($query) AS inner_tbl";


$start = $offset + 1; $start = $offset + 1;
$end = $offset + $count; $end = $offset + $count;


$query = "WITH outer_tbl AS ($query) SELECT * FROM outer_tbl WHERE \"doctrine_rownum\" BETWEEN $start AND $end"; $query = "SELECT * FROM (SELECT ROW_NUMBER() OVER ($over) AS \"doctrine_rownum\", $query) AS doctrine_tbl WHERE \"doctrine_rownum\" BETWEEN $start AND $end";
} }
} }


Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
Expand Up @@ -108,22 +108,22 @@ public function getDateDiffExpression($date1, $date2)


public function getDateAddDaysExpression($date, $days) public function getDateAddDaysExpression($date, $days)
{ {
return 'DATE_ADD(' . $date . ', INTERVAL ' . (int)$days . ' DAY)'; return 'DATE_ADD(' . $date . ', INTERVAL ' . $days . ' DAY)';
} }


public function getDateSubDaysExpression($date, $days) public function getDateSubDaysExpression($date, $days)
{ {
return 'DATE_SUB(' . $date . ', INTERVAL ' . (int)$days . ' DAY)'; return 'DATE_SUB(' . $date . ', INTERVAL ' . $days . ' DAY)';
} }


public function getDateAddMonthExpression($date, $months) public function getDateAddMonthExpression($date, $months)
{ {
return 'DATE_ADD(' . $date . ', INTERVAL ' . (int)$months . ' MONTH)'; return 'DATE_ADD(' . $date . ', INTERVAL ' . $months . ' MONTH)';
} }


public function getDateSubMonthExpression($date, $months) public function getDateSubMonthExpression($date, $months)
{ {
return 'DATE_SUB(' . $date . ', INTERVAL ' . (int)$months . ' MONTH)'; return 'DATE_SUB(' . $date . ', INTERVAL ' . $months . ' MONTH)';
} }


public function getListDatabasesSQL() public function getListDatabasesSQL()
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/DBAL/Platforms/OraclePlatform.php
Expand Up @@ -118,22 +118,22 @@ public function getDateDiffExpression($date1, $date2)


public function getDateAddDaysExpression($date, $days) public function getDateAddDaysExpression($date, $days)
{ {
return '(' . $date . '+' . (int)$days . ')'; return '(' . $date . '+' . $days . ')';
} }


public function getDateSubDaysExpression($date, $days) public function getDateSubDaysExpression($date, $days)
{ {
return '(' . $date . '-' . (int)$days . ')'; return '(' . $date . '-' . $days . ')';
} }


public function getDateAddMonthExpression($date, $months) public function getDateAddMonthExpression($date, $months)
{ {
return "ADD_MONTHS(" . $date . ", " . (int)$months . ")"; return "ADD_MONTHS(" . $date . ", " . $months . ")";
} }


public function getDateSubMonthExpression($date, $months) public function getDateSubMonthExpression($date, $months)
{ {
return "ADD_MONTHS(" . $date . ", -" . (int)$months . ")"; return "ADD_MONTHS(" . $date . ", -" . $months . ")";
} }


/** /**
Expand Down
10 changes: 5 additions & 5 deletions lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
Expand Up @@ -94,27 +94,27 @@ public function getLocateExpression($str, $substr, $startPos = false)


public function getDateDiffExpression($date1, $date2) public function getDateDiffExpression($date1, $date2)
{ {
return '('.$date1 . '-'.$date2.')'; return '(DATE(' . $date1 . ')-DATE(' . $date2 . '))';
} }


public function getDateAddDaysExpression($date, $days) public function getDateAddDaysExpression($date, $days)
{ {
return "(" . $date . "+ interval '" . (int)$days . " day')"; return "(" . $date . "+ interval '" . $days . " day')";
} }


public function getDateSubDaysExpression($date, $days) public function getDateSubDaysExpression($date, $days)
{ {
return "(" . $date . "- interval '" . (int)$days . " day')"; return "(" . $date . "- interval '" . $days . " day')";
} }


public function getDateAddMonthExpression($date, $months) public function getDateAddMonthExpression($date, $months)
{ {
return "(" . $date . "+ interval '" . (int)$months . " month')"; return "(" . $date . "+ interval '" . $months . " month')";
} }


public function getDateSubMonthExpression($date, $months) public function getDateSubMonthExpression($date, $months)
{ {
return "(" . $date . "- interval '" . (int)$months . " month')"; return "(" . $date . "- interval '" . $months . " month')";
} }


/** /**
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
Expand Up @@ -132,22 +132,22 @@ public function getDateDiffExpression($date1, $date2)


public function getDateAddDaysExpression($date, $days) public function getDateAddDaysExpression($date, $days)
{ {
return "DATE(" . $date . ",'+". (int)$days . " day')"; return "DATE(" . $date . ",'+". $days . " day')";
} }


public function getDateSubDaysExpression($date, $days) public function getDateSubDaysExpression($date, $days)
{ {
return "DATE(" . $date . ",'-". (int)$days . " day')"; return "DATE(" . $date . ",'-". $days . " day')";
} }


public function getDateAddMonthExpression($date, $months) public function getDateAddMonthExpression($date, $months)
{ {
return "DATE(" . $date . ",'+". (int)$months . " month')"; return "DATE(" . $date . ",'+". $months . " month')";
} }


public function getDateSubMonthExpression($date, $months) public function getDateSubMonthExpression($date, $months)
{ {
return "DATE(" . $date . ",'-". (int)$months . " month')"; return "DATE(" . $date . ",'-". $months . " month')";
} }


protected function _getTransactionIsolationLevelSQL($level) protected function _getTransactionIsolationLevelSQL($level)
Expand Down
5 changes: 4 additions & 1 deletion lib/Doctrine/DBAL/Schema/Comparator.php
Expand Up @@ -325,7 +325,10 @@ public function diffColumn(Column $column1, Column $column2)
} }


if ($column1->getType() instanceof \Doctrine\DBAL\Types\StringType) { if ($column1->getType() instanceof \Doctrine\DBAL\Types\StringType) {
if ($column1->getLength() != $column2->getLength()) { // check if value of length is set at all, default value assumed otherwise.
$length1 = $column1->getLength() ?: 255;
$length2 = $column2->getLength() ?: 255;
if ($length1 != $length2) {
$changedProperties[] = 'length'; $changedProperties[] = 'length';
} }


Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
Expand Up @@ -38,10 +38,10 @@ protected function _getPortableTableForeignKeyDefinition($tableForeignKey)
$onUpdate = null; $onUpdate = null;
$onDelete = null; $onDelete = null;


if (preg_match('(ON UPDATE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))', $tableForeignKey['condef'], $match)) { if (preg_match('(ON UPDATE ([a-zA-Z0-9]+))', $tableForeignKey['condef'], $match)) {
$onUpdate = $match[1]; $onUpdate = $match[1];
} }
if (preg_match('(ON DELETE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))', $tableForeignKey['condef'], $match)) { if (preg_match('(ON DELETE ([a-zA-Z0-9]+))', $tableForeignKey['condef'], $match)) {
$onDelete = $match[1]; $onDelete = $match[1];
} }


Expand Down
11 changes: 7 additions & 4 deletions lib/Doctrine/DBAL/Schema/Table.php
Expand Up @@ -288,19 +288,21 @@ public function dropColumn($columnName)
* @param array $localColumns * @param array $localColumns
* @param array $foreignColumns * @param array $foreignColumns
* @param array $options * @param array $options
* @param string $constraintName
* @return Table * @return Table
*/ */
public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options=array()) public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options=array(), $constraintName = null)
{ {
$name = $this->_generateIdentifierName(array_merge((array)$this->getName(), $localColumnNames), "fk", $this->_getMaxIdentifierLength()); $constraintName = $constraintName ?: $this->_generateIdentifierName(array_merge((array)$this->getName(), $localColumnNames), "fk", $this->_getMaxIdentifierLength());
return $this->addNamedForeignKeyConstraint($name, $foreignTable, $localColumnNames, $foreignColumnNames, $options); return $this->addNamedForeignKeyConstraint($constraintName, $foreignTable, $localColumnNames, $foreignColumnNames, $options);
} }


/** /**
* Add a foreign key constraint * Add a foreign key constraint
* *
* Name is to be generated by the database itsself. * Name is to be generated by the database itsself.
* *
* @deprecated Use {@link addForeignKeyConstraint}
* @param Table $foreignTable * @param Table $foreignTable
* @param array $localColumns * @param array $localColumns
* @param array $foreignColumns * @param array $foreignColumns
Expand All @@ -309,12 +311,13 @@ public function addForeignKeyConstraint($foreignTable, array $localColumnNames,
*/ */
public function addUnnamedForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options=array()) public function addUnnamedForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options=array())
{ {
return $this->addNamedForeignKeyConstraint(null, $foreignTable, $localColumnNames, $foreignColumnNames, $options); return $this->addForeignKeyConstraint($foreignTable, $localColumnNames, $foreignColumnNames, $options);
} }


/** /**
* Add a foreign key constraint with a given name * Add a foreign key constraint with a given name
* *
* @deprecated Use {@link addForeignKeyConstraint}
* @param string $name * @param string $name
* @param Table $foreignTable * @param Table $foreignTable
* @param array $localColumns * @param array $localColumns
Expand Down
8 changes: 2 additions & 6 deletions lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php
Expand Up @@ -26,7 +26,7 @@
/** /**
* Task for executing arbitrary SQL that can come from a file or directly from * Task for executing arbitrary SQL that can come from a file or directly from
* the command line. * the command line.
* *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.0 * @since 2.0
Expand Down Expand Up @@ -71,17 +71,13 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
if ( ! is_numeric($depth)) { if ( ! is_numeric($depth)) {
throw new \LogicException("Option 'depth' must contains an integer value"); throw new \LogicException("Option 'depth' must contains an integer value");
} }

if (preg_match('/^select/i', $sql)) { if (preg_match('/^select/i', $sql)) {
$resultSet = $conn->fetchAll($sql); $resultSet = $conn->fetchAll($sql);
} else { } else {
$resultSet = $conn->executeUpdate($sql); $resultSet = $conn->executeUpdate($sql);
} }


ob_start();
\Doctrine\Common\Util\Debug::dump($resultSet, (int) $depth); \Doctrine\Common\Util\Debug::dump($resultSet, (int) $depth);
$message = ob_get_clean();

$output->write($message);
} }
} }
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Version.php
Expand Up @@ -36,7 +36,7 @@ class Version
/** /**
* Current Doctrine Version * Current Doctrine Version
*/ */
const VERSION = '2.2.0-DEV'; const VERSION = '2.1.0-DEV';


/** /**
* Compares a Doctrine version with the current one. * Compares a Doctrine version with the current one.
Expand Down
Expand Up @@ -2,11 +2,49 @@


namespace Doctrine\Tests\DBAL\Functional\Schema; namespace Doctrine\Tests\DBAL\Functional\Schema;


use Doctrine\DBAL\Schema; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\Schema;


require_once __DIR__ . '/../../../TestInit.php'; require_once __DIR__ . '/../../../TestInit.php';


class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
{ {

public function testSwitchPrimaryKeyColumns()
{
$tableOld = new Table("switch_primary_key_columns");
$tableOld->addColumn('foo_id', 'integer');
$tableOld->addColumn('bar_id', 'integer');
$tableNew = clone $tableOld;

$this->_sm->createTable($tableOld);
$tableFetched = $this->_sm->listTableDetails("switch_primary_key_columns");
$tableNew = clone $tableFetched;
$tableNew->setPrimaryKey(array('bar_id', 'foo_id'));

$comparator = new \Doctrine\DBAL\Schema\Comparator;
$this->_sm->alterTable($comparator->diffTable($tableFetched, $tableNew));
}

public function testDiffTableBug()
{
$schema = new Schema();
$table = $schema->createTable('diffbug_routing_translations');
$table->addColumn('id', 'integer');
$table->addColumn('route', 'string');
$table->addColumn('locale', 'string');
$table->addColumn('attribute', 'string');
$table->addColumn('localized_value', 'string');
$table->addColumn('original_value', 'string');
$table->setPrimaryKey(array('id'));
$table->addUniqueIndex(array('route', 'locale', 'attribute'));
$table->addIndex(array('localized_value')); // this is much more selective than the unique index

$this->_sm->createTable($table);
$tableFetched = $this->_sm->listTableDetails("diffbug_routing_translations");

$comparator = new \Doctrine\DBAL\Schema\Comparator;
$diff = $comparator->diffTable($tableFetched, $table);

$this->assertFalse($diff, "no changes expected.");
}
} }