diff options
author | Robin Appelman <icewind@owncloud.com> | 2014-09-09 13:57:02 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-09-16 15:32:34 +0200 |
commit | 1771bfc2f2c790bc5d7a439095290cb4c97edf1a (patch) | |
tree | 85d26a01433af40d1aa7b3a39c22b51053a91f1e /lib/private/db | |
parent | 1978d3d6a279a4c60371b2cf809bd57e70f4ed35 (diff) | |
download | nextcloud-server-1771bfc2f2c790bc5d7a439095290cb4c97edf1a.tar.gz nextcloud-server-1771bfc2f2c790bc5d7a439095290cb4c97edf1a.zip |
Introduce cross-db ILIKE
Diffstat (limited to 'lib/private/db')
-rw-r--r-- | lib/private/db/adaptermysql.php | 17 | ||||
-rw-r--r-- | lib/private/db/adapteroci8.php | 12 | ||||
-rw-r--r-- | lib/private/db/adaptersqlite.php | 1 | ||||
-rw-r--r-- | lib/private/db/connectionfactory.php | 2 |
4 files changed, 26 insertions, 6 deletions
diff --git a/lib/private/db/adaptermysql.php b/lib/private/db/adaptermysql.php new file mode 100644 index 00000000000..0b6e6a5e969 --- /dev/null +++ b/lib/private/db/adaptermysql.php @@ -0,0 +1,17 @@ +<?php +/** + * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + + +namespace OC\DB; + +class AdapterMySQL extends Adapter { + public function fixupStatement($statement) { + $statement = str_replace(' ILIKE ', ' COLLATE utf8_general_ci LIKE ', $statement); + return $statement; + } +} diff --git a/lib/private/db/adapteroci8.php b/lib/private/db/adapteroci8.php index bc226e979ec..fb4ea1bcde9 100644 --- a/lib/private/db/adapteroci8.php +++ b/lib/private/db/adapteroci8.php @@ -11,18 +11,20 @@ namespace OC\DB; class AdapterOCI8 extends Adapter { public function lastInsertId($table) { - if($table !== null) { + if ($table !== null) { $suffix = '_SEQ'; - $table = '"'.$table.$suffix.'"'; + $table = '"' . $table . $suffix . '"'; } return $this->conn->realLastInsertId($table); } const UNIX_TIMESTAMP_REPLACEMENT = "(cast(sys_extract_utc(systimestamp) as date) - date'1970-01-01') * 86400"; + public function fixupStatement($statement) { - $statement = str_replace( '`', '"', $statement ); - $statement = str_ireplace( 'NOW()', 'CURRENT_TIMESTAMP', $statement ); - $statement = str_ireplace( 'UNIX_TIMESTAMP()', self::UNIX_TIMESTAMP_REPLACEMENT, $statement ); + $statement = preg_replace('/`(\w+)` ILIKE \?/', 'REGEXP_LIKE(`$1`, TRIM(BOTH \'%\' FROM ?), \'i\')', $statement); + $statement = str_replace('`', '"', $statement); + $statement = str_ireplace('NOW()', 'CURRENT_TIMESTAMP', $statement); + $statement = str_ireplace('UNIX_TIMESTAMP()', self::UNIX_TIMESTAMP_REPLACEMENT, $statement); return $statement; } } diff --git a/lib/private/db/adaptersqlite.php b/lib/private/db/adaptersqlite.php index 5b9c5a437da..06cdb7aab05 100644 --- a/lib/private/db/adaptersqlite.php +++ b/lib/private/db/adaptersqlite.php @@ -11,6 +11,7 @@ namespace OC\DB; class AdapterSqlite extends Adapter { public function fixupStatement($statement) { + $statement = str_replace(' ILIKE ', ' LIKE ', $statement); $statement = str_replace( '`', '"', $statement ); $statement = str_ireplace( 'NOW()', 'datetime(\'now\')', $statement ); $statement = str_ireplace( 'UNIX_TIMESTAMP()', 'strftime(\'%s\',\'now\')', $statement ); diff --git a/lib/private/db/connectionfactory.php b/lib/private/db/connectionfactory.php index dbbe58dbef8..8fd26bdc947 100644 --- a/lib/private/db/connectionfactory.php +++ b/lib/private/db/connectionfactory.php @@ -26,7 +26,7 @@ class ConnectionFactory { 'wrapperClass' => 'OC\DB\Connection', ), 'mysql' => array( - 'adapter' => '\OC\DB\Adapter', + 'adapter' => '\OC\DB\AdapterMySQL', 'charset' => 'UTF8', 'driver' => 'pdo_mysql', 'wrapperClass' => 'OC\DB\Connection', |