Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
wants to merge 16 commits into from

4 participants

@gnomii

Hi,

Sorry, I was not able to merge the branchs with the master :( I try some methods

Best regards,
Maxime

@stof

You should cherry-pick your commit to send a PR based on master instead

@beberlei
Owner

This is already in master.

@beberlei beberlei closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 24, 2011
  1. @beberlei
  2. @beberlei
Commits on Jul 31, 2011
  1. @beberlei

    DDC-1271 - Fix date diff in PostgreSQL when timestamps are passed by …

    beberlei authored
    …casting everything into dates explicitly.
  2. @beberlei
  3. @beberlei

    Revert "Merge branch 'DDC-1271' into 2.1.x"

    beberlei authored
    This reverts commit 0d2af88, reversing
    changes made to eb0a461.
  4. @beberlei

    DDC-1271 - Fix date diff in PostgreSQL when timestamps are passed by …

    beberlei authored
    …casting everything into dates explicitly.
  5. @beberlei

    DDC-1282 - Remove overprotective casting of days/months to integer, w…

    beberlei authored
    …hich prevents passing columns as days. The platform is not responsible for escapsing, the DQL parser already does it way before generating the sql statements.
  6. @beberlei
  7. @beberlei

    Fix typo

    beberlei authored
  8. @AaronDDM @beberlei

    Fix for DBAL-82

    AaronDDM authored beberlei committed
  9. @beberlei
  10. @beberlei
  11. @beberlei
  12. @beberlei

    DBAL-132 - Make Table::addUnnamedForeignKeyConstraint() generate a na…

    beberlei authored
    …me based on the input, @deprecated addUnnamedForeignKeyConstraint and addNamedForeignKeyConstraint.
  13. @beberlei
Commits on Aug 11, 2011
  1. @gnomii

    Fix if the port is empty

    gnomii authored
This page is out of date. Refresh to see the latest.
View
2  lib/Doctrine/DBAL/Driver/OCI8/Driver.php
@@ -47,7 +47,7 @@ public function connect(array $params, $username = null, $password = null, array
*
* @return string The DSN.
*/
- protected function _constructDsn(array $params)
+ private function _constructDsn(array $params)
{
$dsn = '';
if (isset($params['host'])) {
View
4 lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php
@@ -26,9 +26,9 @@
*/
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.
View
10 lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
@@ -30,15 +30,15 @@
class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
{
/** Statement handle. */
- protected $_sth;
- protected $_executeMode;
- protected static $_PARAM = ':param';
- protected static $fetchStyleMap = array(
+ private $_sth;
+ private $_executeMode;
+ private static $_PARAM = ':param';
+ private static $fetchStyleMap = array(
PDO::FETCH_BOTH => OCI_BOTH,
PDO::FETCH_ASSOC => OCI_ASSOC,
PDO::FETCH_NUM => OCI_NUM
);
- protected $_paramMap = array();
+ private $_paramMap = array();
/**
* Creates a new OCI8Statement that uses the given connection handle and SQL statement.
View
8 lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php
@@ -71,7 +71,7 @@ private function _constructPdoDsn(array $params)
if (isset($params['charset'])) {
$dsn .= 'charset=' . $params['charset'] . ';';
}
-
+
return $dsn;
}
@@ -93,10 +93,6 @@ public function getName()
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
-
- if (isset($params['dbname'])) {
- return $params['dbname'];
- }
- return $conn->query('SELECT DATABASE()')->fetchColumn();
+ return $params['dbname'];
}
}
View
2  lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php
@@ -37,7 +37,7 @@ private function _constructPdoDsn(array $params)
if (isset($params['host']) && $params['host'] != '') {
$dsn .= 'host=' . $params['host'] . ' ';
}
- if (isset($params['port'])) {
+ if (isset($params['port']) && $params['port'] != '') {
$dsn .= 'port=' . $params['port'] . ' ';
}
if (isset($params['dbname'])) {
View
6 lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
@@ -607,14 +607,12 @@ protected function doModifyLimitQuery($query, $limit, $offset = null)
// Remove ORDER BY clause from $query
$query = preg_replace('/\s+ORDER BY(.*)/', '', $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";
+ $query = preg_replace('/^SELECT\s/', '', $query);
$start = $offset + 1;
$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";
}
}
View
8 lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
@@ -108,22 +108,22 @@ public function getDateDiffExpression($date1, $date2)
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)
{
- return 'DATE_SUB(' . $date . ', INTERVAL ' . (int)$days . ' DAY)';
+ return 'DATE_SUB(' . $date . ', INTERVAL ' . $days . ' DAY)';
}
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)
{
- return 'DATE_SUB(' . $date . ', INTERVAL ' . (int)$months . ' MONTH)';
+ return 'DATE_SUB(' . $date . ', INTERVAL ' . $months . ' MONTH)';
}
public function getListDatabasesSQL()
View
8 lib/Doctrine/DBAL/Platforms/OraclePlatform.php
@@ -118,22 +118,22 @@ public function getDateDiffExpression($date1, $date2)
public function getDateAddDaysExpression($date, $days)
{
- return '(' . $date . '+' . (int)$days . ')';
+ return '(' . $date . '+' . $days . ')';
}
public function getDateSubDaysExpression($date, $days)
{
- return '(' . $date . '-' . (int)$days . ')';
+ return '(' . $date . '-' . $days . ')';
}
public function getDateAddMonthExpression($date, $months)
{
- return "ADD_MONTHS(" . $date . ", " . (int)$months . ")";
+ return "ADD_MONTHS(" . $date . ", " . $months . ")";
}
public function getDateSubMonthExpression($date, $months)
{
- return "ADD_MONTHS(" . $date . ", -" . (int)$months . ")";
+ return "ADD_MONTHS(" . $date . ", -" . $months . ")";
}
/**
View
10 lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
@@ -94,27 +94,27 @@ public function getLocateExpression($str, $substr, $startPos = false)
public function getDateDiffExpression($date1, $date2)
{
- return '('.$date1 . '-'.$date2.')';
+ return '(DATE(' . $date1 . ')-DATE(' . $date2 . '))';
}
public function getDateAddDaysExpression($date, $days)
{
- return "(" . $date . "+ interval '" . (int)$days . " day')";
+ return "(" . $date . "+ interval '" . $days . " day')";
}
public function getDateSubDaysExpression($date, $days)
{
- return "(" . $date . "- interval '" . (int)$days . " day')";
+ return "(" . $date . "- interval '" . $days . " day')";
}
public function getDateAddMonthExpression($date, $months)
{
- return "(" . $date . "+ interval '" . (int)$months . " month')";
+ return "(" . $date . "+ interval '" . $months . " month')";
}
public function getDateSubMonthExpression($date, $months)
{
- return "(" . $date . "- interval '" . (int)$months . " month')";
+ return "(" . $date . "- interval '" . $months . " month')";
}
/**
View
8 lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
@@ -132,22 +132,22 @@ public function getDateDiffExpression($date1, $date2)
public function getDateAddDaysExpression($date, $days)
{
- return "DATE(" . $date . ",'+". (int)$days . " day')";
+ return "DATE(" . $date . ",'+". $days . " day')";
}
public function getDateSubDaysExpression($date, $days)
{
- return "DATE(" . $date . ",'-". (int)$days . " day')";
+ return "DATE(" . $date . ",'-". $days . " day')";
}
public function getDateAddMonthExpression($date, $months)
{
- return "DATE(" . $date . ",'+". (int)$months . " month')";
+ return "DATE(" . $date . ",'+". $months . " month')";
}
public function getDateSubMonthExpression($date, $months)
{
- return "DATE(" . $date . ",'-". (int)$months . " month')";
+ return "DATE(" . $date . ",'-". $months . " month')";
}
protected function _getTransactionIsolationLevelSQL($level)
View
5 lib/Doctrine/DBAL/Schema/Comparator.php
@@ -325,7 +325,10 @@ public function diffColumn(Column $column1, Column $column2)
}
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';
}
View
4 lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
@@ -38,10 +38,10 @@ protected function _getPortableTableForeignKeyDefinition($tableForeignKey)
$onUpdate = 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];
}
- 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];
}
View
11 lib/Doctrine/DBAL/Schema/Table.php
@@ -288,12 +288,13 @@ public function dropColumn($columnName)
* @param array $localColumns
* @param array $foreignColumns
* @param array $options
+ * @param string $constraintName
* @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());
- return $this->addNamedForeignKeyConstraint($name, $foreignTable, $localColumnNames, $foreignColumnNames, $options);
+ $constraintName = $constraintName ?: $this->_generateIdentifierName(array_merge((array)$this->getName(), $localColumnNames), "fk", $this->_getMaxIdentifierLength());
+ return $this->addNamedForeignKeyConstraint($constraintName, $foreignTable, $localColumnNames, $foreignColumnNames, $options);
}
/**
@@ -301,6 +302,7 @@ public function addForeignKeyConstraint($foreignTable, array $localColumnNames,
*
* Name is to be generated by the database itsself.
*
+ * @deprecated Use {@link addForeignKeyConstraint}
* @param Table $foreignTable
* @param array $localColumns
* @param array $foreignColumns
@@ -309,12 +311,13 @@ public function addForeignKeyConstraint($foreignTable, array $localColumnNames,
*/
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
*
+ * @deprecated Use {@link addForeignKeyConstraint}
* @param string $name
* @param Table $foreignTable
* @param array $localColumns
View
8 lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php
@@ -26,7 +26,7 @@
/**
* Task for executing arbitrary SQL that can come from a file or directly from
* the command line.
- *
+ *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
@@ -71,17 +71,13 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
if ( ! is_numeric($depth)) {
throw new \LogicException("Option 'depth' must contains an integer value");
}
-
+
if (preg_match('/^select/i', $sql)) {
$resultSet = $conn->fetchAll($sql);
} else {
$resultSet = $conn->executeUpdate($sql);
}
- ob_start();
\Doctrine\Common\Util\Debug::dump($resultSet, (int) $depth);
- $message = ob_get_clean();
-
- $output->write($message);
}
}
View
2  lib/Doctrine/DBAL/Version.php
@@ -36,7 +36,7 @@ class Version
/**
* Current Doctrine Version
*/
- const VERSION = '2.2.0-DEV';
+ const VERSION = '2.1.0-DEV';
/**
* Compares a Doctrine version with the current one.
View
42 tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
@@ -2,11 +2,49 @@
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';
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.");
+ }
}
View
67 tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php
@@ -0,0 +1,67 @@
+<?php
+
+namespace Doctrine\Tests\DBAL\Schema\Platforms;
+
+require_once __DIR__ . '/../../../TestInit.php';
+
+use Doctrine\DBAL\Schema\Schema;
+use Doctrine\DBAL\Schema\Table;
+use Doctrine\DBAL\Schema\Column;
+use Doctrine\DBAL\Types\Type;
+
+class MySQLSchemaTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @var Comparator
+ */
+ private $comparator;
+ /**
+ *
+ * @var \Doctrine\DBAL\Platforms\AbstractPlatform
+ */
+ private $platform;
+
+ public function setUp()
+ {
+ $this->comparator = new \Doctrine\DBAL\Schema\Comparator;
+ $this->platform = new \Doctrine\DBAL\Platforms\MySqlPlatform;
+ }
+
+ public function testSwitchPrimaryKeyOrder()
+ {
+ $tableOld = new Table("test");
+ $tableOld->addColumn('foo_id', 'integer');
+ $tableOld->addColumn('bar_id', 'integer');
+ $tableNew = clone $tableOld;
+
+ $tableOld->setPrimaryKey(array('foo_id', 'bar_id'));
+ $tableNew->setPrimaryKey(array('bar_id', 'foo_id'));
+
+ $diff = $this->comparator->diffTable($tableOld, $tableNew);
+ $sql = $this->platform->getAlterTableSQL($diff);
+
+ $this->assertEquals(
+ array(
+ 'ALTER TABLE test DROP PRIMARY KEY',
+ 'ALTER TABLE test ADD PRIMARY KEY (bar_id, foo_id)'
+ ), $sql
+ );
+ }
+
+ /**
+ * @group DBAL-132
+ */
+ public function testGenerateForeignKeySQL()
+ {
+ $tableOld = new Table("test");
+ $tableOld->addColumn('foo_id', 'integer');
+ $tableOld->addUnnamedForeignKeyConstraint('test_foreign', array('foo_id'), array('foo_id'));
+
+ $sqls = array();
+ foreach ($tableOld->getForeignKeys() AS $fk) {
+ $sqls[] = $this->platform->getCreateForeignKeySQL($fk, $tableOld);
+ }
+
+ $this->assertEquals(array("ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C8E48560F FOREIGN KEY (foo_id) REFERENCES test_foreign(foo_id)"), $sqls);
+ }
+}
Something went wrong with that request. Please try again.