00001 <?php
00052 class zQuery extends zCore{
00053 var $handle;
00054 var $conAlias;
00055 var $num_rows;
00056 var $affected_rows;
00057 var $raw_exported;
00058 var $lex;
00059
00060 function zQuery($conAlias){
00061 $this->__construct($conAlias);
00062 }
00068 function __construct($conAlias){
00069 global $__ZigOrm;
00070 if(!defined('ZIGORM_Q_SELECT')){define('ZIGORM_Q_SELECT', 's');}
00071 if(!defined('ZIGORM_Q_INSERT')){define('ZIGORM_Q_INSERT', 'i');}
00072 if(!defined('ZIGORM_Q_UPDATE')){define('ZIGORM_Q_UPDATE', 'u');}
00073 if(!defined('ZIGORM_Q_REMOVE')){define('ZIGORM_Q_REMOVE', 'r');}
00074 if(!defined('ZIGORM_Q_SQL')){define('ZIGORM_Q_SQL', 'q');}
00075 if(!defined('ZIGORM_Q_TRUNCATE')){define('ZIGORM_Q_TRUNCATE', 't');}
00076 if(!defined('ZIGORM_NO_FLUSH')){define('ZIGORM_NO_FLUSH', false);}
00077 if(!defined('ZIGORM_FLUSH')){define('ZIGORM_FLUSH', true);}
00078 if(!defined('ZIGORM_NO_QUOTE'))define('ZIGORM_NO_QUOTE', false);
00079 if(!defined('ZIGORM_QUOTE'))define('ZIGORM_QUOTE', true);
00080 if(!defined('ZIGORM_Q_JOIN')){define('ZIGORM_Q_JOIN', 'j');}
00081 if(!defined('ZIGORM_Q_AUTOJOIN')){define('ZIGORM_Q_AUTOJOIN', 'aj');}
00082 if(!defined('ZIGORM_JOIN_CROSS'))define('ZIGORM_JOIN_CROSS', 'jc');
00083 if(!defined('ZIGORM_JOIN_LEFT'))define('ZIGORM_JOIN_LEFT', 'jl');
00084 if(!defined('ZIGORM_JOIN_RIGHT'))define('ZIGORM_JOIN_RIGHT', 'jr');
00085 if(!defined('ZIGORM_JOIN_FULL'))define('ZIGORM_JOIN_FULL', 'jf');
00086 if(!defined('ZIGORM_JOIN_INNER'))define('ZIGORM_JOIN_INNER', 'ji');
00087 if(!defined('ZIGORM_JOIN_NATURAL'))define('ZIGORM_JOIN_NATURAL', 'jn');
00088 if(!defined('ZIGORM_OP_EQUALS'))define('ZIGORM_OP_EQUALS', '=');
00089 if(!defined('ZIGORM_OP_GREATER'))define('ZIGORM_OP_GREATER', '>');
00090 if(!defined('ZIGORM_OP_LESS'))define('ZIGORM_OP_LESS', '<');
00091 if(!defined('ZIGORM_OP_GREATER_EQUALS'))define('ZIGORM_OP_GREATER_EQUALS', '>=');
00092 if(!defined('ZIGORM_OP_LESS_EQUALS'))define('ZIGORM_OP_LESS_EQUALS', '<=');
00093 if(!defined('ZIGORM_OP_NOT_EQUALS'))define('ZIGORM_OP_NOT_EQUALS', '<>');
00094 if(!strlen($this->conAlias))$this->conAlias = $conAlias;
00095 $path = ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.ZIGSETTINGSDIR.DRS.Z_DIR_ETC_CONF.DRS.$conAlias.".con.ini.php";
00096 if(!file_exists($path)){
00097 perror('<code>zigmoyd.dynamicOrm.init</code><br />Failed to parse the connection file '.$conAlias.' as the file doesn\'t exist');
00098 exit;
00099 }
00100 $conData = parse_ini_file($path);
00101 if(!is_object($this->handle)){
00102 switch(trim($conData['driver'])){
00103 case 'mysql':
00104 zLogger::debug("Using Orm driver mysql", 'orm');
00105 include_once(ZIGROOT.DRS.MOD_KEY_NAME_EXPLICIT.DRS.'orm'.DRS.'driver'.DRS.'mysql.php');
00106 $this->handle = new OrmDriver_mysql();
00107 break;
00108 default:
00109 zLogger::error("Using Invalid Driver ".$__ZigOrm->connections[$this->conAlias]->driver, 'orm.');
00110 perror('Invalid Driver '.$__ZigOrm->connections[$this->conAlias]->driver." seleced");
00111 }
00112 }
00113 }
00119 function init(){
00120 $this->num_rows = null;
00121 $this->affected_rows = null;
00122 $this->raw_exported = null;
00123 }
00130 function exec($sqlQuery){
00131 $this->init();
00132 $this->handle->connAlias($this->conAlias);
00133 $this->handle->setCaller(&$this);
00134 $this->handle->sql = $sqlQuery;
00135 $this->handle->connect();
00136 $this->handle->qType(ZIGORM_Q_SQL);
00137 $ret = $this->handle->execute();
00138 $this->num_rows = $this->handle->numRows();
00139 $this->affected_rows = $this->handle->affectedRows();
00140 $this->raw_exported = $this->handle->exportRaw();
00141 return $ret;
00142 }
00148 function export(){
00149 $rowSetClassName = get_class($this).'RowSet';
00150 $ret = array();
00151 if(!is_array($this->raw_exported))return false;
00152 foreach($this->raw_exported as $rowId => $rowObj){
00153 $indx = $rowId;
00154 $ret[$indx] = new $rowSetClassName;
00155 $ret[$indx]->colList = $rowObj->colList;
00156
00157 unset($rowObj);
00158 }
00159 return $ret;
00160 }
00166 function numRows(){
00167 return $this->num_rows;
00168 }
00174 function affectedRows(){
00175 return $this->affected_rows;
00176 }
00177 }
00181 class zQueryRowSet extends zigRowSet{
00182 function zQueryRowSet(){
00183 if(function_exists('overload'))overload(get_class($this));
00184 }
00185 }
00187 ?>