summaryrefslogtreecommitdiffstats
path: root/lib/MDB2
diff options
context:
space:
mode:
authorRobin Appelman <icewind1991@gmail.com>2011-11-15 15:58:12 +0100
committerRobin Appelman <icewind1991@gmail.com>2012-01-08 01:57:53 +0100
commit09a53170a309677b344b25d9820ef038a0e87929 (patch)
tree5c0245cfe266c563146bec4d2ee9a4d330240bf0 /lib/MDB2
parentecf6f2ca2f74abbfdc72788c502ef5a015dc890a (diff)
downloadnextcloud-server-09a53170a309677b344b25d9820ef038a0e87929.tar.gz
nextcloud-server-09a53170a309677b344b25d9820ef038a0e87929.zip
fixes in the sqlite manager driver
Diffstat (limited to 'lib/MDB2')
-rw-r--r--lib/MDB2/Driver/Manager/sqlite3.php72
1 files changed, 49 insertions, 23 deletions
diff --git a/lib/MDB2/Driver/Manager/sqlite3.php b/lib/MDB2/Driver/Manager/sqlite3.php
index 71b9597d202..a6fde69d6c4 100644
--- a/lib/MDB2/Driver/Manager/sqlite3.php
+++ b/lib/MDB2/Driver/Manager/sqlite3.php
@@ -531,9 +531,26 @@ class MDB2_Driver_Manager_sqlite3 extends MDB2_Driver_Manager_Common
return MDB2_OK;
}
+ if (empty($changes['remove']) and empty($changes['rename']) and empty($changes['change']) ){//if only rename or add changes are required, we can use ALTER TABLE
+ $query = '';
+ if (!empty($changes['name'])) {
+ $change_name = $db->quoteIdentifier($changes['name'], true);
+ $query = 'RENAME TO ' . $change_name;
+ $db->exec("ALTER TABLE $name $query");
+ }
+
+ if (!empty($changes['add']) && is_array($changes['add'])) {
+ foreach ($changes['add'] as $field_name => $field) {
+ $query= 'ADD ' . $db->getDeclaration($field['type'], $field_name, $field);
+ $db->exec("ALTER TABLE $name $query");
+ }
+ }
+ return MDB2_OK;
+ }
+
$db->loadModule('Reverse', null, true);
- // actually sqlite 2.x supports no ALTER TABLE at all .. so we emulate it
+ // for other operations we need to emulate them with sqlite3
$fields = $db->manager->listTableFields($name);
if (PEAR::isError($fields)) {
return $fields;
@@ -633,16 +650,10 @@ class MDB2_Driver_Manager_sqlite3 extends MDB2_Driver_Manager_Common
}
}
+ //rename the old table so we can create the new one
+ $db->exec("ALTER TABLE $name RENAME TO __$name");
$data = null;
- if (!empty($select_fields)) {
- $query = 'SELECT '.implode(', ', $select_fields).' FROM '.$db->quoteIdentifier($name, true);
- $data = $db->queryAll($query, null, MDB2_FETCHMODE_ORDERED);
- }
- $result = $this->dropTable($name);
- if (PEAR::isError($result)) {
- return $result;
- }
$result = $this->createTable($name_new, $fields, $options);
if (PEAR::isError($result)) {
@@ -657,20 +668,35 @@ class MDB2_Driver_Manager_sqlite3 extends MDB2_Driver_Manager_Common
$this->createConstraint($name_new, $constraint, $definition);
}
- if (!empty($select_fields) && !empty($data)) {
- $query = 'INSERT INTO '.$db->quoteIdentifier($name_new, true);
- $query.= '('.implode(', ', array_slice(array_keys($fields), 0, count($select_fields))).')';
- $query.=' VALUES (?'.str_repeat(', ?', (count($select_fields) - 1)).')';
- $stmt =$db->prepare($query, null, MDB2_PREPARE_MANIP);
- if (PEAR::isError($stmt)) {
- return $stmt;
- }
- foreach ($data as $row) {
- $result = $stmt->execute($row);
- if (PEAR::isError($result)) {
- return $result;
- }
- }
+ //fill the new table with data from the old one
+ if (!empty($select_fields)) {
+ $query = 'INSERT INTO '.$db->quoteIdentifier($name_new, true);
+ $query.= '('.implode(', ', array_slice(array_keys($fields), 0, count($select_fields))).')';
+ $query .= ' SELECT '.implode(', ', $select_fields).' FROM '.$db->quoteIdentifier('__'.$name, true);
+ $db->exec($query);
+ }
+
+// if (!empty($select_fields) && !empty($data)) {
+// $query = 'INSERT INTO '.$db->quoteIdentifier($name_new, true);
+// $query.= '('.implode(', ', array_slice(array_keys($fields), 0, count($select_fields))).')';
+// $query.=' VALUES (?'.str_repeat(', ?', (count($select_fields) - 1)).')';
+// $stmt =$db->prepare($query, null, MDB2_PREPARE_MANIP);
+// if (PEAR::isError($stmt)) {
+// return $stmt;
+// }
+// foreach ($data as $row) {
+// $result = $stmt->execute($row);
+// if (PEAR::isError($result)) {
+// return $result;
+// }
+// }
+// }
+ echo "changes $name";
+
+ //remove the old table
+ $result = $this->dropTable('__'.$name);
+ if (PEAR::isError($result)) {
+ return $result;
}
return MDB2_OK;
}