Branch 'oracle' - lib/kolab_sync_backend_common.php
Aleksander Machniak
machniak at kolabsys.com
Fri Sep 19 14:06:07 CEST 2014
lib/kolab_sync_backend_common.php | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
New commits:
commit 4f12f064ffdff954e2010fa156257be2a64ff83c
Author: Aleksander Machniak <machniak at kolabsys.com>
Date: Fri Sep 19 14:05:20 2014 +0200
Use parametrized INSERT/UPDATE queries to "workaround" Oracle length limits
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;
}
More information about the commits
mailing list