Dotclear

Changeset 3743:07ef48e3d0e5


Ignore:
Timestamp:
03/30/18 00:15:46 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Work in progress, not yet finished

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.selectstatement.php

    r3742 r3743  
    149149        } 
    150150        if (is_array($c)) { 
    151             $c          = array_map(trim(ltrim($c, ',')), $c); // Cope with legacy code 
     151            $filter = function($v) { 
     152                return trim(ltrim($v, ',')); 
     153            }; 
     154            $c          = array_map($filter, $c); // Cope with legacy code 
    152155            $this->from = array_merge($this->from, $c); 
    153156        } else { 
     
    360363 
    361364    /** 
    362      * Escape an identifier 
    363      * 
    364      * @param      string  $identifier  The identifier 
     365     * Escape a value 
     366     * 
     367     * @param      string  $value  The value 
    365368     * 
    366369     * @return     string 
    367370     */ 
    368     public function escape($identifier) 
    369     { 
    370         return $this->con->escape($identifier); 
     371    public function escape($value) 
     372    { 
     373        return $this->con->escape($value); 
    371374    } 
    372375 
     
    394397    { 
    395398        return $this->con->dateFormat($field, $pattern); 
     399    } 
     400 
     401    /** 
     402     * Return an SQL formatted REGEXP clause 
     403     * 
     404     * @param      string  $value  The value 
     405     * 
     406     * @return     string 
     407     */ 
     408    public function regexp($value) 
     409    { 
     410        if ($this->con->driver() == 'mysql' || $this->con->driver() == 'mysqli' || $this->con->driver() == 'mysqlimb4') { 
     411            $clause = "REGEXP '^" . $this->escape(preg_quote($value)) . "[0-9]+$'"; 
     412        } elseif ($this->con->driver() == 'pgsql') { 
     413            $clause = "~ '^" . $this->escape(preg_quote($value)) . "[0-9]+$'"; 
     414        } else { 
     415            $clause = "LIKE '" . 
     416                $sql->escape(preg_replace(array('%', '_', '!'), array('!%', '!_', '!!'), $value)) . 
     417                "%' ESCAPE '!'"; 
     418        } 
     419        return $clause; 
     420    } 
     421 
     422    /** 
     423     * Quote and escape a value if necessary (type string) 
     424     * 
     425     * @param      mixed    $value   The value 
     426     * @param      boolean  $escape  The escape 
     427     * 
     428     * @return     string 
     429     */ 
     430    public function quote($value, $escape = true) 
     431    { 
     432        return 
     433            (is_string($value) ? "'" : '') . 
     434            ($escape ? $this->con->escape($value) : $value) . 
     435            (is_string($value) ? "'" : ''); 
    396436    } 
    397437 
     
    470510        } 
    471511 
    472         return $query; 
     512        return trim($query); 
    473513    } 
    474514 
     
    496536                '\( ' => '(' // (<space> -> ( 
    497537            ); 
    498             foreach ($patterns as $from => $to) { 
    499                 $s = preg_replace('!' . $from . '!', $to, $s); 
     538            foreach ($patterns as $pattern => $replace) { 
     539                $s = preg_replace('!' . $pattern . '!', $replace, $s); 
    500540            } 
    501541            return $s; 
    502542        }; 
    503         return ($filter($local) !== $filter($external)); 
     543        return ($filter($local) === $filter($external)); 
    504544    } 
    505545} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map