[Pkg-owncloud-commits] [owncloud] 13/70: make search case insensitive on postgres and oracle

David Prévot taffit at moszumanska.debian.org
Mon Jul 14 17:38:03 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit 71261decf11f6db9c2de30b24f37bda0789a0032
Author: Jörn Friedrich Dreyer <jfd at butonic.de>
Date:   Thu Jul 3 19:01:00 2014 +0200

    make search case insensitive on postgres and oracle
---
 lib/private/files/cache/cache.php | 24 +++++++++++++++++++++---
 tests/lib/files/cache/cache.php   |  6 ++++++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php
index 48c57e2..72af474 100644
--- a/lib/private/files/cache/cache.php
+++ b/lib/private/files/cache/cache.php
@@ -458,9 +458,27 @@ class Cache {
 		// normalize pattern
 		$pattern = $this->normalize($pattern);
 
-		$sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `unencrypted_size`, `etag`, `permissions`
-				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`, `permissions`
+			FROM `*PREFIX*filecache`
+			WHERE `storage` = ? AND ';
+		$dbtype = \OC_Config::getValue( 'dbtype', 'sqlite' );
+		if($dbtype === 'oci') {
+			//remove starting and ending % from the 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 8ed2eca..bf17f7a 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