diff options
author | Bart Visscher <bartv@thisnet.nl> | 2013-02-25 22:49:55 +0100 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2013-07-21 23:17:37 +0200 |
commit | 58991150ab17846640907d43a6d4b0ff502d4986 (patch) | |
tree | 68b840c85a9b099872510b6adc6f420273ebbd80 /lib/db | |
parent | 1d5d23a1de5a490595d8bb7ea81b8bda48b8feeb (diff) | |
download | nextcloud-server-58991150ab17846640907d43a6d4b0ff502d4986.tar.gz nextcloud-server-58991150ab17846640907d43a6d4b0ff502d4986.zip |
Move query statement fixup handling to Connection wrapper
Diffstat (limited to 'lib/db')
-rw-r--r-- | lib/db/adapter.php | 4 | ||||
-rw-r--r-- | lib/db/adapteroci8.php | 7 | ||||
-rw-r--r-- | lib/db/adapterpgsql.php | 6 | ||||
-rw-r--r-- | lib/db/adaptersqlite.php | 6 | ||||
-rw-r--r-- | lib/db/adaptersqlsrv.php | 9 | ||||
-rw-r--r-- | lib/db/connection.php | 9 |
6 files changed, 39 insertions, 2 deletions
diff --git a/lib/db/adapter.php b/lib/db/adapter.php index b0c9aab9c7a..3b83853289a 100644 --- a/lib/db/adapter.php +++ b/lib/db/adapter.php @@ -18,4 +18,8 @@ class Adapter { public function lastInsertId($table) { return $this->conn->realLastInsertId($table); } + + public function fixupStatement($statement) { + return $statement; + } } diff --git a/lib/db/adapteroci8.php b/lib/db/adapteroci8.php index 50c4d078243..6123007cb2f 100644 --- a/lib/db/adapteroci8.php +++ b/lib/db/adapteroci8.php @@ -18,4 +18,11 @@ class AdapterOCI8 extends Adapter { } return $this->conn->lastInsertId($table); } + + public function fixupStatement($statement) { + $statement = str_replace( '`', '"', $statement ); + $statement = str_ireplace( 'NOW()', 'CURRENT_TIMESTAMP', $statement ); + $statement = str_ireplace( 'UNIX_TIMESTAMP()', "(cast(sys_extract_utc(systimestamp) as date) - date'1970-01-01') * 86400", $statement ); + return $statement; + } } diff --git a/lib/db/adapterpgsql.php b/lib/db/adapterpgsql.php index 0084aad470e..acfc4201629 100644 --- a/lib/db/adapterpgsql.php +++ b/lib/db/adapterpgsql.php @@ -13,4 +13,10 @@ class AdapterPgSql extends Adapter { public function lastInsertId($table) { return $this->conn->fetchColumn('SELECT lastval()'); } + + public function fixupStatement($statement) { + $statement = str_replace( '`', '"', $statement ); + $statement = str_ireplace( 'UNIX_TIMESTAMP()', 'cast(extract(epoch from current_timestamp) as integer)', $statement ); + return $statement; + } } diff --git a/lib/db/adaptersqlite.php b/lib/db/adaptersqlite.php index 0b8107ac53e..f0057ab489f 100644 --- a/lib/db/adaptersqlite.php +++ b/lib/db/adaptersqlite.php @@ -10,4 +10,10 @@ namespace OC\DB; class AdapterSqlite extends Adapter { + public function fixupStatement($statement) { + $statement = str_replace( '`', '"', $statement ); + $statement = str_ireplace( 'NOW()', 'datetime(\'now\')', $statement ); + $statement = str_ireplace( 'UNIX_TIMESTAMP()', 'strftime(\'%s\',\'now\')', $statement ); + return $statement; + } } diff --git a/lib/db/adaptersqlsrv.php b/lib/db/adaptersqlsrv.php index 602c70456e5..d0a67af28a7 100644 --- a/lib/db/adaptersqlsrv.php +++ b/lib/db/adaptersqlsrv.php @@ -16,4 +16,13 @@ class AdapterSQLSrv extends Adapter { } return $this->conn->lastInsertId($table); } + + public function fixupStatement($statement) { + $statement = preg_replace( "/\`(.*?)`/", "[$1]", $statement ); + $statement = str_ireplace( 'NOW()', 'CURRENT_TIMESTAMP', $statement ); + $statement = str_replace( 'LENGTH(', 'LEN(', $statement ); + $statement = str_replace( 'SUBSTR(', 'SUBSTRING(', $statement ); + $statement = str_ireplace( 'UNIX_TIMESTAMP()', 'DATEDIFF(second,{d \'1970-01-01\'},GETDATE())', $statement ); + return $statement; + } } diff --git a/lib/db/connection.php b/lib/db/connection.php index c8695b13190..8442efc47c9 100644 --- a/lib/db/connection.php +++ b/lib/db/connection.php @@ -50,6 +50,8 @@ class Connection extends \Doctrine\DBAL\Connection { */ public function prepare( $statement, $limit=null, $offset=null ) { $statement = $this->replaceTablePrefix($statement); + $statement = $this->adapter->fixupStatement($statement); + if ($limit === -1) { $limit = null; } @@ -62,6 +64,9 @@ class Connection extends \Doctrine\DBAL\Connection { } } $rawQuery = $statement; + if(\OC_Config::getValue( "log_query", false)) { + \OC_Log::write('core', 'DB prepare : '.$statement, \OC_Log::DEBUG); + } $result = parent::prepare($statement); if (is_null($limit) && $this->cachingQueryStatementEnabled) { $this->preparedQueries[$rawQuery] = $result; @@ -85,7 +90,7 @@ class Connection extends \Doctrine\DBAL\Connection { public function executeQuery($query, array $params = array(), $types = array(), QueryCacheProfile $qcp = null) { $query = $this->replaceTablePrefix($query); - // TODO: fixup + $query = $this->adapter->fixupStatement($query); return parent::executeQuery($query, $params, $types, $qcp); } @@ -104,7 +109,7 @@ class Connection extends \Doctrine\DBAL\Connection { public function executeUpdate($query, array $params = array(), array $types = array()) { $query = $this->replaceTablePrefix($query); - // TODO: fixup + $query = $this->adapter->fixupStatement($query); return parent::executeUpdate($query, $params, $types); } |