Skip to content

Commit

Permalink
Fix using addColumn() with autoincrementKey types in SQLite.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Nov 17, 2014
1 parent 915774f commit 0d80dfc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 17 additions & 5 deletions framework/Db/lib/Horde/Db/Adapter/Sqlite/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,27 @@ public function renameTable($name, $newName)
* Horde_Db_Adapter_Base_TableDefinition#column()
* for details.
*/
public function addColumn($tableName, $columnName, $type, $options=array())
public function addColumn($tableName, $columnName, $type, $options = array())
{
/* Ignore ':autoincrement' - it is handled automatically by SQLite
* for any 'INTEGER PRIMARY KEY' column. */
if ($this->transactionStarted()) {
throw new Horde_Db_Exception('Cannot add columns to a SQLite database while inside a transaction');
}

parent::addColumn($tableName, $columnName, $type, $options);
if ($type == 'autoincrementKey') {
$this->_alterTable(
$tableName,
array(),
create_function(
'$definition',
sprintf(
'$definition->column("%s", "%s", %s);',
$columnName, $type, var_export($options, true)
)
)
);
} else {
parent::addColumn($tableName, $columnName, $type, $options);
}

// See last paragraph on http://www.sqlite.org/lang_altertable.html
$this->execute('VACUUM');
Expand Down Expand Up @@ -271,7 +283,7 @@ public function removeColumn($tableName, $columnName)
* Horde_Db_Adapter_Base_TableDefinition#column()
* for details.
*/
public function changeColumn($tableName, $columnName, $type, $options=array())
public function changeColumn($tableName, $columnName, $type, $options = array())
{
$this->_clearTableCache($tableName);

Expand Down
2 changes: 2 additions & 0 deletions framework/Db/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
</stability>
<license uri="http://www.horde.org/licenses/bsd">BSD-2-Clause</license>
<notes>
* [jan] Fix using addColumn() with autoincrementKey types in SQLite.
* [jan] Fix several issues with changing autoincrementKey columns in Oracle.
* [mms] Fix SplitRead driver to work with the recent blob changes.
</notes>
Expand Down Expand Up @@ -858,6 +859,7 @@
<date>2014-11-06</date>
<license uri="http://www.horde.org/licenses/bsd">BSD-2-Clause</license>
<notes>
* [jan] Fix using addColumn() with autoincrementKey types in SQLite.
* [jan] Fix several issues with changing autoincrementKey columns in Oracle.
* [mms] Fix SplitRead driver to work with the recent blob changes.
</notes>
Expand Down

0 comments on commit 0d80dfc

Please sign in to comment.