Changeset 4725 for trunk/lib/Doctrine

Show
Ignore:
Timestamp:
08/02/08 18:41:37 (5 months ago)
Author:
romanb
Message:

Intermediate checkin.

Location:
trunk/lib/Doctrine
Files:
1 added
19 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/Doctrine/Configuration.php

    r4718 r4725  
    6464    /** 
    6565     * 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(). 
    6668     *  
    6769     * @return void 
     
    6971    private function _initAttributes() 
    7072    { 
    71         // Change null default values to references to the Null object to allow 
    72         // fast isset() checks instead of array_key_exists(). 
    7373        foreach ($this->_attributes as $key => $value) { 
    7474            if ($value === null) { 
  • trunk/lib/Doctrine/Connection.php

    r4723 r4725  
    2727 
    2828/** 
    29  * A thin connection wrapper on top of PDO. 
     29 * A thin wrapper on top of the PDO class. 
    3030 * 
    3131 * 1. Event listeners 
     
    118118     
    119119    /** 
    120      * @var array $serverInfo 
    121      */ 
    122     protected $serverInfo = array(); 
     120     * @var array 
     121     */ 
     122    protected $_serverInfo = array(); 
    123123     
    124124    /** 
     
    155155 
    156156    /** 
    157      * Enter description here... 
     157     * The transaction object. 
    158158     * 
    159159     * @var Doctrine::DBAL::Transactions::Transaction 
    160160     */ 
    161161    protected $_transaction; 
     162     
     163    /** 
     164     * The sequence manager. 
     165     * 
     166     * @var Doctrine::DBAL::Sequencing::SequenceManager 
     167     */ 
     168    protected $_sequenceManager; 
    162169 
    163170    /** 
     
    340347     * @return string 
    341348     * @todo make abstract, implement in subclasses. 
     349     * @todo throw different exception? 
    342350     */ 
    343351    protected function _constructPdoDsn() 
    344352    { 
    345353        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++; 
    354354    } 
    355355     
     
    361361     * 
    362362     * The REPLACE type of query does not make part of the SQL standards. Since 
    363      * practically only MySQL and SQLIte implement it natively, this type of 
    364      * query isemulated through this method for other DBMS using standard types 
     363     * practically only MySQL and SQLite implement it natively, this type of 
     364     * query is emulated through this method for other DBMS using standard types 
    365365     * of queries inside a transaction to assure the atomicity of the operation. 
    366366     * 
     
    491491        // column names are specified as array keys 
    492492        $cols = array(); 
    493         // the query VALUES will contain either expresions (eg 'NOW()') or ? 
     493        // the query VALUES will contain either expressions (eg 'NOW()') or ? 
    494494        $a = array(); 
    495495        foreach ($data as $columnName => $value) { 
     
    503503        } 
    504504 
    505         // build the statement 
    506505        $query = 'INSERT INTO ' . $this->quoteIdentifier($tableName) 
    507506               . ' (' . implode(', ', $cols) . ') ' 
    508507               . 'VALUES ('; 
    509  
    510508        $query .= implode(', ', $a) . ')'; 
    511         // prepare and execute the statement 
    512509 
    513510        return $this->exec($query, array_values($data)); 
     
    568565        if (strpos($str, '.')) { 
    569566            $e = explode('.', $str); 
    570             return $this->quoteIdentifier($e[0]) . '.' 
     567            return $this->quoteIdentifier($e[0]) 
     568                    . '.' 
    571569                    . $this->quoteIdentifier($e[1]); 
    572570        } 
    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; 
    578576    } 
    579577 
     
    604602 
    605603    /** 
    606      * Quotes given input parameter 
    607      * 
    608      * @param mixed $input      parameter to be quoted 
    609      * @param string $type 
    610      * @return mixed 
     604     * 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. 
    611609     */ 
    612610    public function quote($input, $type = null) 
     
    614612        return $this->_pdo->quote($input, $type); 
    615613    } 
    616     /** 
    617      * quote 
    618      * quotes given input parameter 
    619      * 
    620      * @param mixed $input      parameter to be quoted 
    621      * @param string $type 
    622      * @return mixed 
    623      */ 
    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     }*/ 
    655614 
    656615    /** 
     
    883842     */ 
    884843    public function rethrowException(Exception $e, $invoker) 
    885     { 
    886         //$event = new Doctrine_Event($this, Doctrine_Event::CONN_ERROR); 
    887         //$this->getListener()->preError($event); 
    888          
     844    {         
    889845        $name = 'Doctrine_Connection_' . $this->_driverName . '_Exception'; 
    890          
    891846        $exc = new $name($e->getMessage(), (int) $e->getCode()); 
    892847        if ( ! is_array($e->errorInfo)) { 
     
    894849        } 
    895850        $exc->processErrorInfo($e->errorInfo); 
    896  
    897851        throw $exc; 
    898  
    899         //$this->getListener()->postError($event); 
    900852    } 
    901853     
     
    1008960    public function commit($savepoint = null) 
    1009961    { 
    1010         return $this->transaction->commit($savepoint); 
     962        return $this->_transaction->commit($savepoint); 
    1011963    } 
    1012964 
     
    1026978    public function rollback($savepoint = null) 
    1027979    { 
    1028         $this->transaction->rollback($savepoint); 
     980        $this->_transaction->rollback($savepoint); 
    1029981    } 
    1030982 
     
    12031155    } 
    12041156     
    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     */ 
    12241163    public function getSequenceManager() 
    12251164    { 
    1226         if ( ! $this->modules['sequence']) { 
     1165        if ( ! $this->_sequenceManager) { 
    12271166            $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; 
    12311170    } 
    12321171} 
  • trunk/lib/Doctrine/Connection/Mock.php

    r4723 r4725  
    6060    public function quote($input, $type = null) 
    6161    { 
     62        if ($type === 'string') { 
     63            return "'" . $input . "'"; 
     64        } 
    6265        return $input; 
    6366    } 
  • trunk/lib/Doctrine/Connection/Statement.php

    r4328 r4725  
    1919 * <http://www.phpdoctrine.org>. 
    2020 */ 
    21 Doctrine::autoload('Doctrine_Adapter_Statement_Interface'); 
     21 
    2222/** 
    23  * Doctrine_Connection_Statement 
     23 * A thin wrapper around PDOStatement. 
    2424 * 
    25  * @package     Doctrine 
    26  * @subpackage  Connection 
    2725 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi> 
    2826 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL 
     
    3230 * @todo Do we seriously need this wrapper? 
    3331 */ 
    34 class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interface 
     32class Doctrine_Connection_Statement 
    3533{ 
    3634    /** 
     
    4139 
    4240    /** 
    43      * @var mixed $_stmt                    PDOStatement object, boolean false or Doctrine_Adapter_Statement object 
     41     * @var PDOStatement $_stmt                    PDOStatement object, boolean false or Doctrine_Adapter_Statement object 
    4442     */ 
    4543    protected $_stmt; 
     
    8280 
    8381    /** 
    84      * bindColumn 
    8582     * Bind a column to a PHP variable 
    8683     * 
     
    126123 
    127124    /** 
    128      * bindParam 
    129125     * Binds a PHP variable to a corresponding named or question mark placeholder in the 
    130126     * SQL statement that was use to prepare the statement. Unlike Doctrine_Adapter_Statement_Interface->bindValue(), 
     
    162158 
    163159    /** 
    164      * closeCursor 
    165160     * Closes the cursor, enabling the statement to be executed again. 
    166161     * 
     
    173168 
    174169    /** 
    175      * columnCount 
    176170     * Returns the number of columns in the result set 
    177171     * 
     
    186180 
    187181    /** 
    188      * errorCode 
    189182     * Fetch the SQLSTATE associated with the last operation on the statement handle 
    190183     * 
     
    198191 
    199192    /** 
    200      * errorInfo 
    201193     * Fetch extended error information associated with the last operation on the statement handle 
    202194     * 
     
    210202 
    211203    /** 
    212      * execute 
    213204     * Executes a prepared statement 
    214205     * 
     
    227218    { 
    228219        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); 
    231222 
    232223            $result = true; 
    233             if ( ! $event->skipOperation) { 
     224            //if ( ! $event->skipOperation) { 
    234225                $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); 
    239230 
    240231            return $result; 
    241232        } catch (PDOException $e) { 
    242         } catch (Doctrine_Adapter_Exception $e) { 
     233            $this->_conn->rethrowException($e, $this); 
    243234        } 
    244  
    245         $this->_conn->rethrowException($e, $this); 
    246235 
    247236        return false; 
     
    279268                          $cursorOffset = null) 
    280269    { 
    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) { 
    290278            $data = $this->_stmt->fetch($fetchMode, $cursorOrientation, $cursorOffset); 
    291         } 
    292  
    293         $this->_conn->getListener()->postFetch($event); 
     279        //} 
     280 
     281        //$this->_conn->getListener()->postFetch($event); 
    294282 
    295283        return $data; 
     
    297285 
    298286    /** 
    299      * fetchAll 
    300287     * Returns an array containing all of the result set rows 
    301288     * 
     
    309296     * @return array 
    310297     */ 
    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) { 
    321306            if ($columnIndex !== null) { 
    322307                $data = $this->_stmt->fetchAll($fetchMode, $columnIndex); 
     
    324309                $data = $this->_stmt->fetchAll($fetchMode); 
    325310            } 
    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); 
    331315 
    332316        return $data; 
     
    334318 
    335319    /** 
    336      * fetchColumn 
    337320     * Returns a single column from the next row of a 
    338321     * result set or FALSE if there are no more rows. 
     
    350333 
    351334    /** 
    352      * fetchObject 
    353335     * Fetches the next row and returns it as an object. 
    354336     * 
     
    368350 
    369351    /** 
    370      * getAttribute 
    371352     * Retrieve a statement attribute 
    372353     * 
     
    381362 
    382363    /** 
    383      * getColumnMeta 
    384364     * Returns metadata for a column in a result set 
    385365     * 
     
    402382 
    403383    /** 
    404      * nextRowset 
    405384     * Advances to the next rowset in a multi-rowset statement handle 
    406385     * 
     
    418397 
    419398    /** 
    420      * rowCount 
    421399     * rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement 
    422400     * executed by the corresponding object. 
     
    435413 
    436414    /** 
    437      * setAttribute 
    438415     * Set a statement attribute 
    439416     * 
     
    448425 
    449426    /** 
    450      * setFetchMode 
    451427     * Set the default fetch mode for this statement 
    452428     * 
  • trunk/lib/Doctrine/DatabasePlatform.php

    r4723 r4725  
    1111 */ 
    1212abstract 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     */ 
    5617    public function __construct() {} 
    5718     
    5819    /** 
    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     */