Source for file jDbTools.class.php
Documentation is available at jDbTools.class.php
- <?php
- /**
- * @package jelix
- * @subpackage db
- * @author Croes Gérald, Laurent Jouanneau
- * @contributor Laurent Jouanneau, Gwendal Jouannic, Julien Issler
- * @copyright 2001-2005 CopixTeam, 2005-2010 Laurent Jouanneau
- * @copyright 2008 Gwendal Jouannic
- * @copyright 2008 Julien Issler
- *
- * This class was get originally from the Copix project (CopixDbTools, CopixDbConnection, Copix 2.3dev20050901, http://www.copix.org)
- * Some lines of code are still copyrighted 2001-2005 CopixTeam (LGPL licence).
- * Initial authors of this Copix classes are Gerald Croes and Laurent Jouanneau,
- * and this class was adapted/improved for Jelix by Laurent Jouanneau
- *
- * @link http://www.jelix.org
- * @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
- */
-
- /**
- * Description of a field of a table
- * @package jelix
- * @subpackage db
- * @see jDbTools::getFieldList
- */
- class jDbFieldProperties {
- /**
- * type of the field
- * @var string
- */
- public $type;
-
- /**
- * field name
- * @var string
- */
- public $name;
-
- /**
- * says if the field can be null or not
- * @var boolean
- */
- public $notNull=true;
-
- /**
- * says if the field is the primary key
- * @var boolean
- */
- public $primary=false;
-
- /**
- * says if the field is auto incremented
- * @var boolean
- */
- public $autoIncrement=false;
-
- /**
- * default value
- * @var string
- */
- public $default='';
-
- /**
- * says if there is a default value
- * @var boolean
- */
- public $hasDefault = false;
-
- public $length = 0;
-
- /**
- * if there is a sequence
- * @var string
- */
- public $sequence = false;
- }
-
- /**
- * Provides utilities methods for a database
- * @package jelix
- * @subpackage db
- */
- abstract class jDbTools {
-
- /**
- * the database connector
- * @var jDbConnection
- */
- protected $_connector;
-
- /**
- *
- */
- function __construct( $connector){
- $this->_connector = $connector;
- }
-
- /**
- * returns the table list
- */
- public function getTableList (){
- return $this->_getTableList ();
- }
-
- /**
- * return the field list of a given table
- * @return array array of jDbFieldProperties
- */
- public function getFieldList ($tableName){
- return $this->_getFieldList ($this->_connector->prefixTable($tableName));
- }
-
- abstract protected function _getTableList ();
- abstract protected function _getFieldList ($tableName);
-
- /**
- * regular expression to detect comments and end of query
- */
- protected $dbmsStyle = array('/^\s*#/', '/;\s*$/');
-
- public function execSQLScript ($file) {
- if(!isset($this->_connector->profile['table_prefix']))
- $prefix = '';
- else
- $prefix = $this->_connector->profile['table_prefix'];
-
- $lines = file($file);
- $cmdSQL = '';
- $nbCmd = 0;
-
- $style=$this->dbmsStyle;
-
- foreach ((array)$lines as $key=>$line) {
- if ((!preg_match($style[0],$line))&&(strlen(trim($line))>0)) { // la ligne n'est ni vide ni commentaire
- //$line = str_replace("\\'","''",$line);
- //$line = str_replace($this->scriptReplaceFrom, $this->scriptReplaceBy,$line);
-
- $cmdSQL.=$line;
-
- if (preg_match($style[1],$line)) {
- //Si on est à la ligne de fin de la commande on l'execute
- // On nettoie la commande du ";" de fin et on l'execute
- $cmdSQL = preg_replace($style[1],'',$cmdSQL);
- $cmdSQL = str_replace('%%PREFIX%%', $prefix, $cmdSQL);
- $this->_connector->query ($cmdSQL);
- $nbCmd++;
- $cmdSQL = '';
- }
- }
- }
- return $nbCmd;
- }
- }
Documentation generated on Thu, 22 Mar 2012 22:15:22 +0100 by phpDocumentor 1.4.3