[Pkg-owncloud-commits] [owncloud] 38/50: fix case insensitive search on oracle and postgresql on oracle use regex_like on postgres use ILIKE add unit test to check case insensitivity
David Prévot
taffit at moszumanska.debian.org
Fri Oct 17 03:12:15 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag v6.0.6RC1
in repository owncloud.
commit 5e0ea9f3b5a1f8315d00cd3859a7ae27283102c4
Author: Jörn Friedrich Dreyer <jfd at butonic.de>
Date: Tue Apr 22 20:40:18 2014 +0200
fix case insensitive search on oracle and postgresql
on oracle use regex_like
on postgres use ILIKE
add unit test to check case insensitivity
---
lib/private/files/cache/cache.php | 25 ++++++++++++++++++++++---
tests/lib/files/cache/cache.php | 6 ++++++
2 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php
index e259513..8b289b4 100644
--- a/lib/private/files/cache/cache.php
+++ b/lib/private/files/cache/cache.php
@@ -447,9 +447,28 @@ class Cache {
// normalize pattern
$pattern = $this->normalize($pattern);
- $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `unencrypted_size`, `etag`
- FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `storage` = ?';
- $result = \OC_DB::executeAudited($sql, array($pattern, $this->getNumericStorageId()));
+ $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`,
+ `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`,
+ `unencrypted_size`, `etag`
+ FROM `*PREFIX*filecache`
+ WHERE `storage` = ? AND ';
+
+ $dbtype = \OC_Config::getValue( 'dbtype', 'sqlite' );
+ if($dbtype === 'oci') {
+ //replace % with .* for regex pattern
+ $pattern = '^'.str_replace('%', '.*', $pattern).'$';
+ $sql .= 'REGEXP_LIKE(`name`, ?, \'i\')';
+ } else if($dbtype === 'pgsql') {
+ $sql .= '`name` ILIKE ?';
+ } else {
+ $sql .= '`name` LIKE ?';
+ }
+
+ $result = \OC_DB::executeAudited(
+ $sql,
+ array($this->getNumericStorageId(), $pattern)
+ );
+
$files = array();
while ($row = $result->fetchRow()) {
$row['mimetype'] = $this->getMimetype($row['mimetype']);
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index 5d87693..e66f0ed 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -239,6 +239,12 @@ class Cache extends \PHPUnit_Framework_TestCase {
$this->assertEquals(1, count($this->cache->search('folder%')));
$this->assertEquals(3, count($this->cache->search('%')));
+ // case insensitive search should match the same files
+ $this->assertEquals(2, count($this->cache->search('%Foo%')));
+ $this->assertEquals(1, count($this->cache->search('Foo')));
+ $this->assertEquals(1, count($this->cache->search('%Folder%')));
+ $this->assertEquals(1, count($this->cache->search('Folder%')));
+
$this->assertEquals(3, count($this->cache->searchByMime('foo')));
$this->assertEquals(2, count($this->cache->searchByMime('foo/file')));
}
--
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