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 #293: prefix-dao.patch

File prefix-dao.patch, 6.0 KB (added by Julien, 13 years ago)

Nouveau patch

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

     
    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   
    122124    /**
     125      * Prefix the given table with the prefix specified in the connection's profile
     126      * If there's no prefix for the connection's profile, return the table's name unchanged.
     127      *
     128      * @param string $table the table's name
     129      * @return string the prefixed table's name
     130      * @author Julien Issler
     131      **/
     132    public function prefixTable($table_name){
     133        if(!isset($this->profil['table_prefix']))
     134            return $table_name;
     135        return $this->profil['table_prefix'].$table_name;
     136    }
     137   
     138   
     139    /**
     140      * Check if the current connection has a table prefix set
     141      *
     142      * @return boolean
     143      * @author Julien Issler
     144      **/
     145    public function hasTablePrefix(){
     146        return isset($this->profil['table_prefix']);
     147    }
     148   
     149   
     150   
     151   
     152    /**
    123153    * sets the autocommit state
    124154    * @param boolean state the status of autocommit
    125155    */
  • lib/jelix/dao/jDaoFactoryBase.class.php

     
    44 * @subpackage  dao
    55 * @author      Laurent Jouanneau
    66 * @contributor Loic Mathaud
     7 * @contributor Julien Issler
    78 * @copyright   2005-2007 Laurent Jouanneau
    89 * @copyright   2007 Loic Mathaud
     10 * @copyright   2007 Julien Issler
    911 * @link        http://www.jelix.org
    1012 * @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
    1113 */
     
    8082     */
    8183    function  __construct($conn){
    8284        $this->_conn = $conn;
     85       
     86        if($this->_conn->hasTablePrefix()){
     87            $tables = array();
     88            foreach($this->_tables as $table_name=>$table){
     89                $table['realname'] = $this->_conn->prefixTable($table['realname']);
     90                $tables[$table_name] = $table;
     91            }
     92            $this->_tables = $tables;           
     93        }
     94               
     95       
     96       
    8397    }
    8498
    8599    /**
  • lib/jelix/dao/jDaoGenerator.class.php

     
    55* @author     Croes Gérald, Laurent Jouanneau
    66* @contributor Laurent Jouanneau
    77* @contributor Bastien Jaillot (bug fix)
     8* @contributor Julien Issler
    89* @copyright  2001-2005 CopixTeam, 2005-2006 Laurent Jouanneau
     10* @copyright  2007 Julien Issler
    911* This class was get originally from the Copix project (CopixDAOGeneratorV1, Copix 2.3dev20050901, http://www.copix.org)
    1012* Few lines of code are still copyrighted 2001-2005 CopixTeam (LGPL licence).
    1113* Initial authors of this Copix class are Gerald Croes and Laurent Jouanneau,
     
    7375      $sqlSelectClause   = $this->_getSelectClause();
    7476      $pkFields          = $this->_getPropertiesBy('PkFields');
    7577      $pTableRealName    = $tables[$this->_datasParser->getPrimaryTable()]['realname'];
    76       $pTableRealNameEsc = $this->_encloseName($pTableRealName);
     78      $pTableRealNameEsc = $this->_encloseName('\'.$this->_conn->prefixTable(\''.$pTableRealName.'\').\'');
    7779      $pkai              = $this->_getAutoIncrementPKField();
    7880      $sqlPkCondition    = $this->_buildSimpleConditions($pkFields);
    7981      if($sqlPkCondition != ''){
     
    108110      $src[] = '   protected $_tables = '.var_export($tables, true).';';
    109111      $src[] = '   protected $_primaryTable = \''.$this->_datasParser->getPrimaryTable().'\';';
    110112      $src[] = '   protected $_selectClause=\''.$sqlSelectClause.'\';';
    111       $src[] = '   protected $_fromClause=\''.$sqlFromClause.'\';';
     113      $src[] = '   protected $_fromClause;';
    112114      $src[] = '   protected $_whereClause=\''.$sqlWhereClause.'\';';
    113115      $src[] = '   protected $_DaoRecordClassName=\''.$this->_DaoRecordClassName.'\';';
    114116      $src[] = '   protected $_daoSelector = \''.jDaoCompiler::$daoId.'\';';
     
    125127      $src[] = '   public static $_properties = '.var_export($properties, true).';';
    126128      $src[] = '   public static $_pkFields = array('.$this->_writeFieldNamesWith ($start = '\'', $end='\'', $beetween = ',', $pkFields).');';
    127129
     130
     131      $src[] = ' ';
     132      $src[] = 'public function __construct($conn){';
     133      $src[] = '   parent::__construct($conn);';
     134      $src[] = '   $this->_fromClause = \''.$sqlFromClause.'\';';
     135      $src[] = '}';
     136
     137
    128138      // cannot put this methods directly into jDaoBase because of a php bug on static methods/properties
    129139      $src[] = '   public function getProperties() { return self::$_properties; }';
    130140      $src[] = '   public function getPrimaryKeyNames() { return self::$_pkFields;}';
     
    411421    final protected function _getFromClause(){
    412422
    413423      $tables = $this->_datasParser->getTables();
     424     
     425      $prefixed_tables = array();
     426      foreach($tables as $table_name => $table){
     427         $table['realname'] = '\'.$this->_conn->prefixTable(\''.$table['realname'].'\').\'';
     428         $prefixed_tables[$table_name] = $table;
     429      }
     430      $tables = $prefixed_tables;
     431     
    414432      $primarytable = $tables[$this->_datasParser->getPrimaryTable()];
    415433      $ptrealname = $this->_encloseName($primarytable['realname']);
    416434      $ptname = $this->_encloseName($primarytable['name']);