Ticket #293: prefix-dao.patch
| File prefix-dao.patch, 6.0 kB (added by Julien, 1 year ago) |
|---|
-
lib/jelix/db/jDbConnection.class.php
old new 3 3 * @package jelix 4 4 * @subpackage db 5 5 * @author Laurent Jouanneau 6 * @contributor 6 * @contributor Julien Issler 7 7 * @copyright 2005-2006 Laurent Jouanneau 8 * @copyright 2007 Julien Issler 8 9 * 9 10 * This class was get originally from the Copix project (CopixDbConnection, Copix 2.3dev20050901, http://www.copix.org) 10 11 * However only few lines of code are still copyrighted 2001-2005 CopixTeam (LGPL licence). … … 119 120 return "'".$this->_quote ($text)."'"; 120 121 } 121 122 123 122 124 /** 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 /** 123 153 * sets the autocommit state 124 154 * @param boolean state the status of autocommit 125 155 */ -
lib/jelix/dao/jDaoFactoryBase.class.php
old new 4 4 * @subpackage dao 5 5 * @author Laurent Jouanneau 6 6 * @contributor Loic Mathaud 7 * @contributor Julien Issler 7 8 * @copyright 2005-2007 Laurent Jouanneau 8 9 * @copyright 2007 Loic Mathaud 10 * @copyright 2007 Julien Issler 9 11 * @link http://www.jelix.org 10 12 * @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 11 13 */ … … 80 82 */ 81 83 function __construct($conn){ 82 84 $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 83 97 } 84 98 85 99 /** -
lib/jelix/dao/jDaoGenerator.class.php
old new 5 5 * @author Croes GĂ©rald, Laurent Jouanneau 6 6 * @contributor Laurent Jouanneau 7 7 * @contributor Bastien Jaillot (bug fix) 8 * @contributor Julien Issler 8 9 * @copyright 2001-2005 CopixTeam, 2005-2006 Laurent Jouanneau 10 * @copyright 2007 Julien Issler 9 11 * This class was get originally from the Copix project (CopixDAOGeneratorV1, Copix 2.3dev20050901, http://www.copix.org) 10 12 * Few lines of code are still copyrighted 2001-2005 CopixTeam (LGPL licence). 11 13 * Initial authors of this Copix class are Gerald Croes and Laurent Jouanneau, … … 73 75 $sqlSelectClause = $this->_getSelectClause(); 74 76 $pkFields = $this->_getPropertiesBy('PkFields'); 75 77 $pTableRealName = $tables[$this->_datasParser->getPrimaryTable()]['realname']; 76 $pTableRealNameEsc = $this->_encloseName( $pTableRealName);78 $pTableRealNameEsc = $this->_encloseName('\'.$this->_conn->prefixTable(\''.$pTableRealName.'\').\''); 77 79 $pkai = $this->_getAutoIncrementPKField(); 78 80 $sqlPkCondition = $this->_buildSimpleConditions($pkFields); 79 81 if($sqlPkCondition != ''){ … … 108 110 $src[] = ' protected $_tables = '.var_export($tables, true).';'; 109 111 $src[] = ' protected $_primaryTable = \''.$this->_datasParser->getPrimaryTable().'\';'; 110 112 $src[] = ' protected $_selectClause=\''.$sqlSelectClause.'\';'; 111 $src[] = ' protected $_fromClause =\''.$sqlFromClause.'\';';113 $src[] = ' protected $_fromClause;'; 112 114 $src[] = ' protected $_whereClause=\''.$sqlWhereClause.'\';'; 113 115 $src[] = ' protected $_DaoRecordClassName=\''.$this->_DaoRecordClassName.'\';'; 114 116 $src[] = ' protected $_daoSelector = \''.jDaoCompiler::$daoId.'\';'; … … 125 127 $src[] = ' public static $_properties = '.var_export($properties, true).';'; 126 128 $src[] = ' public static $_pkFields = array('.$this->_writeFieldNamesWith ($start = '\'', $end='\'', $beetween = ',', $pkFields).');'; 127 129 130 131 $src[] = ' '; 132 $src[] = 'public function __construct($conn){'; 133 $src[] = ' parent::__construct($conn);'; 134 $src[] = ' $this->_fromClause = \''.$sqlFromClause.'\';'; 135 $src[] = '}'; 136 137 128 138 // cannot put this methods directly into jDaoBase because of a php bug on static methods/properties 129 139 $src[] = ' public function getProperties() { return self::$_properties; }'; 130 140 $src[] = ' public function getPrimaryKeyNames() { return self::$_pkFields;}'; … … 411 421 final protected function _getFromClause(){ 412 422 413 423 $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 414 432 $primarytable = $tables[$this->_datasParser->getPrimaryTable()]; 415 433 $ptrealname = $this->_encloseName($primarytable['realname']); 416 434 $ptname = $this->_encloseName($primarytable['name']);
