summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2014-09-19 12:05:20 (GMT)
committerAleksander Machniak <machniak@kolabsys.com>2014-09-19 12:05:20 (GMT)
commit4f12f064ffdff954e2010fa156257be2a64ff83c (patch)
treebf4375feadb4ef0b98d0f56af131f46a6ad5d7e0
parent32aa1ab046776f823cfaec222f7cda07e1d3752b (diff)
downloadkolab-syncroton-4f12f064ffdff954e2010fa156257be2a64ff83c.tar.gz
Use parametrized INSERT/UPDATE queries to "workaround" Oracle length limitsoracle
-rw-r--r--lib/kolab_sync_backend_common.php20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/kolab_sync_backend_common.php b/lib/kolab_sync_backend_common.php
index 55e2f3b..13fdf23 100644
--- a/lib/kolab_sync_backend_common.php
+++ b/lib/kolab_sync_backend_common.php
@@ -90,17 +90,19 @@ class kolab_sync_backend_common implements Syncroton_Backend_IBackend
throw new InvalidArgumentException('$object must be instanace of ' . $this->interface_name);
}
- $data = $this->object_to_array($object);
- $insert = array();
+ $data = $this->object_to_array($object);
+ $cols = array();
$data['id'] = $object->id = sha1(mt_rand(). microtime());
- foreach ($data as $key => $value) {
- $insert[$this->db->quote_identifier($key)] = $this->db->quote($value);
+ foreach (array_keys($data) as $key) {
+ $cols[] = $this->db->quote_identifier($key);
}
- $this->db->query('INSERT INTO `' . $this->table_name . '`'
- . ' (' . implode(', ', array_keys($insert)) . ')' . ' VALUES(' . implode(', ', $insert) . ')');
+ $this->db->query('INSERT INTO `' . $this->table_name . '`' . ' (' . implode(', ', $cols) . ')'
+ . ' VALUES(' . implode(', ', array_fill(0, count($cols), '?')) . ')',
+ array_values($data)
+ );
if (!$this->db->insert_id($this->table_name)) {
// @TODO: throw exception
@@ -169,12 +171,12 @@ class kolab_sync_backend_common implements Syncroton_Backend_IBackend
$data = $this->object_to_array($object);
$set = array();
- foreach ($data as $key => $value) {
- $set[] = $this->db->quote_identifier($key) . ' = ' . $this->db->quote($value);
+ foreach (array_keys($data) as $key) {
+ $set[] = $this->db->quote_identifier($key) . ' = ?';
}
$this->db->query('UPDATE `' . $this->table_name . '` SET ' . implode(', ', $set)
- . ' WHERE `id` = ' . $this->db->quote($object->id));
+ . ' WHERE `id` = ' . $this->db->quote($object->id), array_values($data));
return $object;
}