Changeset 4725 for trunk/lib/Doctrine
- Timestamp:
- 08/02/08 18:41:37 (5 months ago)
- Location:
- trunk/lib/Doctrine
- Files:
-
- 1 added
- 19 modified
-
ActiveEntity.php (added)
-
Configuration.php (modified) (2 diffs)
-
Connection.php (modified) (15 diffs)
-
Connection/Mock.php (modified) (1 diff)
-
Connection/Statement.php (modified) (23 diffs)
-
DatabasePlatform.php (modified) (3 diffs)
-
DatabasePlatform/FirebirdPlatform.php (modified) (1 diff)
-
DatabasePlatform/MsSqlPlatform.php (modified) (1 diff)
-
DatabasePlatform/MySqlPlatform.php (modified) (4 diffs)
-
DatabasePlatform/OraclePlatform.php (modified) (2 diffs)
-
DatabasePlatform/PostgreSqlPlatform.php (modified) (5 diffs)
-
DatabasePlatform/SqlitePlatform.php (modified) (1 diff)
-
Entity.php (modified) (21 diffs)
-
Hydrator/RecordDriver.php (modified) (4 diffs)
-
Query/Parser.php (modified) (1 diff)
-
Query/Production/Atom.php (modified) (2 diffs)
-
Query/Scanner.php (modified) (9 diffs)
-
Relation/Parser.php (modified) (1 diff)
-
Sequence/Mysql.php (modified) (2 diffs)
-
Sequence/Oracle.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Doctrine/Configuration.php
r4718 r4725 64 64 /** 65 65 * Initializes the attributes. 66 * Changes null default values to references to the Null object to allow 67 * fast isset() checks instead of array_key_exists(). 66 68 * 67 69 * @return void … … 69 71 private function _initAttributes() 70 72 { 71 // Change null default values to references to the Null object to allow72 // fast isset() checks instead of array_key_exists().73 73 foreach ($this->_attributes as $key => $value) { 74 74 if ($value === null) { -
trunk/lib/Doctrine/Connection.php
r4723 r4725 27 27 28 28 /** 29 * A thin connection wrapper on top of PDO.29 * A thin wrapper on top of the PDO class. 30 30 * 31 31 * 1. Event listeners … … 118 118 119 119 /** 120 * @var array $serverInfo121 */ 122 protected $ serverInfo = array();120 * @var array 121 */ 122 protected $_serverInfo = array(); 123 123 124 124 /** … … 155 155 156 156 /** 157 * Enter description here...157 * The transaction object. 158 158 * 159 159 * @var Doctrine::DBAL::Transactions::Transaction 160 160 */ 161 161 protected $_transaction; 162 163 /** 164 * The sequence manager. 165 * 166 * @var Doctrine::DBAL::Sequencing::SequenceManager 167 */ 168 protected $_sequenceManager; 162 169 163 170 /** … … 340 347 * @return string 341 348 * @todo make abstract, implement in subclasses. 349 * @todo throw different exception? 342 350 */ 343 351 protected function _constructPdoDsn() 344 352 { 345 353 throw Doctrine_Exception::notImplemented('_constructPdoDsn', get_class($this)); 346 }347 348 /**349 * @todo Remove. Breaks encapsulation.350 */351 public function incrementQueryCount()352 {353 $this->_queryCount++;354 354 } 355 355 … … 361 361 * 362 362 * The REPLACE type of query does not make part of the SQL standards. Since 363 * practically only MySQL and SQL Ite implement it natively, this type of364 * query is emulated through this method for other DBMS using standard types363 * practically only MySQL and SQLite implement it natively, this type of 364 * query is emulated through this method for other DBMS using standard types 365 365 * of queries inside a transaction to assure the atomicity of the operation. 366 366 * … … 491 491 // column names are specified as array keys 492 492 $cols = array(); 493 // the query VALUES will contain either expres ions (eg 'NOW()') or ?493 // the query VALUES will contain either expressions (eg 'NOW()') or ? 494 494 $a = array(); 495 495 foreach ($data as $columnName => $value) { … … 503 503 } 504 504 505 // build the statement506 505 $query = 'INSERT INTO ' . $this->quoteIdentifier($tableName) 507 506 . ' (' . implode(', ', $cols) . ') ' 508 507 . 'VALUES ('; 509 510 508 $query .= implode(', ', $a) . ')'; 511 // prepare and execute the statement512 509 513 510 return $this->exec($query, array_values($data)); … … 568 565 if (strpos($str, '.')) { 569 566 $e = explode('.', $str); 570 return $this->quoteIdentifier($e[0]) . '.' 567 return $this->quoteIdentifier($e[0]) 568 . '.' 571 569 . $this->quoteIdentifier($e[1]); 572 570 } 573 574 $ q = $this->properties['identifier_quoting'];575 $str = str_replace($ q['end'], $q['escape'] . $q['end'], $str);576 577 return $ q['start'] . $str . $q['end'];571 572 $c = $this->_platform->getIdentifierQuoteCharacter(); 573 $str = str_replace($c, $c . $c, $str); 574 575 return $c . $str . $c; 578 576 } 579 577 … … 604 602 605 603 /** 606 * Quotes given input parameter 607 * 608 * @param mixed $input parameter to be quoted609 * @param string $type 610 * @return mixed604 * Quotes given input parameter. 605 * 606 * @param mixed $input Parameter to be quoted. 607 * @param string $type Type of the parameter. 608 * @return string The quoted parameter. 611 609 */ 612 610 public function quote($input, $type = null) … … 614 612 return $this->_pdo->quote($input, $type); 615 613 } 616 /**617 * quote618 * quotes given input parameter619 *620 * @param mixed $input parameter to be quoted621 * @param string $type622 * @return mixed623 */624 /*public function quote($input, $type = null)625 {626 if ($type == null) {627 $type = gettype($input);628 }629 switch ($type) {630 case 'integer':631 case 'enum':632 case 'boolean':633 case 'double':634 case 'float':635 case 'bool':636 case 'decimal':637 case 'int':638 return $input;639 case 'array':640 case 'object':641 $input = serialize($input);642 case 'date':643 case 'time':644 case 'timestamp':645 case 'string':646 case 'char':647 case 'varchar':648 case 'text':649 case 'gzip':650 case 'blob':651 case 'clob':652 return $this->conn->quote($input);653 }654 }*/655 614 656 615 /** … … 883 842 */ 884 843 public function rethrowException(Exception $e, $invoker) 885 { 886 //$event = new Doctrine_Event($this, Doctrine_Event::CONN_ERROR); 887 //$this->getListener()->preError($event); 888 844 { 889 845 $name = 'Doctrine_Connection_' . $this->_driverName . '_Exception'; 890 891 846 $exc = new $name($e->getMessage(), (int) $e->getCode()); 892 847 if ( ! is_array($e->errorInfo)) { … … 894 849 } 895 850 $exc->processErrorInfo($e->errorInfo); 896 897 851 throw $exc; 898 899 //$this->getListener()->postError($event);900 852 } 901 853 … … 1008 960 public function commit($savepoint = null) 1009 961 { 1010 return $this-> transaction->commit($savepoint);962 return $this->_transaction->commit($savepoint); 1011 963 } 1012 964 … … 1026 978 public function rollback($savepoint = null) 1027 979 { 1028 $this-> transaction->rollback($savepoint);980 $this->_transaction->rollback($savepoint); 1029 981 } 1030 982 … … 1203 1155 } 1204 1156 1205 /* 1206 * ----------- Mixed methods (need to figure out where they go) --------------- 1207 */ 1208 1209 /** 1210 * retrieves a database connection attribute 1211 * 1212 * @param integer $attribute 1213 * @return mixed 1214 * @todo Implementation or remove if not needed. Configuration is the main 1215 * container for all the attributes now. 1216 */ 1217 public function getAttribute($attribute) 1218 { 1219 if ($attribute == Doctrine::ATTR_QUOTE_IDENTIFIER) { 1220 return false; 1221 } 1222 } 1223 1157 /** 1158 * Gets the SequenceManager that can be used to retrieve sequence values 1159 * through this connection. 1160 * 1161 * @return Doctrine::DBAL::Sequencing::SequenceManager 1162 */ 1224 1163 public function getSequenceManager() 1225 1164 { 1226 if ( ! $this-> modules['sequence']) {1165 if ( ! $this->_sequenceManager) { 1227 1166 $class = "Doctrine_Sequence_" . $this->_driverName; 1228 $this-> modules['sequence']= new $class;1229 } 1230 return $this-> modules['sequence'];1167 $this->_sequenceManager = new $class; 1168 } 1169 return $this->_sequenceManager; 1231 1170 } 1232 1171 } -
trunk/lib/Doctrine/Connection/Mock.php
r4723 r4725 60 60 public function quote($input, $type = null) 61 61 { 62 if ($type === 'string') { 63 return "'" . $input . "'"; 64 } 62 65 return $input; 63 66 } -
trunk/lib/Doctrine/Connection/Statement.php
r4328 r4725 19 19 * <http://www.phpdoctrine.org>. 20 20 */ 21 Doctrine::autoload('Doctrine_Adapter_Statement_Interface'); 21 22 22 /** 23 * Doctrine_Connection_Statement23 * A thin wrapper around PDOStatement. 24 24 * 25 * @package Doctrine26 * @subpackage Connection27 25 * @author Konsta Vesterinen <kvesteri@cc.hut.fi> 28 26 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL … … 32 30 * @todo Do we seriously need this wrapper? 33 31 */ 34 class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interface32 class Doctrine_Connection_Statement 35 33 { 36 34 /** … … 41 39 42 40 /** 43 * @var mixed$_stmt PDOStatement object, boolean false or Doctrine_Adapter_Statement object41 * @var PDOStatement $_stmt PDOStatement object, boolean false or Doctrine_Adapter_Statement object 44 42 */ 45 43 protected $_stmt; … … 82 80 83 81 /** 84 * bindColumn85 82 * Bind a column to a PHP variable 86 83 * … … 126 123 127 124 /** 128 * bindParam129 125 * Binds a PHP variable to a corresponding named or question mark placeholder in the 130 126 * SQL statement that was use to prepare the statement. Unlike Doctrine_Adapter_Statement_Interface->bindValue(), … … 162 158 163 159 /** 164 * closeCursor165 160 * Closes the cursor, enabling the statement to be executed again. 166 161 * … … 173 168 174 169 /** 175 * columnCount176 170 * Returns the number of columns in the result set 177 171 * … … 186 180 187 181 /** 188 * errorCode189 182 * Fetch the SQLSTATE associated with the last operation on the statement handle 190 183 * … … 198 191 199 192 /** 200 * errorInfo201 193 * Fetch extended error information associated with the last operation on the statement handle 202 194 * … … 210 202 211 203 /** 212 * execute213 204 * Executes a prepared statement 214 205 * … … 227 218 { 228 219 try { 229 $event = new Doctrine_Event($this, Doctrine_Event::STMT_EXECUTE, $this->getQuery(), $params);230 $this->_conn->getListener()->preStmtExecute($event);220 //$event = new Doctrine_Event($this, Doctrine_Event::STMT_EXECUTE, $this->getQuery(), $params); 221 //$this->_conn->getListener()->preStmtExecute($event); 231 222 232 223 $result = true; 233 if ( ! $event->skipOperation) {224 //if ( ! $event->skipOperation) { 234 225 $result = $this->_stmt->execute($params); 235 $this->_conn->incrementQueryCount();236 }237 238 $this->_conn->getListener()->postStmtExecute($event);226 //$this->_conn->incrementQueryCount(); 227 //} 228 229 //$this->_conn->getListener()->postStmtExecute($event); 239 230 240 231 return $result; 241 232 } catch (PDOException $e) { 242 } catch (Doctrine_Adapter_Exception $e) {233 $this->_conn->rethrowException($e, $this); 243 234 } 244 245 $this->_conn->rethrowException($e, $this);246 235 247 236 return false; … … 279 268 $cursorOffset = null) 280 269 { 281 $event = new Doctrine_Event($this, Doctrine_Event::STMT_FETCH, $this->getQuery()); 282 283 $event->fetchMode = $fetchMode; 284 $event->cursorOrientation = $cursorOrientation; 285 $event->cursorOffset = $cursorOffset; 286 287 $data = $this->_conn->getListener()->preFetch($event); 288 289 if ( ! $event->skipOperation) { 270 //$event = new Doctrine_Event($this, Doctrine_Event::STMT_FETCH, $this->getQuery()); 271 //$event->fetchMode = $fetchMode; 272 //$event->cursorOrientation = $cursorOrientation; 273 //$event->cursorOffset = $cursorOffset; 274 275 //$data = $this->_conn->getListener()->preFetch($event); 276 277 //if ( ! $event->skipOperation) { 290 278 $data = $this->_stmt->fetch($fetchMode, $cursorOrientation, $cursorOffset); 291 }292 293 $this->_conn->getListener()->postFetch($event);279 //} 280 281 //$this->_conn->getListener()->postFetch($event); 294 282 295 283 return $data; … … 297 285 298 286 /** 299 * fetchAll300 287 * Returns an array containing all of the result set rows 301 288 * … … 309 296 * @return array 310 297 */ 311 public function fetchAll($fetchMode = Doctrine::FETCH_BOTH, 312 $columnIndex = null) 313 { 314 $event = new Doctrine_Event($this, Doctrine_Event::STMT_FETCHALL, $this->getQuery()); 315 $event->fetchMode = $fetchMode; 316 $event->columnIndex = $columnIndex; 317 318 $this->_conn->getListener()->preFetchAll($event); 319 320 if ( ! $event->skipOperation) { 298 public function fetchAll($fetchMode = Doctrine::FETCH_BOTH, $columnIndex = null) 299 { 300 //$event = new Doctrine_Event($this, Doctrine_Event::STMT_FETCHALL, $this->getQuery()); 301 //$event->fetchMode = $fetchMode; 302 //$event->columnIndex = $columnIndex; 303 //$this->_conn->getListener()->preFetchAll($event); 304 305 //if ( ! $event->skipOperation) { 321 306 if ($columnIndex !== null) { 322 307 $data = $this->_stmt->fetchAll($fetchMode, $columnIndex); … … 324 309 $data = $this->_stmt->fetchAll($fetchMode); 325 310 } 326 327 $event->data = $data; 328 } 329 330 $this->_conn->getListener()->postFetchAll($event); 311 //$event->data = $data; 312 //} 313 314 //$this->_conn->getListener()->postFetchAll($event); 331 315 332 316 return $data; … … 334 318 335 319 /** 336 * fetchColumn337 320 * Returns a single column from the next row of a 338 321 * result set or FALSE if there are no more rows. … … 350 333 351 334 /** 352 * fetchObject353 335 * Fetches the next row and returns it as an object. 354 336 * … … 368 350 369 351 /** 370 * getAttribute371 352 * Retrieve a statement attribute 372 353 * … … 381 362 382 363 /** 383 * getColumnMeta384 364 * Returns metadata for a column in a result set 385 365 * … … 402 382 403 383 /** 404 * nextRowset405 384 * Advances to the next rowset in a multi-rowset statement handle 406 385 * … … 418 397 419 398 /** 420 * rowCount421 399 * rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement 422 400 * executed by the corresponding object. … … 435 413 436 414 /** 437 * setAttribute438 415 * Set a statement attribute 439 416 * … … 448 425 449 426 /** 450 * setFetchMode451 427 * Set the default fetch mode for this statement 452 428 * -
trunk/lib/Doctrine/DatabasePlatform.php
r4723 r4725 11 11 */ 12 12 abstract class Doctrine_DatabasePlatform 13 { 14 /** 15 * An array containing all features this platform supports, keys representing feature 16 * names and values as one of the following (true, false, 'emulated'). 17 * 18 * @var array 19 */ 20 protected $_supported = array(); 21 22 /** 23 * Platform specific properties. Subclasses can override these in the 24 * constructor. 25 * 26 * @var array $properties 27 */ 28 protected $_properties = array( 29 'sql_comments' => array( 30 array( 31 'start' => '--', 32 'end' => "\n", 33 'escape' => false 34 ), 35 array( 36 'start' => '/*', 37 'end' => '*/', 38 'escape' => false 39 ) 40 ), 41 'identifier_quoting' => array( 42 'start' => '"', 43 'end' => '"', 44 'escape' => '"' 45 ), 46 'string_quoting' => array( 47 'start' => "'", 48 'end' => "'", 49 'escape' => false, 50 'escape_pattern' => false 51 ), 52 'wildcards' => array('%', '_'), 53 'varchar_max_length' => 255, 54 ); 55 13 { 14 /** 15 * Constructor. 16 */ 56 17 public function __construct() {} 57 18 58 19 /** 59 * Checks whether a certain feature is supported. 60 * 61 * @param string $feature the name of the feature 62 * @return boolean whether or not this drivers supports given feature 63 */ 64 public function supports($feature) 65 { 66 return (isset($this->_supported[$feature]) && 67 ($this->_supported[$feature] === 'emulated' || $this->_supported[$feature])); 68 } 69 70 /** 71 * regexp 72 * returns the regular expression operator 20 * Gets the character used for identifier quoting. 21 * 22 * @return string 23 */ 24 public function getIdentifierQuoteCharacter() 25 { 26 return '"'; 27 } 28 29 /** 30 * Gets the string portion that starts an SQL comment. 31 * 32 * @return string 33 */ 34 public function getSqlCommentStartString() 35 { 36 return "--"; 37 } 38 39 /** 40 * Gets the string portion that starts an SQL comment. 41 * 42 * @return string 43 */ 44 public function getSqlCommentEndString() 45 { 46 return "\n"; 47 } 48 49 /** 50 * Gets the maximum length of a varchar field. 51 * 52 * @return integer 53 */ 54 public function getVarcharMaxLength() 55 { 56 return 255; 57 } 58 59 /** 60 * Gets all SQL wildcard characters of the platform. 61 * 62 * @return array 63 */