[Pkg-owncloud-commits] [owncloud] 30/66: Get rid of the SELECT query. Try UPDATE, on failure INSERT.
David Prévot
taffit at moszumanska.debian.org
Fri Apr 18 22:49:45 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag v5.0.15
in repository owncloud.
commit 0ae41c3afffc44acec09b2fe5a49d95a41bc9dda
Author: Andreas Fischer <bantu at owncloud.com>
Date: Thu Oct 31 15:44:19 2013 +0100
Get rid of the SELECT query. Try UPDATE, on failure INSERT.
---
lib/ocs/privatedata.php | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/lib/ocs/privatedata.php b/lib/ocs/privatedata.php
index 2c53d57..9324137 100644
--- a/lib/ocs/privatedata.php
+++ b/lib/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);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list