Changeset 5104
- Timestamp:
- 10/16/08 22:25:25 (9 months ago)
- Location:
- branches/1.0/lib/Doctrine/Adapter
- Files:
-
- 2 modified
-
Oracle.php (modified) (11 diffs)
-
Statement/Oracle.php (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.0/lib/Doctrine/Adapter/Oracle.php
r5082 r5104 26 26 * @subpackage Adapter 27 27 * @author Konsta Vesterinen <kvesteri@cc.hut.fi> 28 * @author vadik56 29 * @author Miloslav Kmet <adrive-nospam@hip-hop.sk> 28 30 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL 29 31 * @link www.phpdoctrine.org … … 33 35 34 36 class Doctrine_Adapter_Oracle implements Doctrine_Adapter_Interface{ 35 /** 36 * execution mode 37 */ 38 protected $_executeMode = OCI_COMMIT_ON_SUCCESS; 39 40 /** 41 * Resource representing connection to database 42 */ 43 protected $_connection = false; 44 45 46 protected $_attributes = array( Doctrine::ATTR_DRIVER_NAME => "oci8", 47 Doctrine::ATTR_ERRMODE => Doctrine::ERRMODE_SILENT, 48 ); 49 50 /** 51 * User-provided configuration. 52 * 53 * Basic keys are: 54 * 55 * username => (string) Connect to the database as this username. 56 * password => (string) Password associated with the username. 57 * dbname => Either the name of the local Oracle instance, or the 58 * name of the entry in tnsnames.ora to which you want to connect. 59 * 60 * @var array 61 */ 62 protected $_config = array( 63 'dbname' => null, 64 'username' => null, 65 'password' => null, 66 'charset' => null, 67 ); 37 /** 38 * execution mode 39 */ 40 protected $executeMode = OCI_COMMIT_ON_SUCCESS; 41 42 /** 43 * Resource representing connection to database 44 */ 45 protected $connection = false; 46 47 48 protected $attributes = array(Doctrine::ATTR_DRIVER_NAME => "oci8", 49 Doctrine::ATTR_ERRMODE => Doctrine::ERRMODE_SILENT); 50 51 /** 52 * User-provided configuration. 53 * 54 * Basic keys are: 55 * 56 * username => (string) Connect to the database as this username. 57 * password => (string) Password associated with the username. 58 * dbname => Either the name of the local Oracle instance, or the 59 * name of the entry in tnsnames.ora to which you want to connect. 60 * 61 * @var array 62 */ 63 protected $config = array('dbname' => null, 64 'username' => null, 65 'password' => null, 66 'charset' => null); 68 67 69 68 /** … … 77 76 * @return void 78 77 */ 79 public function __construct($config = array()){ 80 if ( ! isset($config['password']) || ! isset($config['username'])) { 81 throw new Doctrine_Adapter_Exception('config array must have at least a username and a password'); 82 } 83 84 $this->_config['username'] = $config['username']; 85 $this->_config['password'] = $config['password']; 86 $this->_config['dbname'] = $config['dbname']; 87 $this->_config['charset'] = $config['charset']; 88 } 89 90 private function connect(){ 91 92 $this->_connection = @oci_connect($this->_config['username'], $this->_config['password'], $this->_config['dbname'], $this->_config['charset'] ); 93 94 if( $this->_connection === false){ 95 throw new Exception(sprintf("Unable to Connect to :'%s' as '%s'", $this->_config['dbname'], $this->_config['username'])); 96 } 97 } 78 public function __construct($config = array()) 79 { 80 if ( ! isset($config['password']) || ! isset($config['username'])) { 81 throw new Doctrine_Adapter_Exception('config array must have at least a username and a password'); 82 } 83 84 $this->config['username'] = $config['username']; 85 $this->config['password'] = $config['password']; 86 $this->config['dbname'] = $config['dbname']; 87 $this->config['charset'] = $config['charset']; 88 } 89 /** 90 * Connect to a database 91 * @throws Doctrine_Adapter_Exception 92 * @return void 93 */ 94 private function connect() 95 { 96 $this->connection = @oci_connect($this->config['username'], $this->config['password'], 97 $this->config['dbname'], $this->config['charset']); 98 99 if ($this->connection === false) { 100 throw new Doctrine_Adapter_Exception(sprintf("Unable to Connect to :'%s' as '%s'", $this->config['dbname'], $this->config['username'])); 101 } 102 } 103 98 104 /** 99 105 * Prepare a query statement … … 102 108 * @return Doctrine_Adapter_Statement_Oracle $stmt prepared statement 103 109 */ 104 public function prepare($query) {105 if($this->_connection ===false){106 $this->connect();107 }108 $oci_stmt = $this->parseQuery($query);109 $stmt = new Doctrine_Adapter_Statement_Oracle($this, $oci_stmt, $this->_executeMode); 110 //$stmt->queryString = $query;110 public function prepare($query) 111 { 112 if ($this->connection ===false) { 113 $this->connect(); 114 } 115 116 $stmt = new Doctrine_Adapter_Statement_Oracle($this, $query, $this->executeMode); 111 117 112 118 return $stmt; … … 119 125 * @return Doctrine_Adapter_Statement_Oracle $stmt 120 126 */ 121 public function query($query){ 122 if($this->_connection ===false){ 123 $this->connect(); 124 } 125 126 $resource = $this->parseQuery($query); 127 128 $stmt = new Doctrine_Adapter_Statement_Oracle($this, $resource,$this->_executeMode); 127 public function query($query) 128 { 129 if ($this->connection ===false) { 130 $this->connect(); 131 } 132 133 $stmt = new Doctrine_Adapter_Statement_Oracle($this, $query, $this->executeMode); 129 134 $stmt->execute(); 130 135 131 136 return $stmt; 132 137 } 133 private function parseQuery($query){134 135 $bind_index = 0;136 137 /*138 * Replace ? bind-placeholders with :bind_var_ variables139 */140 141 $query = preg_replace("/(\?)/e", '":oci_b_var_". $bind_index++' , $query);142 //print $query.PHP_EOL;143 $resource = @oci_parse ( $this->_connection , $query );144 145 if( $resource === false){146 //TODO handle error147 print "error in parseQuery";148 }149 150 return $resource;151 }152 138 153 139 /** … … 170 156 public function exec($statement) 171 157 { 172 if($this->_connection ===false){ 173 $this->connect(); 174 } 175 $resource = $this->parseQuery($statement); 176 177 $stmt = new Doctrine_Adapter_Statement_Oracle($this, $resource, $this->_executeMode); 158 if ($this->connection ===false) { 159 $this->connect(); 160 } 161 162 $stmt = new Doctrine_Adapter_Statement_Oracle($this, $statement, $this->executeMode); 178 163 $stmt->execute(); 179 164 $count = $stmt->rowCount(); 180 165 181 166 return $count; 182 167 } … … 187 172 * @return integer $id 188 173 */ 189 public function lastInsertId(){ 190 throw new Exception("unsupported"); 174 public function lastInsertId() 175 { 176 throw new Exception("unsupported"); 191 177 } 192 178 … … 207 193 * @return void 208 194 */ 209 public function commit(){ 210 if($this->_connection ===false){ 211 $this->connect(); 212 } 213 return @oci_commit($this->_connection); 195 public function commit() 196 { 197 if ($this->connection ===false) { 198 $this->connect(); 199 } 200 201 return @oci_commit($this->connection); 214 202 } 215 203 … … 219 207 * @return boolean 220 208 */ 221 public function rollBack(){ 222 if($this->_connection ===false){ 223 $this->connect(); 224 } 225 return @oci_rollback($this->_connection); 226 } 227 228 /** 209 public function rollBack() 210 { 211 if ($this->connection ===false) { 212 $this->connect(); 213 } 214 return @oci_rollback($this->connection); 215 } 216 217 /** 229 218 * Set connection attribute 230 219 * … … 233 222 * @return boolean Returns TRUE on success or FALSE on failure. 234 223 */ 235 public function setAttribute($attribute, $value){ 236 switch($attribute){ 237 case Doctrine::ATTR_DRIVER_NAME: 238 //TODO throw an error since driver name can not be changed 239 case Doctrine::ATTR_ERRMODE: 240 break; 241 case Doctrine::ATTR_CASE: 242 if($value == Doctrine::CASE_NATURAL){ 243 break; 244 }else{ 245 throw new Doctrine_Adapter_Exception("Unsupported Option for ATTR_CASE: $value"); 246 } 247 default: 248 throw new Doctrine_Adapter_Exception("Unsupported Attribute: $attribute"); 249 return false; 250 } 251 $this->_attributes[$attribute] = $value; 252 return true; 253 } 254 255 /** 224 public function setAttribute($attribute, $value) 225 { 226 switch ($attribute) { 227 case Doctrine::ATTR_DRIVER_NAME: 228 //TODO throw an error since driver name can not be changed 229 case Doctrine::ATTR_ERRMODE: 230 break; 231 case Doctrine::ATTR_CASE: 232 if ($value == Doctrine::CASE_NATURAL) { 233 break; 234 } else { 235 throw new Doctrine_Adapter_Exception("Unsupported Option for ATTR_CASE: $value"); 236 } 237 default: 238 throw new Doctrine_Adapter_Exception("Unsupported Attribute: $attribute"); 239 return false; 240 } 241 $this->attributes[$attribute] = $value; 242 return true; 243 } 244 245 /** 256 246 * Retrieve a statement attribute 257 247 * … … 260 250 * @return mixed the attribute value 261 251 */ 262 public function getAttribute($attribute){ 263 return $this->_attributes[$attribute]; 252 public function getAttribute($attribute) 253 { 254 return $this->attributes[$attribute]; 255 } 256 257 /** 258 * Returns established OCI connection handler 259 * 260 * @return resource OCI connection handler 261 */ 262 public function getConnection() 263 { 264 return $this->connection; 264 265 } 265 266 266 public function errorCode(){ 267 if( is_resource($this->_connection)){ 268 $error = @oci_error($this->_connection); 269 }else{ 270 $error = @oci_error(); 271 } 272 return $error['code']; 273 } 274 275 public function errorInfo(){ 276 if( is_resource($this->_connection)){ 277 $error = @oci_error($this->_connection); 278 }else{ 279 $error = @oci_error(); 280 } 281 return $error['message']; 282 } 283 267 public function errorCode() 268 { 269 if (is_resource($this->connection)) { 270 $error = @oci_error($this->connection); 271 } else { 272 $error = @oci_error(); 273 } 274 return $error['code']; 275 } 276 277 public function errorInfo() 278 { 279 if (is_resource($this->connection)) { 280 $error = @oci_error($this->connection); 281 } else { 282 $error = @oci_error(); 283 } 284 return $error['message']; 285 } 284 286 } -
branches/1.0/lib/Doctrine/Adapter/Statement/Oracle.php
r5082 r5104 26 26 * @subpackage Adapter 27 27 * @author Konsta Vesterinen <kvesteri@cc.hut.fi> 28 * @author vadik56 29 * @author Miloslav Kmet <adrive-nospam@hip-hop.sk> 28 30 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL 29 31 * @link www.phpdoctrine.org … … 31 33 * @version $Rev$ 32 34 */ 33 class Doctrine_Adapter_Statement_Oracle implements Doctrine_Adapter_Statement_Interface{ 34 protected $_connection; 35 protected $_statement; 36 protected $_executeMode = OCI_COMMIT_ON_SUCCESS; 37 protected $_bind_params = array(); 38 protected $_attributes = array(); 39 //array of errors 40 protected $_oci_errors = array(); 41 42 function __construct( Doctrine_Adapter_Oracle $connection, $statement, $executeMode){ 43 $this->_connection = $connection; 44 $this->_statement = $statement; 45 $this->_executeMode = $executeMode; 46 $this->_attributes[Doctrine::ATTR_ERRMODE] = $connection->getAttribute(Doctrine::ATTR_ERRMODE); 47 } 35 class Doctrine_Adapter_Statement_Oracle implements Doctrine_Adapter_Statement_Interface 36 { 37 /** 38 * @var string $queryString actual query string 39 */ 40 public $queryString; 41 42 /** 43 * @var resource $connection OCI connection handler 44 */ 45 protected $connection; 46 47 /** 48 * @var resource $statement OCI prepared statement 49 */ 50 protected $statement; 51 52 /** 53 * @var integer $executeMode OCI statement execution mode 54 */ 55 protected $executeMode = OCI_COMMIT_ON_SUCCESS; 56 57 /** 58 * @var array $bind_params Array of parameters bounded to a statement 59 */ 60 protected $bindParams = array(); 61 62 /** 63 * @var array $attributes Array of attributes 64 */ 65 protected $attributes = array(); 66 67 /** 68 * @var array $ociErrors Array of errors 69 */ 70 protected $ociErrors = array(); 71 72 /** 73 * the constructor 74 * 75 * @param Doctrine_Adapter_Oracle $connection 76 * @param string $query Query string to be executed 77 * @param integer $executeMode OCI execute mode 78 */ 79 public function __construct( Doctrine_Adapter_Oracle $connection, $query, $executeMode) 80 { 81 $this->connection = $connection->getConnection(); 82 $this->queryString = $query; 83 $this->executeMode = $executeMode; 84 $this->attributes[Doctrine::ATTR_ERRMODE] = $connection->getAttribute(Doctrine::ATTR_ERRMODE); 85 86 $this->parseQuery(); 87 } 88 48 89 /** 49 90 * Bind a column to a PHP variable … … 56 97 * @return boolean Returns TRUE on success or FALSE on failure 57 98 */ 58 public function bindColumn($column, $param, $type = null){ 59 throw new Exception("Unsupported"); 99 public function bindColumn($column, $param, $type = null) 100 { 101 throw new Exception("Unsupported"); 60 102 } 61 103 … … 74 116 */ 75 117 public function bindValue($param, $value, $type = null){ 76 /**77 * need to store the value internally since binding is done by reference78 */79 $this->_bind_params[] = $value;80 $this->bindParam($param, $this->_bind_params[count($this->_bind_params) - 1], $type);118 /** 119 * need to store the value internally since binding is done by reference 120 */ 121 $this->bindParams[] = $value; 122 $this->bindParam($param, $this->bindParams[count($this->bindParams) - 1], $type); 81 123 } 82 124 … … 108 150 */ 109 151 public function bindParam($column, &$variable, $type = null, $length = null, $driverOptions = array()){ 110 if($driverOptions || $length ){111 throw new Doctrine_Adapter_Exception('Unsupported parameters:$length, $driverOptions');112 }113 114 if($length === null){115 $oci_length = -1;116 }117 $oci_type = SQLT_CHR;118 119 switch($type){120 case Doctrine::PARAM_STR:121 $oci_type = SQLT_CHR;122 break;123 }124 125 if(is_integer($column)){126 $variable_name = ":oci_b_var_$column";127 }else{128 $variable_name = $column;129 }130 //print "Binding $variable to $variable_name".PHP_EOL;131 $status = @oci_bind_by_name($this->_statement, $variable_name, $variable, $oci_length, $oci_type);132 if($status === false){133 $this->handleError();134 }135 return $status;152 if ($driverOptions || $length ) { 153 throw new Doctrine_Adapter_Exception('Unsupported parameters:$length, $driverOptions'); 154 } 155 156 if ($length === null) { 157 $oci_length = -1; 158 } 159 $oci_type = SQLT_CHR; 160 161 switch ($type) { 162 case Doctrine::PARAM_STR: 163 $oci_type = SQLT_CHR; 164 break; 165 } 166 167 if (is_integer($column)) { 168 $variable_name = ":oci_b_var_$column"; 169 } else { 170 $variable_name = $column; 171 } 172 //print "Binding $variable to $variable_name".PHP_EOL; 173 $status = @oci_bind_by_name($this->statement, $variable_name, $variable, $oci_length, $oci_type); 174 if($status === false){ 175 $this->handleError(); 176 } 177 return $status; 136 178 } 137 179 … … 142 184 */ 143 185 public function closeCursor(){ 144 $this->_bind_params = array();145 return oci_free_statement($this->_statement);186 $this->bind_params = array(); 187 return oci_free_statement($this->statement); 146 188 } 147 189 … … 154 196 */ 155 197 public function columnCount(){ 156 return oci_num_fields ( $this->_statement );198 return oci_num_fields ( $this->statement ); 157 199 } 158 200 … … 164 206 */ 165 207 public function errorCode(){ 166 $oci_error = $this->getOciError();167 return $oci_error['code'];208 $oci_error = $this->getOciError(); 209 return $oci_error['code']; 168 210 } 169 211 … … 175 217 */ 176 218 public function errorInfo(){ 177 $oci_error = $this->getOciError(); 178 return $oci_error['message'] . " : " . $oci_error['sqltext']; 179 } 180 private function getOciError(){ 181 if( is_resource($this->_statement) ){ 182 $oci_error = oci_error ( $this->_statement ); 183 }else{ 184 $oci_error = oci_error (); 185 } 186 187 if($oci_error){ 188 //store the error 189 $this->_oci_errors[] = $oci_error; 190 }else if(count($this->_oci_errors) > 0){ 191 $oci_error = $this->_oci_errors[count($this->_oci_errors)-1]; 192 } 193 return $oci_error; 219 $oci_error = $this->getOciError(); 220 return $oci_error['message'] . " : " . $oci_error['sqltext']; 221 } 222 private function getOciError() 223 { 224 if (is_resource($this->statement)) { 225 $oci_error = oci_error ($this->statement); 226 } else { 227 $oci_error = oci_error (); 228 } 229 230 if ($oci_error) { 231 //store the error 232 $this->oci_errors[] = $oci_error; 233 } else if (count($this->ociErrors) > 0) { 234 $oci_error = $this->ociErrors[count($this->ociErrors)-1]; 235 } 236 return $oci_error; 194 237 } 195 238 … … 208 251 * @return boolean Returns TRUE on success or FALSE on failure. 209 252 */ 210 public function execute($params = null) {211 212 if(is_array($params)){213 foreach ($params as $var => $value){214 $this->bindValue($var, $value);215 }216 }217 218 $result = @oci_execute($this->_statement , $this->_executeMode );219 220 if($result === false){221 $this->handleError();222 return false;223 }224 return true;253 public function execute($params = null) 254 { 255 if (is_array($params)) { 256 foreach ($params as $var => $value) { 257 $this->bindValue($var, $value); 258 } 259 } 260 261 $result = @oci_execute($this->statement , $this->executeMode ); 262 263 if ($result === false) { 264 $this->handleError(); 265 return false; 266 } 267 return true; 225 268 } 226 269 … … 252 295 * @return mixed 253 296 */ 254 public function fetch($fetchStyle = Doctrine::FETCH_BOTH, $cursorOrientation = Doctrine::FETCH_ORI_NEXT, $cursorOffset = null) {255 256 switch($fetchStyle){257 case Doctrine::FETCH_BOTH :258 return oci_fetch_array($this->_statement, OCI_BOTH + OCI_RETURN_NULLS + OCI_RETURN_LOBS);259 break;260 case Doctrine::FETCH_ASSOC :261 return oci_fetch_array($this->_statement, OCI_ASSOC + OCI_RETURN_NULLS + OCI_RETURN_LOBS);262 break;263 case Doctrine::FETCH_NUM :264 return oci_fetch_array($this->_statement, OCI_NUM + OCI_RETURN_NULLS + OCI_RETURN_LOBS);265 break;266 case FETCH_OBJ:267 return oci_fetch_object($this->_statement, OCI_NUM + OCI_RETURN_NULLS + OCI_RETURN_LOBS);268 break;269 default:270 throw new Doctrine_Adapter_Exception("This type of fetch is not supported: ".$fetchStyle); 297 public function fetch($fetchStyle = Doctrine::FETCH_BOTH, $cursorOrientation = Doctrine::FETCH_ORI_NEXT, $cursorOffset = null) 298 { 299 switch ($fetchStyle) { 300 case Doctrine::FETCH_BOTH : 301 return oci_fetch_array($this->statement, OCI_BOTH + OCI_RETURN_NULLS + OCI_RETURN_LOBS); 302 break; 303 case Doctrine::FETCH_ASSOC : 304 return oci_fetch_array($this->statement, OCI_ASSOC + OCI_RETURN_NULLS + OCI_RETURN_LOBS); 305 break; 306 case Doctrine::FETCH_NUM : 307 return oci_fetch_array($this->statement, OCI_NUM + OCI_RETURN_NULLS + OCI_RETURN_LOBS); 308 break; 309 case FETCH_OBJ: 310 return oci_fetch_object($this->statement, OCI_NUM + OCI_RETURN_NULLS + OCI_RETURN_LOBS); 311 break; 312 default: 313 throw new Doctrine_Adapter_Exception("This type of fetch is not supported: ".$fetchStyle); 271 314 /* 272 case Doctrine::FETCH_BOUND:273 case Doctrine::FETCH_CLASS:274 case FETCH_CLASSTYPE:275 case FETCH_COLUMN:276 case FETCH_FUNC:277 case FETCH_GROUP:278 case FETCH_INTO:279 case FETCH_LAZY:280 case FETCH_NAMED:281 case FETCH_SERIALIZE:282 case FETCH_UNIQUE:283 case FETCH_ORI_ABS:284 case FETCH_ORI_FIRST:285 case FETCH_ORI_LAST:286 case FETCH_ORI_NEXT:287 case FETCH_ORI_PRIOR:288 case FETCH_ORI_REL:289 */ 290 }291 }315 case Doctrine::FETCH_BOUND: 316 case Doctrine::FETCH_CLASS: 317 case FETCH_CLASSTYPE: 318 case FETCH_COLUMN: 319 case FETCH_FUNC: 320 case FETCH_GROUP: 321 case FETCH_INTO: 322 case FETCH_LAZY: 323 case FETCH_NAMED: 324 case FETCH_SERIALIZE: 325 case FETCH_UNIQUE: 326 case FETCH_ORI_ABS: 327 case FETCH_ORI_FIRST: 328 case FETCH_ORI_LAST: 329 case FETCH_ORI_NEXT: 330 case FETCH_ORI_PRIOR: 331 case FETCH_ORI_REL: 332 */ 333 } 334 } 292 335 293 336 /** … … 303 346 * @return array 304 347 */ 305 public function fetchAll($fetchStyle = Doctrine::FETCH_BOTH, $colnum=0){ 306 $fetchColumn = false; 307 $skip = 0; 308 $maxrows = -1; 309 $data = array(); 310 $flags = OCI_FETCHSTATEMENT_BY_ROW + OCI_ASSOC; 311 312 $int = $fetchStyle & Doctrine::FETCH_COLUMN; 313 314 if( $fetchStyle == Doctrine::FETCH_BOTH ){ 315 $flags = OCI_BOTH; 316 }else if( $fetchStyle == Doctrine::FETCH_ASSOC ){ 317 $numberOfRows = @oci_fetch_all($this->_statement, $data, $skip, $maxrows, OCI_FETCHSTATEMENT_BY_ROW + OCI_ASSOC + OCI_RETURN_LOBS); 318 }else if( $fetchStyle == Doctrine::FETCH_NUM ){ 319 $numberOfRows = @oci_fetch_all($this->_statement, $data, $skip, $maxrows, OCI_FETCHSTATEMENT_BY_ROW + OCI_NUM + OCI_RETURN_LOBS); 320 }else if( $fetchStyle == Doctrine::FETCH_COLUMN){ 321 while ($row = @oci_fetch_array ($this->_statement, OCI_NUM+OCI_RETURN_LOBS)) { 322 $data[] = $row[$colnum]; 323 } 324 }else{ 325 throw new Exception("Unsupported mode: '" . $fetchStyle . "' "); 326 } 327 328 return $data; 348 public function fetchAll($fetchStyle = Doctrine::FETCH_BOTH, $colnum=0) 349 { 350 $fetchColumn = false; 351 $skip = 0; 352 $maxrows = -1; 353 $data = array(); 354 $flags = OCI_FETCHSTATEMENT_BY_ROW + OCI_ASSOC; 355 356 $int = $fetchStyle & Doctrine::FETCH_COLUMN; 357 358 if ($fetchStyle == Doctrine::FETCH_BOTH) { 359 $flags = OCI_BOTH; 360 } else if ($fetchStyle == Doctrine::FETCH_ASSOC) { 361 $numberOfRows = @oci_fetch_all($this->statement, $data, $skip, $maxrows, OCI_FETCHSTATEMENT_BY_ROW + OCI_ASSOC + OCI_RETURN_LOBS); 362 } else if ($fetchStyle == Doctrine::FETCH_NUM) { 363 $numberOfRows = @oci_fetch_all($this->statement, $data, $skip, $maxrows, OCI_FETCHSTATEMENT_BY_ROW + OCI_NUM + OCI_RETURN_LOBS); 364 } else if ($fetchStyle == Doctrine::FETCH_COLUMN) { 365 while ($row = @oci_fetch_array ($this->statement, OCI_NUM+OCI_RETURN_LOBS)) { 366 $data[] = $row[$colnum]; 367 } 368 } else { 369 throw new Exception("Unsupported mode: '" . $fetchStyle . "' "); 370 } 371 372 return $data; 329 373 } 330 374 … … 339 383 * @return string returns a single column in the next row of a result set. 340 384 */ 341 public function fetchColumn($columnIndex = 0){ 342 if(! is_integer($columnIndex)){ 343 $this->handleError(array('message'=>"columnIndex parameter should be numeric")); 344 } 345 $row = $this->fetch( Doctrine::FETCH_NUM ); 346 return $row[$columnIndex]; 385 public function fetchColumn($columnIndex = 0) 386 { 387 if( ! is_integer($columnIndex)) { 388 $this->handleError(array('message'=>"columnIndex parameter should be numeric")); 389 } 390 $row = $this->fetch(Doctrine::FETCH_NUM); 391 return $row[$columnIndex]; 347 392 } 348 393 … … 359 404 * to the column names or FALSE in case of an error. 360 405 */ 361 public function fetchObject( $className = 'stdClass', $args = array() ){ 362 $row = $this->fetch(Doctrine::FETCH_ASSOC); 363 if($row === false){ 364 return false; 365 } 366 367 $instantiation_code = "\$object = new $className("; 368 $firstParam=true; 369 foreach($args as $index=>$value){ 370 if(!$firstParam){ 371 $instantiation_code = $instantiation_code . ","; 372 }else{ 373 $firstParam= false; 374 } 375 if( is_string($index)){ 376 $instantiation_code = $instantiation_code . " \$args['$index']"; 377 }else{ 378 $instantiation_code = $instantiation_code . "\$args[$index]"; 379 } 380 381 } 382 $instantiation_code = $instantiation_code . ");"; 383 384 eval($instantiation_code); 385 386 387 //initialize instance of $className class 388 foreach($row as $col => $value ){ 389 $object->$col = $value; 390 } 391 return $object; 406 public function fetchObject($className = 'stdClass', $args = array()) 407 { 408 $row = $this->fetch(Doctrine::FETCH_ASSOC); 409 if ($row === false) { 410 return false; 411 } 412 413 $instantiation_code = "\$object = new $className("; 414 $firstParam=true; 415 foreach ($args as $index=>$value) { 416 if ( ! $firstParam ) { 417 $instantiation_code = $instantiation_code . ","; 418 } else { 419 $firstParam= false; 420 } 421 if ( is_string($index)) { 422 $instantiation_code = $instantiation_code . " \$args['$index']"; 423 } else { 424 $instantiation_code = $instantiation_code . "\$args[$index]"; 425 } 426 } 427 428 $instantiation_code = $instantiation_code . ");"; 429 430 eval($instantiation_code); 431 432 //initialize instance of $className class 433 foreach ($row as $col => $value) { 434 $object->$col = $value; 435 } 436 437 return $object; 392 438 } 393 439 … … 407 453 * pdo_type The type of this column as represented by the PDO::PARAM_* constants. 408 454 */ 409 public function getColumnMeta($column){ 410 if( is_integer($column) ){ 411 $internal_column = $column +1; 412 }else{ 413 $internal_column = $column; 414 } 415 416 $data = array(); 417 $data['native_type'] = oci_field_type($this->_statement, $internal_column); 418 $data['flags'] = ""; 419 $data['len'] = oci_field_size($this->_statement, $internal_column); 420 $data['name'] = oci_field_name($this->_statement, $internal_column); 421 $data['precision'] = oci_field_precision($this->_statement, $internal_column); 422 423 return $data; 455 public function getColumnMeta($column) 456 { 457 if (is_integer($column)) { 458 $internal_column = $column +1; 459 } else { 460 $internal_column = $column; 461 } 462 463 $data = array(); 464 $data['native_type'] = oci_field_type($this->statement, $internal_column); 465 $data['flags'] = ""; 466 $data['len'] = oci_field_size($this->statement, $internal_column); 467 $data['name'] = oci_field_name($this->statement, $internal_column); 468 $data['precision'] = oci_field_precision($this->statement, $internal_column); 469 470 return $data; 424 471 } 425 472 … … 434 481 * @return boolean Returns TRUE on success or FALSE on failure. 435 482 */ 436 public function nextRowset(){ 437 throw new Exception("Unsupported"); 483 public function nextRowset() 484 { 485 throw new Exception("Unsupported"); 438 486 } 439 487 … … 449 497 * @return integer Returns the number of rows. 450 498 */ 451 public function rowCount(){ 452 return @oci_num_rows ( $this->_statement ); 499 public function rowCount() 500 { 501 return @oci_num_rows($this->statement); 453 502 } 454 503 … … 460 509 * @return boolean Returns TRUE on success or FALSE on failure. 461 510 */ 462 public function setAttribute($attribute, $value){ 463 switch($attribute){ 464 case Doctrine::ATTR_ERRMODE; 465 break; 466 default: 467 throw new Doctrine_Adapter_Exception("Unsupported Attribute: $attribute"); 468 } 469 $this->_attributes[$attribute] = $value; 470 } 471 472 /** 511 public function setAttribute($attribute, $value) 512 { 513 switch ($attribute) { 514 case Doctrine::ATTR_ERRMODE; 515 break; 516 default: 517 throw new Doctrine_Adapter_Exception("Unsupported Attribute: $attribute"); 518 } 519 $this->attributes[$attribute] = $value; 520 } 521 522 /** 473 523 * Retrieve a statement attribute 474 524 * … … 477 527 * @return mixed the attribute value 478 528 */ 479 public function getAttribute($attribute){ 480 return $this->_attributes[$attribute]; 529 public function getAttribute($attribute) 530 { 531 return $this->attributes[$attribute]; 481 532 } 482 533 /** … … 486 537 * @return boolean Returns 1 on success or FALSE on failure. 487 538 */ 488 public function setFetchMode($mode, $arg1 = null, $arg2 = null){ 489 throw new Exception("Unsupported"); 490 } 491 492 private function handleError($params=array()){ 493 494 switch($this->_attributes[Doctrine::ATTR_ERRMODE]) { 495 case Doctrine::ERRMODE_EXCEPTION: 496 if( isset($params['message']) ){ 497 throw new Doctrine_Adapter_Exception( $params['message'] ); 498 }else{ 499 throw new Doctrine_Adapter_Exception($this->errorInfo()); 500 } 501 502 break; 503 case Doctrine::ERRMODE_WARNING: 504 case Doctrine::ERRMODE_SILENT: 505 break; 506 } 539 public function setFetchMode($mode, $arg1 = null, $arg2 = null) 540 { 541 throw new Exception("Unsupported"); 542 } 543 544 private function handleError($params=array()) 545 { 546 547 switch ($this->attributes[Doctrine::ATTR_ERRMODE]) { 548 case Doctrine::ERRMODE_EXCEPTION: 549 if (isset($params['message'])) { 550 throw new Doctrine_Adapter_Exception($params['message']); 551 } else { 552 throw new Doctrine_Adapter_Exception($this->errorInfo()); 553 } 554 555 break; 556 case Doctrine::ERRMODE_WARNING: 557 case Doctrine::ERRMODE_SILENT: 558 break; 559 } 560 } 561 562 /** 563 * Parse actual query from queryString and returns OCI statement handler 564 * @param string Query string to parse, if NULL, $this->queryString is used 565 * 566 * @return resource OCI statement handler 567 */ 568 private function parseQuery($query=null) 569 { 570 if (is_null($query)) { 571 $query = $this->queryString; 572 } 573 $bind_index = 0; 574 // Replace ? bind-placeholders with :oci_b_var_ variables 575 $query = preg_replace("/(\?)/e", '":oci_b_var_". $bind_index++' , $query); 576 577 $this->statement = @oci_parse($this->connection, $query); 578 579 if ( $this->statement == false ) 580 { 581 throw new Doctrine_Adapter_Exception($this->getOciError()); 582 } 583 584 return $this->statement; 507 585 } 508 586 }