コード例 #1
0
ファイル: db.php プロジェクト: noci2012/owncloud
 /**
  * @brief does minor chages to query
  * @param $query Query string
  * @returns corrected query string
  *
  * This function replaces *PREFIX* with the value of $CONFIG_DBTABLEPREFIX
  * and replaces the ` woth ' or " according to the database driver.
  */
 private static function processQuery($query)
 {
     self::connect();
     // We need Database type and table prefix
     if (is_null(self::$type)) {
         self::$type = OC_Config::getValue("dbtype", "sqlite");
     }
     $type = self::$type;
     if (is_null(self::$prefix)) {
         self::$prefix = OC_Config::getValue("dbtableprefix", "oc_");
     }
     $prefix = self::$prefix;
     // differences in escaping of table names ('`' for mysql) and getting the current timestamp
     if ($type == 'sqlite' || $type == 'sqlite3') {
         $query = str_replace('`', '"', $query);
         $query = str_replace('NOW()', 'datetime(\'now\')', $query);
         $query = str_replace('now()', 'datetime(\'now\')', $query);
     } elseif ($type == 'mysql') {
         $query = str_replace('NOW()', 'CURRENT_TIMESTAMP', $query);
         $query = str_replace('now()', 'CURRENT_TIMESTAMP', $query);
     } elseif ($type == 'pgsql') {
         $query = str_replace('`', '"', $query);
         $query = str_replace('NOW()', 'CURRENT_TIMESTAMP', $query);
         $query = str_replace('now()', 'CURRENT_TIMESTAMP', $query);
     }
     // replace table name prefix
     $query = str_replace('*PREFIX*', $prefix, $query);
     return $query;
 }
コード例 #2
0
ファイル: db.php プロジェクト: CDN-Sparks/owncloud
 /**
  * @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 and table prefix
     if (is_null(self::$type)) {
         self::$type = OC_Config::getValue("dbtype", "sqlite");
     }
     $type = self::$type;
     if (is_null(self::$prefix)) {
         self::$prefix = OC_Config::getValue("dbtableprefix", "oc_");
     }
     $prefix = self::$prefix;
     // 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))-TO_DATE(\'1970101000000\',\'YYYYMMDDHH24MiSS\'))*24*3600', $query);
     } elseif ($type == 'mssql') {
         $query = preg_replace("/\\`(.*?)`/", "[\$1]", $query);
         $query = str_replace('NOW()', 'CURRENT_TIMESTAMP', $query);
         $query = str_replace('now()', 'CURRENT_TIMESTAMP', $query);
         $query = str_replace('LENGTH(', 'LEN(', $query);
         $query = str_replace('SUBSTR(', 'SUBSTRING(', $query);
         $query = self::fixLimitClauseForMSSQL($query);
     }
     // replace table name prefix
     $query = str_replace('*PREFIX*', $prefix, $query);
     return $query;
 }