Changeset 4909 for trunk/lib/Doctrine

Show
Ignore:
Timestamp:
09/12/08 07:09:16 (4 months ago)
Author:
guilhermeblanco
Message:

Fixes in unit tests.
Started refactoring in DQL parser to separate Production into Parser and AST classes.
Finished first tests. Currently only 4 are active in IdentifierRecognitionTest?, and only 2 are passing.

Location:
trunk/lib/Doctrine
Files:
35 added
2 removed
12 modified

Legend:

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

    r4877 r4909  
    105105        // driver 
    106106        if ( isset($params['driver']) && ! isset($this->_drivers[$params['driver']])) { 
    107             throw Doctrine_ConnectionFactory_Exception::unknownDriver($driverName); 
     107            throw Doctrine_ConnectionFactory_Exception::unknownDriver($params['driver']); 
    108108        } 
    109109    } 
  • trunk/lib/Doctrine/DatabasePlatform.php

    r4866 r4909  
    945945     * @todo Throw exception by default? 
    946946     */ 
    947     public function getDropIndexSql($index) 
     947    public function getDropIndexSql($index, $name) 
    948948    { 
    949949        return 'DROP INDEX ' . $index; 
     
    983983     * @todo Throw exception by default? 
    984984     */ 
    985     public function getCreateTableSql($table, array $columns, array $options) 
     985    public function getCreateTableSql($table, array $columns, array $options = array()) 
    986986    { 
    987987        if ( ! $table) { 
  • trunk/lib/Doctrine/HydratorNew.php

    r4866 r4909  
    348348                 
    349349                // Cache general information like the column name <-> field name mapping 
    350                 $e = explode(Doctrine_Query_Production::SQLALIAS_SEPARATOR, $key); 
     350                $e = explode(Doctrine_Query_ParserRule::SQLALIAS_SEPARATOR, $key); 
    351351                $columnName = array_pop($e);                 
    352352                $cache[$key]['dqlAlias'] = $this->_tableAliases[ 
    353                         implode(Doctrine_Query_Production::SQLALIAS_SEPARATOR, $e) 
     353                        implode(Doctrine_Query_ParserRule::SQLALIAS_SEPARATOR, $e) 
    354354                        ]; 
    355355                $classMetadata = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata']; 
     
    433433                 
    434434                // cache general information like the column name <-> field name mapping 
    435                 $e = explode(Doctrine_Query_Production::SQLALIAS_SEPARATOR, $key); 
     435                $e = explode(Doctrine_Query_ParserRule::SQLALIAS_SEPARATOR, $key); 
    436436                $columnName = array_pop($e);               
    437437                $cache[$key]['dqlAlias'] = $this->_tableAliases[ 
    438                         implode(Doctrine_Query_Production::SQLALIAS_SEPARATOR, $e) 
     438                        implode(Doctrine_Query_ParserRule::SQLALIAS_SEPARATOR, $e) 
    439439                        ]; 
    440440                $classMetadata = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata']; 
  • trunk/lib/Doctrine/Query/Parser.php

    r4866 r4909  
    5252     */ 
    5353    protected $_sqlbuilder; 
     54     
     55    /** 
     56     * DQL string. 
     57     * 
     58     * @var string 
     59     */ 
     60    protected $_input; 
    5461 
    5562    /** 
     
    122129    { 
    123130        $this->_em = $query->getEntityManager(); 
    124         $this->_scanner = new Doctrine_Query_Scanner($query->getDql()); 
     131        $this->_input = $query->getDql(); 
     132        $this->_scanner = new Doctrine_Query_Scanner($this->_input); 
    125133        $this->_sqlBuilder = Doctrine_Query_SqlBuilder::fromConnection($this->_em); 
    126134        $this->_keywordTable = new Doctrine_Query_Token(); 
     
    141149            ) 
    142150        ); 
     151         
     152        $this->_parserResult->setEntityManager($this->_em); 
    143153 
    144154        $this->free(true); 
     
    226236        // Building the Abstract Syntax Tree 
    227237        // We have to double the call of QueryLanguage to allow it to work correctly... =\ 
    228         $AST = new Doctrine_Query_Production_QueryLanguage($this); 
    229         $AST = $AST->AST('QueryLanguage', Doctrine_Query_ProductionParamHolder::create()); 
     238        $DQL = new Doctrine_Query_Parser_QueryLanguage($this); 
     239        $AST = $DQL->parse('QueryLanguage', Doctrine_Query_ParserParamHolder::create()); 
    230240 
    231241        // Check for end of string 
     
    353363        return $this->_em; 
    354364    } 
     365     
     366 
     367    /** 
     368     * Retrieve the piece of DQL string given the token position 
     369     * 
     370     * @param array $token Token that it was processing. 
     371     * @return string Piece of DQL string. 
     372     */ 
     373    public function getQueryPiece($token, $previousChars = 10, $nextChars = 10) 
     374    { 
     375        $start = max(0, $token['position'] - $previousChars); 
     376        $end = max($token['position'] + $nextChars, strlen($this->_input)); 
     377         
     378        return substr($this->_input, $start, $end); 
     379    } 
    355380} 
  • trunk/lib/Doctrine/Query/ParserResult.php

    r4866 r4909  
    3535{ 
    3636    /** 
     37     * The EntityManager. 
     38     * 
     39     * @var Doctrine_EntityManager 
     40     */ 
     41    protected $_em; 
     42 
     43    /** 
    3744     * A simple array keys representing table aliases and values table alias 
    3845     * seeds. The seeds are used for generating short table aliases. 
     
    4855     */ 
    4956    protected $_queryFields = array(); 
     57     
     58     
     59    /** 
     60     * Sets the Entity Manager. 
     61     * 
     62     * @param Doctrine_EntityManager $em The Entity Manager. 
     63     */ 
     64    public function setEntityManager($em) 
     65    { 
     66        $this->_em = $em; 
     67    } 
     68 
     69 
     70    /** 
     71     * Gets the Entity Manager. 
     72     * 
     73     * @return Doctrine_EntityManager 
     74     */ 
     75    public function getEntityManager() 
     76    { 
     77        return $this->_em; 
     78    } 
    5079 
    5180 
  • trunk/lib/Doctrine/Query/Production/UpdateStatement.php

    r4523 r4909  
    7171     
    7272    /* Getters */ 
    73      
    7473    public function getUpdateClause() 
    7574    { 
  • trunk/lib/Doctrine/Query/SqlExecutor/Abstract.php

    r4800 r4909  
    1 <?php  
     1<?php 
    22/* 
    33 *  $Id$ 
     
    3636    protected $_sqlStatements; 
    3737 
    38     public function __construct(Doctrine_Query_Production $AST) 
     38    public function __construct(Doctrine_Query_AST $AST) 
    3939    { 
    4040        // [TODO] Remove me later! 
     
    6767     * @return Doctrine_Query_SqlExecutor_Abstract  The executor that is suitable for the given AST. 
    6868     */ 
    69     public static function create(Doctrine_Query_Production $AST) 
     69    public static function create(Doctrine_Query_AST $AST) 
    7070    { 
    71         $isDeleteStatement = $AST instanceof Doctrine_Query_Production_DeleteStatement; 
    72         $isUpdateStatement = $AST instanceof Doctrine_Query_Production_UpdateStatement; 
     71        $isDeleteStatement = $AST instanceof Doctrine_Query_AST_DeleteStatement; 
     72        $isUpdateStatement = $AST instanceof Doctrine_Query_AST_UpdateStatement; 
    7373 
    7474        if ($isUpdateStatement || $isDeleteStatement) { 
  • trunk/lib/Doctrine/Query/SqlExecutor/MultiTableDelete.php

    r4800 r4909  
    1 <?php  
     1<?php 
    22/* 
    33 *  $Id$ 
     
    4040     * @param Doctrine_Query_Production $AST 
    4141     */ 
    42     public function __construct(Doctrine_Query_Production $AST) 
     42    public function __construct(Doctrine_Query_AST $AST) 
    4343    { 
    4444        // TODO: Inspect the AST, create the necessary SQL queries and store them 
  • trunk/lib/Doctrine/Query/SqlExecutor/MultiTableUpdate.php

    r4800 r4909  
    1 <?php  
     1<?php 
    22/* 
    33 *  $Id$ 
     
    3535class Doctrine_Query_SqlExecutor_MultiTableUpdate extends Doctrine_Query_SqlExecutor_Abstract 
    3636{ 
    37     public function __construct(Doctrine_Query_Production $AST) 
     37    public function __construct(Doctrine_Query_AST $AST) 
    3838    { 
    3939        // TODO: Inspect the AST, create the necessary SQL queries and store them 
  • trunk/lib/Doctrine/Query/SqlExecutor/SingleSelect.php

    r4800 r4909  
    1 <?php  
     1<?php 
    22/* 
    33 *  $Id$ 
     
    3131class Doctrine_Query_SqlExecutor_SingleSelect extends Doctrine_Query_SqlExecutor_Abstract 
    3232{     
    33     public function __construct(Doctrine_Query_Production $AST) 
     33    public function __construct(Doctrine_Query_AST $AST) 
    3434    { 
    3535        parent::__construct($AST); 
  • trunk/lib/Doctrine/Query/SqlExecutor/SingleTableDeleteUpdate.php

    r4800 r4909  
    3333class Doctrine_Query_SqlExecutor_SingleTableDeleteUpdate extends Doctrine_Query_SqlExecutor_Abstract 
    3434{ 
    35     public function __construct(Doctrine_Query_Production $AST) 
     35    public function __construct(Doctrine_Query_AST $AST) 
    3636    { 
    3737        parent::__construct($AST);         
  • trunk/lib/Doctrine/Query/Token.php

    r4523 r4909  
    147147    public function getLiteral($token) 
    148148    { 
    149         return isset($this->_keywordsTable[$token]) ? $this->_keywordsTable[$token] : ''; 
     149        return isset($this->_keywordsTable[$token])  
     150            ? $this->_keywordsTable[$token]  
     151            : (is_string($token) ? $token : ''); 
    150152    } 
    151153}