developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Ticket #838: 838-jDaoConditions-enclose-field-names.diff

File 838-jDaoConditions-enclose-field-names.diff, 14.4 KB (added by Julien, 12 years ago)
  • lib/jelix/dao/jDaoFactoryBase.class.php

     
    88 * @contributor Thomas, Yoan Blanc
    99 * @copyright   2005-2007 Laurent Jouanneau
    1010 * @copyright   2007 Loic Mathaud
    11  * @copyright   2007-2008 Julien Issler
     11 * @copyright   2007-2009 Julien Issler
    1212 * @copyright   2008 Thomas, 2008 Yoan Blanc
    1313 * @link        http://www.jelix.org
    1414 * @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
     
    111111
    112112    /**
    113113     * informations on all properties
    114      * 
     114     *
    115115     * keys are property name, and values are an array like that :
    116116     * <pre> array (
    117117     *  'name' => 'name of property',
    118118     *  'fieldName' => 'name of fieldname',
    119119     *  'regExp' => NULL, // or the regular expression to test the value
    120      *  'required' => true/false, 
     120     *  'required' => true/false,
    121121     *  'isPK' => true/false, //says if it is a primary key
    122122     *  'isFK' => true/false, //says if it is a foreign key
    123123     *  'datatype' => '', // type of data : string
     
    234234     * jDaoConditions object.
    235235     * you can limit the number of results by given an offset and a count
    236236     * @param jDaoConditions $searchcond
    237      * @param int $limitOffset 
    238      * @param int $limitCount 
     237     * @param int $limitOffset
     238     * @param int $limitCount
    239239     * @return jDbResultSet
    240240     */
    241241    final public function findBy ($searchcond, $limitOffset=0, $limitCount=null){
     
    340340        $order = array ();
    341341        $props =$this->getProperties();
    342342        foreach ($daocond->order as $name => $way){
    343             if (isset($props[$name])){
    344                 $order[] = $name.' '.$way;
    345             }
     343            if (isset($props[$name]))
     344                $order[] = $this->_conn->encloseFieldName($name).' '.$way;
    346345        }
    347346
    348347        if(count ($order)){
     
    358357        $group = array ();
    359358        $props = $this->getProperties();
    360359        foreach ($daocond->group as $name) {
    361             if (isset($props[$name])) {
    362                 $group[] = $name;
    363             }
     360            if (isset($props[$name]))
     361                $group[] = $this->_conn->encloseFieldName($name);
    364362        }
    365363
    366364        if (count ($group)) {
     
    387385            if($forSelect)
    388386                $prefixNoCondition = $this->_tables[$prop['table']]['name'].'.'.$prop['fieldName'];
    389387            else
    390                 $prefixNoCondition = $prop['fieldName'];
     388                $prefixNoCondition = $this->_conn->encloseFieldName($prop['fieldName']);
    391389
    392390            $op = strtoupper($cond['operator']);
    393391            $prefix = $prefixNoCondition.' '.$op.' '; // ' ' for LIKE..
  • lib/jelix/db/jDbConnection.class.php

     
    55* @author      Laurent Jouanneau
    66* @contributor Julien Issler
    77* @copyright   2005-2006 Laurent Jouanneau
    8 * @copyright   2007 Julien Issler
     8* @copyright   2007-2009 Julien Issler
    99*
    1010* This class was get originally from the Copix project (CopixDbConnection, Copix 2.3dev20050901, http://www.copix.org)
    1111* However only few lines of code are still copyrighted 2001-2005 CopixTeam (LGPL licence).
     
    135135    }
    136136
    137137    /**
     138     * enclose the field name
     139     * @param string $fieldName the field name
     140     * @return string the enclosed field name
     141     * @since 1.1
     142     */
     143    public function encloseFieldName($fieldName){
     144        return $fieldName;
     145    }
     146
     147    /**
    138148      * Prefix the given table with the prefix specified in the connection's profile
    139149      * If there's no prefix for the connection's profile, return the table's name unchanged.
    140150      *
  • lib/jelix/plugins/db/mysql/mysql.dbconnection.php

     
    44* @subpackage db_driver
    55* @author     Croes Gérald, Laurent Jouanneau
    66* @contributor Laurent Jouanneau
    7 * @contributor Sylvain de Vathaire
     7* @contributor Sylvain de Vathaire, Julien Issler
    88* @copyright  2001-2005 CopixTeam, 2005-2007 Laurent Jouanneau
     9* @copyright  2009 Julien Issler
    910* This class was get originally from the Copix project (CopixDbConnectionMysql, Copix 2.3dev20050901, http://www.copix.org)
    1011* Few lines of code are still copyrighted 2001-2005 CopixTeam (LGPL licence).
    1112* Initial authors of this Copix class are Gerald Croes and Laurent Jouanneau,
     
    2223 */
    2324class mysqlDbConnection extends jDbConnection {
    2425
    25    protected $_charsets =array( 'UTF-8'=>'utf8', 'ISO-8859-1'=>'latin1');
     26    protected $_charsets =array( 'UTF-8'=>'utf8', 'ISO-8859-1'=>'latin1');
    2627
    27    function __construct($profile){
    28       // à cause du @, on est obligé de tester l'existence de mysql, sinon en cas d'absence
    29       // on a droit à un arret sans erreur
    30       if(!function_exists('mysql_connect')){
    31          throw new jException('jelix~db.error.nofunction','mysql');
    32       }
    33       parent::__construct($profile);
    34    }
     28    function __construct($profile){
     29        // à cause du @, on est obligé de tester l'existence de mysql, sinon en cas d'absence
     30        // on a droit à un arret sans erreur
     31        if(!function_exists('mysql_connect')){
     32            throw new jException('jelix~db.error.nofunction','mysql');
     33        }
     34        parent::__construct($profile);
     35    }
    3536
    36    /**
    37    * begin a transaction
    38    */
    39    public function beginTransaction (){
    40       $this->_doExec ('SET AUTOCOMMIT=0');
    41       $this->_doExec ('BEGIN');
    42    }
     37    /**
     38     * enclose the field name
     39     * @param string $fieldName the field name
     40     * @return string the enclosed field name
     41     * @since 1.1
     42     */
     43    public function encloseFieldName($fieldName){
     44        return '`'.$fieldName.'`';
     45    }
    4346
    44    /**
    45    * Commit since the last begin
    46    */
    47    public function commit (){
    48       $this->_doExec ('COMMIT');
    49       $this->_doExec ('SET AUTOCOMMIT=1');
    50    }
     47    /**
     48    * begin a transaction
     49    */
     50    public function beginTransaction (){
     51        $this->_doExec ('SET AUTOCOMMIT=0');
     52        $this->_doExec ('BEGIN');
     53    }
    5154
    52    /**
    53    * Rollback since the last BEGIN
    54    */
    55    public function rollback (){
    56       $this->_doExec ('ROLLBACK');
    57       $this->_doExec ('SET AUTOCOMMIT=1');
    58    }
     55    /**
     56    * Commit since the last begin
     57    */
     58    public function commit (){
     59        $this->_doExec ('COMMIT');
     60        $this->_doExec ('SET AUTOCOMMIT=1');
     61    }
    5962
    60    /**
    61    *
    62    */
    63    public function prepare ($query){
    64        throw new jException('jelix~db.error.feature.unsupported', array('mysql','prepare'));
    65    }
     63    /**
     64    * Rollback since the last BEGIN
     65    */
     66    public function rollback (){
     67        $this->_doExec ('ROLLBACK');
     68        $this->_doExec ('SET AUTOCOMMIT=1');
     69    }
    6670
    67    public function errorInfo(){
    68       return array( 'HY000' ,mysql_errno($this->_connection), mysql_error($this->_connection));
    69    }
     71    /**
     72    *
     73    */
     74    public function prepare ($query){
     75        throw new jException('jelix~db.error.feature.unsupported', array('mysql','prepare'));
     76    }
    7077
    71    public function errorCode(){
    72       return mysql_errno($this->_connection);
    73    }
     78    public function errorInfo(){
     79        return array( 'HY000' ,mysql_errno($this->_connection), mysql_error($this->_connection));
     80    }
    7481
    75    protected function _connect (){
    76       $funcconnect= ($this->profile['persistent']? 'mysql_pconnect':'mysql_connect');
    77       if($cnx = @$funcconnect ($this->profile['host'], $this->profile['user'], $this->profile['password'])){
    78          if(isset($this->profile['force_encoding']) && $this->profile['force_encoding'] == true
    79             && isset($this->_charsets[$GLOBALS['gJConfig']->charset])){
    80              mysql_query("SET NAMES '".$this->_charsets[$GLOBALS['gJConfig']->charset]."'", $cnx);
    81          }
    82          return $cnx;
    83       }else{
    84          throw new jException('jelix~db.error.connection',$this->profile['host']);
    85       }
    86    }
     82    public function errorCode(){
     83       return mysql_errno($this->_connection);
     84    }
    8785
    88    protected function _disconnect (){
    89       return mysql_close ($this->_connection);
    90    }
     86    protected function _connect (){
     87        $funcconnect= ($this->profile['persistent']? 'mysql_pconnect':'mysql_connect');
     88        if($cnx = @$funcconnect ($this->profile['host'], $this->profile['user'], $this->profile['password'])){
     89            if(isset($this->profile['force_encoding']) && $this->profile['force_encoding'] == true
     90              && isset($this->_charsets[$GLOBALS['gJConfig']->charset])){
     91                mysql_query("SET NAMES '".$this->_charsets[$GLOBALS['gJConfig']->charset]."'", $cnx);
     92            }
     93            return $cnx;
     94        }else{
     95            throw new jException('jelix~db.error.connection',$this->profile['host']);
     96        }
     97    }
    9198
     99    protected function _disconnect (){
     100        return mysql_close ($this->_connection);
     101    }
    92102
    93    protected function _doQuery ($query){
    94        // ici et non lors du connect, pour le cas où il y a plusieurs connexion active
    95       if(!mysql_select_db ($this->profile['database'], $this->_connection)){
    96           if(mysql_errno($this->_connection))
    97               throw new jException('jelix~db.error.database.unknow',$this->profile['database']);
    98           else
    99               throw new jException('jelix~db.error.connection.closed',$this->profile['name']);
    100       }
    101103
    102       if ($qI = mysql_query ($query, $this->_connection)){
    103          return new mysqlDbResultSet ($qI);
    104       }else{
    105          throw new jException('jelix~db.error.query.bad',  mysql_error($this->_connection).'('.$query.')');
    106       }
    107    }
     104    protected function _doQuery ($query){
     105        // ici et non lors du connect, pour le cas où il y a plusieurs connexion active
     106        if(!mysql_select_db ($this->profile['database'], $this->_connection)){
     107            if(mysql_errno($this->_connection))
     108                throw new jException('jelix~db.error.database.unknow',$this->profile['database']);
     109            else
     110                throw new jException('jelix~db.error.connection.closed',$this->profile['name']);
     111        }
    108112
    109    protected function _doExec($query){
    110       if(!mysql_select_db ($this->profile['database'], $this->_connection))
    111          throw new jException('jelix~db.error.database.unknow',$this->profile['database']);
     113        if ($qI = mysql_query ($query, $this->_connection)){
     114            return new mysqlDbResultSet ($qI);
     115        }else{
     116            throw new jException('jelix~db.error.query.bad',  mysql_error($this->_connection).'('.$query.')');
     117        }
     118    }
    112119
    113       if ($qI = mysql_query ($query, $this->_connection)){
    114          return mysql_affected_rows($this->_connection);
    115       }else{
    116          throw new jException('jelix~db.error.query.bad',  mysql_error($this->_connection).'('.$query.')');
    117       }
    118    }
     120    protected function _doExec($query){
     121        if(!mysql_select_db ($this->profile['database'], $this->_connection))
     122            throw new jException('jelix~db.error.database.unknow',$this->profile['database']);
    119123
    120    protected function _doLimitQuery ($queryString, $offset, $number){
    121      $queryString.= ' LIMIT '.$offset.','.$number;
    122      $result = $this->_doQuery($queryString);
    123      return $result;
    124    }
     124        if ($qI = mysql_query ($query, $this->_connection)){
     125            return mysql_affected_rows($this->_connection);
     126        }else{
     127            throw new jException('jelix~db.error.query.bad',  mysql_error($this->_connection).'('.$query.')');
     128        }
     129    }
    125130
     131    protected function _doLimitQuery ($queryString, $offset, $number){
     132        $queryString.= ' LIMIT '.$offset.','.$number;
     133        $result = $this->_doQuery($queryString);
     134        return $result;
     135    }
    126136
    127    public function lastInsertId($fromSequence=''){// on n'a pas besoin de l'argument pour mysql
    128       return mysql_insert_id ();
    129    }
    130137
    131    /**
    132    * tell mysql to be autocommit or not
    133    * @param boolean state the state of the autocommit value
    134    * @return void
    135    */
    136    protected function _autoCommitNotify ($state){
    137       $this->query ('SET AUTOCOMMIT='.$state ? '1' : '0');
    138    }
     138    public function lastInsertId($fromSequence=''){// on n'a pas besoin de l'argument pour mysql
     139        return mysql_insert_id ();
     140    }
    139141
    140    /**
    141     * renvoi une chaine avec les caractères spéciaux échappés
    142     * @access private
     142    /**
     143    * tell mysql to be autocommit or not
     144    * @param boolean state the state of the autocommit value
     145    * @return void
    143146    */
    144    protected function _quote($text){
    145       return mysql_real_escape_string($text,  $this->_connection );
    146    }
     147    protected function _autoCommitNotify ($state){
     148        $this->query ('SET AUTOCOMMIT='.$state ? '1' : '0');
     149    }
    147150
     151    /**
     152     * renvoi une chaine avec les caractères spéciaux échappés
     153     * @access private
     154     */
     155    protected function _quote($text){
     156        return mysql_real_escape_string($text,  $this->_connection );
     157    }
     158
    148159}
    149160
  • lib/jelix/plugins/db/pgsql/pgsql.dbconnection.php

     
    66* @contributor Laurent Jouanneau
    77* @contributor Yannick Le Guédart
    88* @contributor Laurent Raufaste
     9* @contributor Julien Issler
    910* @copyright  2001-2005 CopixTeam, 2005-2007 Laurent Jouanneau, 2007-2008 Laurent Raufaste
     11* @copyright  2009 Julien Issler
    1012* This class was get originally from the Copix project (CopixDBConnectionPostgreSQL, Copix 2.3dev20050901, http://www.copix.org)
    1113* Few lines of code are still copyrighted 2001-2005 CopixTeam (LGPL licence).
    1214* Initial authors of this Copix class are Gerald Croes and Laurent Jouanneau,
     
    3436        }
    3537    }
    3638
     39    /**
     40     * enclose the field name
     41     * @param string $fieldName the field name
     42     * @return string the enclosed field name
     43     * @since 1.1
     44     */
     45    public function encloseFieldName($fieldName){
     46        return '"'.$fieldName.'"';
     47    }
     48
    3749    function __destruct(){
    3850        if(isset($this->profile['single_transaction']) && ($this->profile['single_transaction'])){
    3951            $this->commit();