|
|
|
@ -213,11 +213,6 @@ class OC_DB { |
|
|
|
* SQL query via Doctrine prepare(), needs to be execute()'d! |
|
|
|
*/ |
|
|
|
static public function prepare( $query , $limit = null, $offset = null, $isManipulation = null) { |
|
|
|
// Optimize the query
|
|
|
|
$query = self::processQuery( $query ); |
|
|
|
if(OC_Config::getValue( "log_query", false)) { |
|
|
|
OC_Log::write('core', 'DB prepare : '.$query, OC_Log::DEBUG); |
|
|
|
} |
|
|
|
self::connect(); |
|
|
|
|
|
|
|
if ($isManipulation === null) { |
|
|
|
@ -448,49 +443,6 @@ class OC_DB { |
|
|
|
return $result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief does minor changes to query |
|
|
|
* @param string $query Query string |
|
|
|
* @return string corrected query string |
|
|
|
* |
|
|
|
* This function replaces *PREFIX* with the value of $CONFIG_DBTABLEPREFIX |
|
|
|
* and replaces the ` with ' or " according to the database driver.
|
|
|
|
*/ |
|
|
|
private static function processQuery( $query ) { |
|
|
|
self::connect(); |
|
|
|
// We need Database type
|
|
|
|
if(is_null(self::$type)) { |
|
|
|
self::$type=OC_Config::getValue( "dbtype", "sqlite" ); |
|
|
|
} |
|
|
|
$type = self::$type; |
|
|
|
|
|
|
|
// differences in escaping of table names ('`' for mysql) and getting the current timestamp
|
|
|
|
if( $type == 'sqlite' || $type == 'sqlite3' ) { |
|
|
|
$query = str_replace( '`', '"', $query ); |
|
|
|
$query = str_ireplace( 'NOW()', 'datetime(\'now\')', $query ); |
|
|
|
$query = str_ireplace( 'UNIX_TIMESTAMP()', 'strftime(\'%s\',\'now\')', $query ); |
|
|
|
} elseif( $type == 'pgsql' ) { |
|
|
|
$query = str_replace( '`', '"', $query ); |
|
|
|
$query = str_ireplace( 'UNIX_TIMESTAMP()', 'cast(extract(epoch from current_timestamp) as integer)', |
|
|
|
$query ); |
|
|
|
} elseif( $type == 'oci' ) { |
|
|
|
$query = str_replace( '`', '"', $query ); |
|
|
|
$query = str_ireplace( 'NOW()', 'CURRENT_TIMESTAMP', $query ); |
|
|
|
$query = str_ireplace( 'UNIX_TIMESTAMP()', "(cast(sys_extract_utc(systimestamp) as date) - date'1970-01-01') * 86400", $query ); |
|
|
|
}elseif( $type == 'mssql' ) { |
|
|
|
$query = preg_replace( "/\`(.*?)`/", "[$1]", $query ); |
|
|
|
$query = str_ireplace( 'NOW()', 'CURRENT_TIMESTAMP', $query ); |
|
|
|
$query = str_replace( 'LENGTH(', 'LEN(', $query ); |
|
|
|
$query = str_replace( 'SUBSTR(', 'SUBSTRING(', $query ); |
|
|
|
$query = str_ireplace( 'UNIX_TIMESTAMP()', 'DATEDIFF(second,{d \'1970-01-01\'},GETDATE())', $query ); |
|
|
|
} |
|
|
|
|
|
|
|
return $query; |
|
|
|
} |
|
|
|
|
|
|
|
return $query; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief drop a table |
|
|
|
* @param string $tableName the table to drop |
|
|
|
|