From 460b681bcb80717883f4b393cb53392ea1c6140a Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Mon, 17 Aug 2015 18:18:21 +0200 Subject: [PATCH] [jan] Fix inserting and updating photos with Oracle backends. Conflicts: turba/docs/CHANGES turba/package.xml --- turba/lib/Driver/Sql.php | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/turba/lib/Driver/Sql.php b/turba/lib/Driver/Sql.php index 47a7d9215e6..35d919e223f 100644 --- a/turba/lib/Driver/Sql.php +++ b/turba/lib/Driver/Sql.php @@ -419,15 +419,20 @@ protected function _read($key, $ids, $owner, array $fields, * * @throws Turba_Exception */ - protected function _add(array $attributes, array $blob_fields = array(), array $date_fields = array()) + protected function _add(array $attributes, array $blob_fields = array(), + array $date_fields = array()) { - list($fields, $values) = $this->_prepareWrite($attributes, $blob_fields, $date_fields); - $query = 'INSERT INTO ' . $this->_params['table'] - . ' (' . implode(', ', $fields) . ')' - . ' VALUES (' . str_repeat('?, ', count($values) - 1) . '?)'; + list($fields, $values) = $this->_prepareWrite( + $attributes, + $blob_fields, + $date_fields + ); try { - $this->_db->insert($query, $values); + $this->_db->insertBlob( + $this->_params['table'], + array_combine($fields, $values) + ); } catch (Horde_Db_Exception $e) { throw new Turba_Exception(_("Server error when adding data.")); } @@ -530,22 +535,25 @@ protected function _deleteAll($sourceName = null) */ protected function _save(Turba_Object $object) { - list($object_key, $object_id) = each($this->toDriverKeys(array('__key' => $object->getValue('__key')))); + list($object_key, $object_id) = each( + $this->toDriverKeys(array('__key' => $object->getValue('__key'))) + ); $attributes = $this->toDriverKeys($object->getAttributes()); $blob_fields = $this->toDriverKeys($this->getBlobs()); $date_fields = $this->toDriverKeys($this->getDateFields()); - - $where = $object_key . ' = ?'; unset($attributes[$object_key]); - - list($fields, $values) = $this->_prepareWrite($attributes, $blob_fields, $date_fields); - - $values[] = $object_id; - - $query = 'UPDATE ' . $this->_params['table'] . ' SET ' . implode(' = ?, ', $fields) . ' = ? WHERE ' . $where; + list($fields, $values) = $this->_prepareWrite( + $attributes, + $blob_fields, + $date_fields + ); try { - $this->_db->update($query, $values); + $this->_db->updateBlob( + $this->_params['table'], + array_combine($fields, $values), + array($object_key . ' = ?', array($object_id)) + ); } catch (Horde_Db_Exception $e) { throw new Turba_Exception(_("Server error when saving data.")); }