Commit 693953dd authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge remote-tracking branch 'origin/2.0.x' into 2.0.x

parents 2241ba2a 6873b7e7
...@@ -89,6 +89,8 @@ ...@@ -89,6 +89,8 @@
<copy todir="${build.dir}/doctrine-dbal/bin"> <copy todir="${build.dir}/doctrine-dbal/bin">
<fileset refid="bin-scripts"/> <fileset refid="bin-scripts"/>
</copy> </copy>
<delete dir="${build.dir}/doctrine-dbal/Doctrine/Symfony/Component/Yaml/.git" includeemptydirs="true"/>
<delete dir="${build.dir}/doctrine-dbal/Doctrine/Symfony/Component/Console/.git" includeemptydirs="true"/>
<exec command="sed 's/${version}-DEV/${version}/' ${build.dir}/doctrine-dbal/Doctrine/DBAL/Version.php > ${build.dir}/doctrine-dbal/Doctrine/DBAL/Version2.php" passthru="true" /> <exec command="sed 's/${version}-DEV/${version}/' ${build.dir}/doctrine-dbal/Doctrine/DBAL/Version.php > ${build.dir}/doctrine-dbal/Doctrine/DBAL/Version2.php" passthru="true" />
<exec command="mv ${build.dir}/doctrine-dbal/Doctrine/DBAL/Version2.php ${build.dir}/doctrine-dbal/Doctrine/DBAL/Version.php" passthru="true" /> <exec command="mv ${build.dir}/doctrine-dbal/Doctrine/DBAL/Version2.php ${build.dir}/doctrine-dbal/Doctrine/DBAL/Version.php" passthru="true" />
</target> </target>
......
...@@ -68,6 +68,9 @@ class Driver implements \Doctrine\DBAL\Driver ...@@ -68,6 +68,9 @@ class Driver implements \Doctrine\DBAL\Driver
if (isset($params['unix_socket'])) { if (isset($params['unix_socket'])) {
$dsn .= 'unix_socket=' . $params['unix_socket'] . ';'; $dsn .= 'unix_socket=' . $params['unix_socket'] . ';';
} }
if (isset($params['charset'])) {
$dsn .= 'charset=' . $params['charset'] . ';';
}
return $dsn; return $dsn;
} }
......
...@@ -1960,13 +1960,40 @@ abstract class AbstractPlatform ...@@ -1960,13 +1960,40 @@ abstract class AbstractPlatform
return 'H:i:s'; return 'H:i:s';
} }
public function modifyLimitQuery($query, $limit, $offset = null) /**
* Modify limit query
*
* @param string $query
* @param int $limit
* @param int $offset
* @return string
*/
final public function modifyLimitQuery($query, $limit, $offset = null)
{
if ( $limit !== null) {
$limit = (int)$limit;
}
if ( $offset !== null) {
$offset = (int)$offset;
}
return $this->doModifyLimitQuery($query, $limit, $offset);
}
/**
* @param string $query
* @param int $limit
* @param int $offset
* @return string
*/
protected function doModifyLimitQuery($query, $limit, $offset)
{ {
if ( ! is_null($limit)) { if ( $limit !== null) {
$query .= ' LIMIT ' . $limit; $query .= ' LIMIT ' . $limit;
} }
if ( ! is_null($offset)) { if ( $offset !== null) {
$query .= ' OFFSET ' . $offset; $query .= ' OFFSET ' . $offset;
} }
......
...@@ -453,7 +453,7 @@ class DB2Platform extends AbstractPlatform ...@@ -453,7 +453,7 @@ class DB2Platform extends AbstractPlatform
return "SESSION." . $tableName; return "SESSION." . $tableName;
} }
public function modifyLimitQuery($query, $limit, $offset = null) protected function doModifyLimitQuery($query, $limit, $offset = null)
{ {
if ($limit === null && $offset === null) { if ($limit === null && $offset === null) {
return $query; return $query;
......
...@@ -583,14 +583,14 @@ class MsSqlPlatform extends AbstractPlatform ...@@ -583,14 +583,14 @@ class MsSqlPlatform extends AbstractPlatform
* @link http://lists.bestpractical.com/pipermail/rt-devel/2005-June/007339.html * @link http://lists.bestpractical.com/pipermail/rt-devel/2005-June/007339.html
* @return string * @return string
*/ */
public function modifyLimitQuery($query, $limit, $offset = null) protected function doModifyLimitQuery($query, $limit, $offset = null)
{ {
if ($limit > 0) { if ($limit > 0) {
$count = intval($limit); $count = intval($limit);
$offset = intval($offset); $offset = intval($offset);
if ($offset < 0) { if ($offset < 0) {
throw new Doctrine_Connection_Exception("LIMIT argument offset=$offset is not valid"); throw new DBALException("LIMIT argument offset=$offset is not valid");
} }
if ($offset == 0) { if ($offset == 0) {
......
...@@ -370,7 +370,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -370,7 +370,7 @@ class MySqlPlatform extends AbstractPlatform
$optionStrings = array(); $optionStrings = array();
if (isset($options['comment'])) { if (isset($options['comment'])) {
$optionStrings['comment'] = 'COMMENT = ' . $this->quote($options['comment'], 'text'); $optionStrings['comment'] = 'COMMENT = ' . $options['comment'];
} }
if (isset($options['charset'])) { if (isset($options['charset'])) {
$optionStrings['charset'] = 'DEFAULT CHARACTER SET ' . $options['charset']; $optionStrings['charset'] = 'DEFAULT CHARACTER SET ' . $options['charset'];
......
...@@ -555,7 +555,7 @@ LEFT JOIN all_cons_columns r_cols ...@@ -555,7 +555,7 @@ LEFT JOIN all_cons_columns r_cols
* @param integer $offset start reading from given offset * @param integer $offset start reading from given offset
* @return string the modified query * @return string the modified query
*/ */
public function modifyLimitQuery($query, $limit, $offset = null) protected function doModifyLimitQuery($query, $limit, $offset = null)
{ {
$limit = (int) $limit; $limit = (int) $limit;
$offset = (int) $offset; $offset = (int) $offset;
......
...@@ -154,6 +154,10 @@ class Column extends AbstractAsset ...@@ -154,6 +154,10 @@ class Column extends AbstractAsset
*/ */
public function setPrecision($precision) public function setPrecision($precision)
{ {
if (!is_numeric($precision)) {
$precision = 10; // defaults to 10 when no valid precision is given.
}
$this->_precision = (int)$precision; $this->_precision = (int)$precision;
return $this; return $this;
} }
...@@ -164,7 +168,11 @@ class Column extends AbstractAsset ...@@ -164,7 +168,11 @@ class Column extends AbstractAsset
*/ */
public function setScale($scale) public function setScale($scale)
{ {
$this->_scale = $scale; if (!is_numeric($scale)) {
$scale = 0;
}
$this->_scale = (int)$scale;
return $this; return $this;
} }
......
...@@ -163,6 +163,7 @@ class Comparator ...@@ -163,6 +163,7 @@ class Comparator
$changes++; $changes++;
} }
} }
foreach ( $table1Columns as $columnName => $column ) { foreach ( $table1Columns as $columnName => $column ) {
if ( $table2->hasColumn($columnName) ) { if ( $table2->hasColumn($columnName) ) {
$changedProperties = $this->diffColumn( $column, $table2->getColumn($columnName) ); $changedProperties = $this->diffColumn( $column, $table2->getColumn($columnName) );
...@@ -249,7 +250,7 @@ class Comparator ...@@ -249,7 +250,7 @@ class Comparator
foreach ($tableDifferences->addedColumns AS $addedColumnName => $addedColumn) { foreach ($tableDifferences->addedColumns AS $addedColumnName => $addedColumn) {
foreach ($tableDifferences->removedColumns AS $removedColumnName => $removedColumn) { foreach ($tableDifferences->removedColumns AS $removedColumnName => $removedColumn) {
if (count($this->diffColumn($addedColumn, $removedColumn)) == 0) { if (count($this->diffColumn($addedColumn, $removedColumn)) == 0) {
$renameCandidates[$addedColumn->getName()][] = array($removedColumn, $addedColumn); $renameCandidates[$addedColumn->getName()][] = array($removedColumn, $addedColumn, $addedColumnName);
} }
} }
} }
...@@ -257,8 +258,10 @@ class Comparator ...@@ -257,8 +258,10 @@ class Comparator
foreach ($renameCandidates AS $candidate => $candidateColumns) { foreach ($renameCandidates AS $candidate => $candidateColumns) {
if (count($candidateColumns) == 1) { if (count($candidateColumns) == 1) {
list($removedColumn, $addedColumn) = $candidateColumns[0]; list($removedColumn, $addedColumn) = $candidateColumns[0];
$removedColumnName = strtolower($removedColumn->getName());
$addedColumnName = strtolower($addedColumn->getName());
$tableDifferences->renamedColumns[$removedColumn->getName()] = $addedColumn; $tableDifferences->renamedColumns[$removedColumnName] = $addedColumn;
unset($tableDifferences->addedColumns[$addedColumnName]); unset($tableDifferences->addedColumns[$addedColumnName]);
unset($tableDifferences->removedColumns[$removedColumnName]); unset($tableDifferences->removedColumns[$removedColumnName]);
} }
...@@ -332,7 +335,7 @@ class Comparator ...@@ -332,7 +335,7 @@ class Comparator
} }
if ($column1->getType() instanceof \Doctrine\DBAL\Types\DecimalType) { if ($column1->getType() instanceof \Doctrine\DBAL\Types\DecimalType) {
if ($column1->getPrecision() != $column2->getPrecision()) { if (($column1->getPrecision()?:10) != ($column2->getPrecision()?:10)) {
$changedProperties[] = 'precision'; $changedProperties[] = 'precision';
} }
if ($column1->getScale() != $column2->getScale()) { if ($column1->getScale() != $column2->getScale()) {
......
...@@ -155,7 +155,9 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -155,7 +155,9 @@ class SqliteSchemaManager extends AbstractSchemaManager
case 'real': case 'real':
case 'decimal': case 'decimal':
case 'numeric': case 'numeric':
list($precision, $scale) = array_map('trim', explode(', ', $tableColumn['length'])); if (isset($tableColumn['length'])) {
list($precision, $scale) = array_map('trim', explode(', ', $tableColumn['length']));
}
$length = null; $length = null;
break; break;
} }
......
...@@ -36,7 +36,7 @@ class Version ...@@ -36,7 +36,7 @@ class Version
/** /**
* Current Doctrine Version * Current Doctrine Version
*/ */
const VERSION = '2.0.2-DEV'; const VERSION = '2.0.5-DEV';
/** /**
* Compares a Doctrine version with the current one. * Compares a Doctrine version with the current one.
......
Subproject commit 9d414673bb007e61977341d78745fc5aa316a92b Subproject commit a46c6180f96647fdd66e2c8f2771d61ecebe6a3f
...@@ -625,6 +625,48 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase ...@@ -625,6 +625,48 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$this->assertArrayHasKey('id', $tableDiff->changedColumns); $this->assertArrayHasKey('id', $tableDiff->changedColumns);
} }
/**
* @group DBAL-105
*/
public function testDiff()
{
$table = new \Doctrine\DBAL\Schema\Table('twitter_users');
$table->addColumn('id', 'integer', array('autoincrement' => true));
$table->addColumn('twitterId', 'integer', array('nullable' => false));
$table->addColumn('displayName', 'string', array('nullable' => false));
$table->setPrimaryKey(array('id'));
$newtable = new \Doctrine\DBAL\Schema\Table('twitter_users');
$newtable->addColumn('id', 'integer', array('autoincrement' => true));
$newtable->addColumn('twitter_id', 'integer', array('nullable' => false));
$newtable->addColumn('display_name', 'string', array('nullable' => false));
$newtable->addColumn('logged_in_at', 'datetime', array('nullable' => true));
$newtable->setPrimaryKey(array('id'));
$c = new Comparator();
$tableDiff = $c->diffTable($table, $newtable);
$this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
$this->assertEquals(array('twitterid', 'displayname'), array_keys($tableDiff->renamedColumns));
$this->assertEquals(array('logged_in_at'), array_keys($tableDiff->addedColumns));
$this->assertEquals(0, count($tableDiff->removedColumns));
}
/**
* @group DBAL-106
*/
public function testDiffDecimalWithNullPrecision()
{
$column = new Column('foo', Type::getType('decimal'));
$column->setPrecision(null);
$column2 = new Column('foo', Type::getType('decimal'));
$c = new Comparator();
$this->assertEquals(array(), $c->diffColumn($column, $column2));
}
/** /**
* @param SchemaDiff $diff * @param SchemaDiff $diff
* @param int $newTableCount * @param int $newTableCount
......
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