Ticket #293: patch-prefixed-sql-tables.patch

File patch-prefixed-sql-tables.patch, 3.9 kB (added by Julien, 1 year ago)

jDb and jDao : SQL table's prefix

  • lib/jelix/db/jDbConnection.class.php

    old new  
    33* @package     jelix 
    44* @subpackage  db 
    55* @author      Laurent Jouanneau 
    6 * @contributor 
     6* @contributor Julien Issler 
    77* @copyright   2005-2006 Laurent Jouanneau 
     8* @copyright   2007 Julien Issler 
    89* 
    910* This class was get originally from the Copix project (CopixDbConnection, Copix 2.3dev20050901, http://www.copix.org) 
    1011* However only few lines of code are still copyrighted 2001-2005 CopixTeam (LGPL licence). 
     
    119120           return "'".$this->_quote ($text)."'"; 
    120121    } 
    121122 
     123        /** 
     124         * Prefix the given table with the prefix specified in the connection's profile 
     125         * If there's no prefix for the connection's profile, return the table's name unchanged. 
     126         * 
     127         * @param string $table the table's name 
     128         * @return string the prefixed table's name 
     129         * @author Julien Issler 
     130         **/ 
     131        public function prefixTable($table_name){ 
     132                if(!isset($this->profil['table_prefix'])) 
     133                        return $table_name; 
     134                return $this->profil['table_prefix'].$table_name; 
     135        } 
     136 
    122137    /** 
    123138    * sets the autocommit state 
    124139    * @param boolean state the status of autocommit 
  • lib/jelix/dao/jDaoParser.class.php

    old new  
    160160        } 
    161161 
    162162        $infos['fields'] = array (); 
     163 
     164                $infos['realname'] = '\'.$this->_conn->profil[\'table_prefix\'].\''.$infos['realname']; 
     165 
    163166        $this->_tables[$infos['name']] = $infos; 
    164167 
     168 
    165169        return $infos; 
    166170    } 
    167171 
  • lib/jelix/dao/jDaoGenerator.class.php

    old new  
    33* @package    jelix 
    44* @subpackage dao 
    55* @author     Croes GĂ©rald, Laurent Jouanneau 
    6 * @contributor Laurent Jouanneau 
     6* @contributor Laurent Jouanneau, Julien Issler 
    77* @contributor Bastien Jaillot (bug fix) 
    88* @copyright  2001-2005 CopixTeam, 2005-2006 Laurent Jouanneau 
     9* @copyright 2007 Julien Issler 
    910* This class was get originally from the Copix project (CopixDAOGeneratorV1, 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, 
     
    101102      $src[] = '   protected $_tables = '.var_export($tables, true).';'; 
    102103      $src[] = '   protected $_primaryTable = \''.$this->_datasParser->getPrimaryTable().'\';'; 
    103104      $src[] = '   protected $_selectClause=\''.$sqlSelectClause.'\';'; 
    104       $src[] = '   protected $_fromClause=\''.$sqlFromClause.'\';'; 
     105      $src[] = '   protected $_fromClause;'; 
    105106      $src[] = '   protected $_whereClause=\''.$sqlWhereClause.'\';'; 
    106107      $src[] = '   protected $_DaoRecordClassName=\''.$this->_DaoRecordClassName.'\';'; 
    107108      $src[] = '   public static $_properties = '.var_export($properties, true).';'; 
    108109      $src[] = '   public static $_pkFields = array('.$this->_writeFieldNamesWith ($start = '\'', $end='\'', $beetween = ',', $pkFields).');'; 
    109110 
     111 
     112          $src[] = '   public function __construct($conn){'; 
     113          $src[] = '       parent::__construct($conn);'; 
     114          $src[] = '       if(!isset($this->_conn->profil[\'table_prefix\'])) $this->_conn->profil[\'table_prefix\']=\'\';'; 
     115          $src[] = '       $this->_fromClause=\''.$sqlFromClause.'\';'; 
     116          $src[] = '   }'; 
     117 
    110118      // cannot put this methods directly into jDaoBase because of a php bug on static methods/properties 
    111119      $src[] = '   public function getProperties() { return self::$_properties; }'; 
    112120      $src[] = '   public function getPrimaryKeyNames() { return self::$_pkFields;}'; 
Download in other formats: Original Format