Skip to content
Snippets Groups Projects
Commit b5545b81 authored by Jörn Friedrich Dreyer's avatar Jörn Friedrich Dreyer
Browse files

make search case insensitive on postgres and oracle

parent 19a6dc54
No related branches found
No related tags found
No related merge requests found
...@@ -458,9 +458,27 @@ class Cache { ...@@ -458,9 +458,27 @@ class Cache {
// normalize pattern // normalize pattern
$pattern = $this->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` = ?'; $sql = '
$result = \OC_DB::executeAudited($sql, array($pattern, $this->getNumericStorageId())); 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(); $files = array();
while ($row = $result->fetchRow()) { while ($row = $result->fetchRow()) {
$row['mimetype'] = $this->getMimetype($row['mimetype']); $row['mimetype'] = $this->getMimetype($row['mimetype']);
......
...@@ -239,6 +239,12 @@ class Cache extends \PHPUnit_Framework_TestCase { ...@@ -239,6 +239,12 @@ class Cache extends \PHPUnit_Framework_TestCase {
$this->assertEquals(1, count($this->cache->search('folder%'))); $this->assertEquals(1, count($this->cache->search('folder%')));
$this->assertEquals(3, count($this->cache->search('%'))); $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(3, count($this->cache->searchByMime('foo')));
$this->assertEquals(2, count($this->cache->searchByMime('foo/file'))); $this->assertEquals(2, count($this->cache->searchByMime('foo/file')));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment