Skip to content

Commit

Permalink
[jan] Fix changing columns to NULL/NOT NULL on Oracle and SQLite.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Jun 17, 2014
1 parent 7fbc34f commit a443761
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
26 changes: 17 additions & 9 deletions framework/Db/lib/Horde/Db/Adapter/Oracle/Schema.php
Expand Up @@ -427,14 +427,22 @@ public function changeColumn($tableName, $columnName, $type, $options = array())
return;
}

$old = $this->typeToSql(
$column->getType(),
$column->getType() == 'integer' || is_null($options['limit'])
? null
: $column->getLimit(),
is_null($options['precision']) ? null : $column->precision(),
is_null($options['scale']) ? null : $column->scale(),
is_null($options['unsigned']) ? null : $column->isUnsigned()
$columnOptions = array(
'limit' => $column->getLimit(),
'default' => $column->getDefault(),
'null' => $column->isNull()
);
$old = $this->addColumnOptions(
$this->typeToSql(
$column->getType(),
$column->getType() == 'integer' || is_null($options['limit'])
? null
: $column->getLimit(),
is_null($options['precision']) ? null : $column->precision(),
is_null($options['scale']) ? null : $column->scale(),
is_null($options['unsigned']) ? null : $column->isUnsigned()
),
$columnOptions
);
$new = $this->typeToSql(
$type,
Expand All @@ -443,7 +451,7 @@ public function changeColumn($tableName, $columnName, $type, $options = array())
$options['scale'],
$options['unsigned']
);
if ($old == $new) {
if ($old == $this->addColumnOptions($new, $options)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion framework/Db/lib/Horde/Db/Adapter/Sqlite/Schema.php
Expand Up @@ -283,7 +283,7 @@ public function changeColumn($tableName, $columnName, $type, $options=array())
$defs[] = sprintf('$definition["%s"]->setLimit("%s");', $columnName, $options['limit']);
}
if (isset($options['null'])) {
$defs[] = sprintf('$definition["%s"]->setNull("%s");', $columnName, $options['null']);
$defs[] = sprintf('$definition["%s"]->setNull((bool)%d);', $columnName, $options['null']);
}
if (isset($options['precision'])) {
$defs[] = sprintf('$definition["%s"]->setPrecision("%s");', $columnName, $options['precision']);
Expand Down
4 changes: 2 additions & 2 deletions framework/Db/package.xml
Expand Up @@ -34,7 +34,7 @@
</stability>
<license uri="http://www.horde.org/licenses/bsd">BSD-2-Clause</license>
<notes>
*
* [jan] Fix changing columns to NULL/NOT NULL on Oracle and SQLite.
</notes>
<contents>
<dir baseinstalldir="/" name="/">
Expand Down Expand Up @@ -800,7 +800,7 @@
<date>2014-05-21</date>
<license uri="http://www.horde.org/licenses/bsd">BSD-2-Clause</license>
<notes>
*
* [jan] Fix changing columns to NULL/NOT NULL on Oracle and SQLite.
</notes>
</release>
</changelog>
Expand Down
1 change: 1 addition & 0 deletions framework/Db/test/Horde/Db/Adapter/Pdo/SqliteTest.php
Expand Up @@ -46,6 +46,7 @@ protected static function _getConnection($overrides = array())

$cache = new Horde_Cache(new Horde_Cache_Storage_Mock());
$conn->setCache($cache);
//$conn->setLogger(new Horde_Log_Logger(new Horde_Log_Handler_Cli()));

return array($conn, $cache);
}
Expand Down
15 changes: 15 additions & 0 deletions framework/Db/test/Horde/Db/Adapter/TestBase.php
Expand Up @@ -430,6 +430,21 @@ abstract public function testChangeColumnLimit();

abstract public function testChangeColumnPrecisionScale();

public function testChangeColumnNull()
{
$this->_createTestTable('sports');
$column = $this->_getColumn('sports', 'name');
$this->assertTrue($column->isNull());
$this->_conn->changeColumn('sports', 'name', 'string',
array('null' => false));
$column = $this->_getColumn('sports', 'name');
$this->assertFalse($column->isNull());
$this->_conn->changeColumn('sports', 'name', 'string',
array('null' => true));
$column = $this->_getColumn('sports', 'name');
$this->assertTrue($column->isNull());
}

abstract public function testRenameColumn();

public function testRenameColumnWithSqlReservedWord()
Expand Down

0 comments on commit a443761

Please sign in to comment.