Skip to content

Commit

Permalink
[jan] Fix inserting and updating photos with Oracle backends.
Browse files Browse the repository at this point in the history
Conflicts:
	turba/docs/CHANGES
	turba/package.xml
  • Loading branch information
yunosh committed Aug 17, 2015
1 parent 2785779 commit 460b681
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions turba/lib/Driver/Sql.php
Expand Up @@ -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."));
}
Expand Down Expand Up @@ -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."));
}
Expand Down

0 comments on commit 460b681

Please sign in to comment.