Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Karlitschek <karlitschek@gmx.de>2015-03-09 16:05:22 +0300
committerFrank Karlitschek <karlitschek@gmx.de>2015-03-09 16:05:22 +0300
commit5def2c0998b9da09a2cc8b4ca82f1536ace63722 (patch)
tree184548a4a381383d76530c5bb047308179358b1b
parent10d0f0d9b338ae2e48043409a4cf316a1d81abc8 (diff)
parentf6ceb0b0d58e00ee4a216b39e377ef1539e55fb9 (diff)
Merge pull request #14738 from owncloud/backport-14734-stable8
[Backport-14734-stable8]
-rw-r--r--lib/private/db/adaptersqlite.php42
-rw-r--r--lib/private/files/cache/cache.php16
2 files changed, 20 insertions, 38 deletions
diff --git a/lib/private/db/adaptersqlite.php b/lib/private/db/adaptersqlite.php
index c5dfa85aaac..df4a804feb1 100644
--- a/lib/private/db/adaptersqlite.php
+++ b/lib/private/db/adaptersqlite.php
@@ -19,11 +19,13 @@ class AdapterSqlite extends Adapter {
}
public function insertIfNotExist($table, $input) {
- // NOTE: For SQLite we have to use this clumsy approach
- // otherwise all fieldnames used must have a unique key.
- $query = 'SELECT COUNT(*) FROM `' . $table . '` WHERE ';
- $inserts = array();
- foreach ($input as $key => $value) {
+ $fieldList = '`' . implode('`,`', array_keys($input)) . '`';
+ $query = "INSERT INTO `$table` ($fieldList) SELECT "
+ . str_repeat('?,', count($input)-1).'? '
+ . " WHERE NOT EXISTS (SELECT 1 FROM `$table` WHERE ";
+
+ $inserts = array_values($input);
+ foreach($input as $key => $value) {
$query .= '`' . $key . '`';
if (is_null($value)) {
$query .= ' IS NULL AND ';
@@ -33,34 +35,10 @@ class AdapterSqlite extends Adapter {
}
}
$query = substr($query, 0, strlen($query) - 5);
+ $query .= ')';
try {
- $stmt = $this->conn->prepare($query);
- $result = $stmt->execute($inserts);
- } catch(\Doctrine\DBAL\DBALException $e) {
- $entry = 'DB Error: "'.$e->getMessage() . '"<br />';
- $entry .= 'Offending command was: ' . $query . '<br />';
- \OC_Log::write('core', $entry, \OC_Log::FATAL);
- $l = \OC::$server->getL10N('lib');
- throw new \OC\HintException(
- $l->t('Database Error'),
- $l->t('Please contact your system administrator.'),
- 0,
- $e
- );
- }
-
- if ($stmt->fetchColumn() === '0') {
- $query = 'INSERT INTO `' . $table . '` (`'
- . implode('`,`', array_keys($input)) . '`) VALUES('
- . str_repeat('?,', count($input)-1).'? ' . ')';
- } else {
- return 0; //no rows updated
- }
-
- try {
- $statement = $this->conn->prepare($query);
- $result = $statement->execute(array_values($input));
+ return $this->conn->executeUpdate($query, $inserts);
} catch(\Doctrine\DBAL\DBALException $e) {
$entry = 'DB Error: "'.$e->getMessage() . '"<br />';
$entry .= 'Offending command was: ' . $query.'<br />';
@@ -73,7 +51,5 @@ class AdapterSqlite extends Adapter {
$e
);
}
-
- return $result;
}
}
diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php
index 3c097a34962..56c9bfa3ac5 100644
--- a/lib/private/files/cache/cache.php
+++ b/lib/private/files/cache/cache.php
@@ -240,13 +240,19 @@ class Cache {
list($queryParts, $params) = $this->buildParts($data);
$queryParts[] = '`storage`';
$params[] = $this->getNumericStorageId();
- $valuesPlaceholder = array_fill(0, count($queryParts), '?');
- $sql = 'INSERT INTO `*PREFIX*filecache` (' . implode(', ', $queryParts) . ')'
- . ' VALUES (' . implode(', ', $valuesPlaceholder) . ')';
- \OC_DB::executeAudited($sql, $params);
+ $params = array_map(function($item) {
+ return trim($item, "`");
+ }, $params);
+ $queryParts = array_map(function($item) {
+ return trim($item, "`");
+ }, $queryParts);
+ $values = array_combine($queryParts, $params);
+ if (\OC::$server->getDatabaseConnection()->insertIfNotExist('*PREFIX*filecache', $values)) {
+ return (int)\OC_DB::insertid('*PREFIX*filecache');
+ }
- return (int)\OC_DB::insertid('*PREFIX*filecache');
+ return $this->getId($file);
}
}