diff options
author | Andreas Fischer <bantu@owncloud.com> | 2013-10-31 15:44:19 +0100 |
---|---|---|
committer | Andreas Fischer <bantu@owncloud.com> | 2013-10-31 16:04:18 +0100 |
commit | d6ddb12c20a646204bee1d5c3d749e1b22783f05 (patch) | |
tree | ecefa3cc77fd86800fabe305ce5f3a0182121d42 /lib/private/ocs | |
parent | 43d71aada89abfaa8b1989874af5f4d7773c0278 (diff) | |
download | nextcloud-server-d6ddb12c20a646204bee1d5c3d749e1b22783f05.tar.gz nextcloud-server-d6ddb12c20a646204bee1d5c3d749e1b22783f05.zip |
Get rid of the SELECT query. Try UPDATE, on failure INSERT.
Diffstat (limited to 'lib/private/ocs')
-rw-r--r-- | lib/private/ocs/privatedata.php | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/private/ocs/privatedata.php b/lib/private/ocs/privatedata.php index 2c53d576092..932413711b8 100644 --- a/lib/private/ocs/privatedata.php +++ b/lib/private/ocs/privatedata.php @@ -69,18 +69,14 @@ class OC_OCS_Privatedata { $key = addslashes(strip_tags($parameters['key'])); $value = OC_OCS::readData('post', 'value', 'text'); - // check if key is already set - $query = \OCP\DB::prepare('SELECT `value` FROM `*PREFIX*privatedata` WHERE `user` = ? AND `app` = ? AND `key` = ? '); - $result = $query->execute(array($user, $app, $key)); + // update in DB + $query = \OCP\DB::prepare('UPDATE `*PREFIX*privatedata` SET `value` = ? WHERE `user` = ? AND `app` = ? AND `key` = ?'); + $numRows = $query->execute(array($value, $user, $app, $key)); - if ($result->numRows()==0) { + if ($numRows === false || $numRows === 0) { // store in DB $query = \OCP\DB::prepare('INSERT INTO `*PREFIX*privatedata` (`user`, `app`, `key`, `value`)' . ' VALUES(?, ?, ?, ?)'); $query->execute(array($user, $app, $key, $value)); - } else { - // update in DB - $query = \OCP\DB::prepare('UPDATE `*PREFIX*privatedata` SET `value` = ? WHERE `user` = ? AND `app` = ? AND `key` = ? '); - $query->execute(array($value, $user, $app, $key )); } return new OC_OCS_Result(null, 100); |