Changeset 5014

Show
Ignore:
Timestamp:
10/01/08 17:56:36 (9 months ago)
Author:
guilhermeblanco
Message:

[1.1] Added support to foo.bar IN ?.
Fixed getDql() with subquery that was throwing a catchable fatal error.
Added possibility to use Doctrine_Query as string (it's converted to DQL).

Location:
branches/1.1
Files:
17 modified

Legend:

Unmodified
Added
Removed
  • branches/1.1/lib/Doctrine/Query.php

    r5009 r5014  
    175175     */ 
    176176    protected $_sql; 
     177     
     178     
     179    /** 
     180     * @var int $_processedParamIdx          Current index of processed param. 
     181     */ 
     182    protected $_processedParamIdx = 0; 
     183 
    177184 
    178185    /** 
     
    201208        $this->_needsSubquery = false; 
    202209        $this->_isLimitSubqueryUsed = false; 
     210        $this->_processedParamIdx = 0; 
    203211    } 
    204212 
     
    327335            throw new Doctrine_Query_Exception('Unknown aggregate alias: ' . $dqlAlias); 
    328336        } 
     337    } 
     338     
     339     
     340    /** 
     341     * Adjust the processed param index for "foo.bar IN ?" support 
     342     * 
     343     */ 
     344    public function adjustProcessedParam($index) 
     345    { 
     346        // Retrieve all params 
     347        $params = $this->getInternalParams(); 
     348 
     349        // Update processed param index 
     350        $this->_processedParamIdx = $index + count($params[$index]); 
     351 
     352        // Retrieve already processed values 
     353        $first = array_slice($params, 0, $index); 
     354        $last = array_slice($params, $index, count($params) - $index); 
     355 
     356        // Include array as values splicing the params array 
     357        array_splice($last, 0, 1, $last[0]); 
     358 
     359        // Put all param values into a single index 
     360        $this->_execParams = array_merge($first, $last); 
     361    } 
     362 
     363    /** 
     364     * @nodoc 
     365     */ 
     366    public function getProcessedParamIndex() 
     367    { 
     368        return $this->_processedParamIdx; 
    329369    } 
    330370 
     
    668708            if ($pos !== false) { 
    669709                $name = substr($term[0], 0, $pos); 
     710 
    670711                $term[0] = $this->parseFunctionExpression($term[0]); 
    671712            } else { 
     
    784825    { 
    785826        $pos = strpos($expr, '('); 
    786  
    787827        $name = substr($expr, 0, $pos); 
    788828 
     
    792832 
    793833        $argStr = substr($expr, ($pos + 1), -1); 
    794  
    795834        $args   = array(); 
    796835        // parse args 
     
    809848        return $expr; 
    810849    } 
     850 
     851 
    811852    public function parseSubquery($subquery) 
    812853    { 
     
    826867        return '(' . $trimmed . ')'; 
    827868    } 
     869     
     870 
    828871    /** 
    829872     * processPendingSubqueries 
     
    10331076    public function getSqlQuery($params = array()) 
    10341077    { 
     1078        // Assign building/execution specific params 
     1079        $this->_params['exec'] = $params; 
     1080 
     1081        // Initialize prepared parameters array 
     1082        $this->_execParams = $this->getParams(); 
     1083 
    10351084        if ($this->_state !== self::STATE_DIRTY) { 
    1036            return $this->_sql; 
     1085            $this->fixArrayParameterValues($this->getInternalParams()); 
     1086 
     1087            // Return compiled SQL 
     1088            return $this->_sql; 
    10371089        } 
    10381090 
     
    17911843    { 
    17921844        // triggers dql parsing/processing 
    1793         $this->getQuery(); // this is ugly 
     1845        $this->getSqlQuery(); // this is ugly 
    17941846 
    17951847        // initialize temporary variables 
     
    18751927    { 
    18761928        $q = $this->getCountQuery(); 
    1877  
    1878         if ( ! is_array($params)) { 
    1879             $params = array($params); 
    1880         } 
    1881  
    1882         $params = array_merge($this->_params['join'], $this->_params['where'], $this->_params['having'], $params); 
    1883  
     1929        $params = $this->getCountQueryParams($params); 
    18841930        $results = $this->getConnection()->fetchAll($q, $params); 
    18851931 
  • branches/1.1/lib/Doctrine/Query/Abstract.php

    r5001 r5014  
    101101 
    102102    /** 
    103      * @var array $params  The parameters of this query. 
    104      */ 
    105     protected $_params = array('join' => array(), 
     103     * @var array $_params  The parameters of this query. 
     104     */ 
     105    protected $_params = array('exec' => array(), 
     106                               'join' => array(), 
    106107                               'where' => array(), 
    107108                               'set' => array(), 
    108109                               'having' => array()); 
     110 
     111    /** 
     112     * @var array $_execParams The parameters passed to connection statement 
     113     */ 
     114    protected $_execParams = array(); 
    109115 
    110116    /* Caching properties */ 
     
    539545    public function getParams($params = array()) 
    540546    { 
    541         return array_merge($params, $this->_params['join'], $this->_params['set'], $this->_params['where'], $this->_params['having']); 
     547        return array_merge( 
     548            $params, $this->_params['exec'],  
     549            $this->_params['join'], $this->_params['set'], 
     550            $this->_params['where'], $this->_params['having'] 
     551        ); 
     552    } 
     553 
     554    /** 
     555     * getInternalParams 
     556     * 
     557     * @return array 
     558     */ 
     559    public function getInternalParams($params = array()) 
     560    { 
     561        return array_merge($params, $this->_execParams); 
    542562    } 
    543563 
     
    550570    { 
    551571        $this->_params = $params; 
     572    } 
     573     
     574    /** 
     575     * getCountQueryParams 
     576     * Retrieves the parameters for count query 
     577     * 
     578     * @return array Parameters array 
     579     */ 
     580    public function getCountQueryParams($params = array()) 
     581    { 
     582        if ( ! is_array($params)) { 
     583            $params = array($params); 
     584        } 
     585 
     586        $this->_params['exec'] = $params; 
     587 
     588        $params = array_merge($this->_params['join'], $this->_params['where'], $this->_params['having'], $this->_params['exec']); 
     589 
     590        $this->fixArrayParameterValues($params); 
     591 
     592        return $this->_execParams; 
     593    } 
     594 
     595    /** 
     596     * @nodoc 
     597     */ 
     598    public function fixArrayParameterValues($params = array()) 
     599    { 
     600        for ($i = 0; $i < count($params); $i++) { 
     601            if (is_array($params[$i])) { 
     602                $c = count($params[$i]); 
     603 
     604                array_splice($params, $i, 1, $params[$i]); 
     605                 
     606                $i += $c; 
     607            } 
     608        } 
     609         
     610        $this->_execParams = $params; 
    552611    } 
    553612 
     
    920979    protected function _execute($params) 
    921980    { 
     981        // Apply boolean conversion in DQL params 
    922982        $params = $this->_conn->convertBooleans($params); 
    923983 
     984        foreach ($this->_params as $k => $v) { 
     985            $this->_params[$k] = $this->_conn->convertBooleans($v); 
     986        } 
     987 
     988        $dqlParams = $this->getParams($params); 
     989 
     990        // Check if we're not using a Doctrine_View 
    924991        if ( ! $this->_view) { 
    925992            if ($this->_queryCache !== false && ($this->_queryCache || $this->_conn->getAttribute(Doctrine::ATTR_QUERY_CACHE))) { 
    926993                $queryCacheDriver = $this->getQueryCacheDriver(); 
    927                 // calculate hash for dql query 
     994                 
     995                // Calculate hash for dql query 
    928996                $dql = $this->getDql(); 
    929997                $hash = md5($dql . 'DOCTRINE_QUERY_CACHE_SALT'); 
    930998                $cached = $queryCacheDriver->fetch($hash); 
     999 
     1000                // If we have a cached query... 
    9311001                if ($cached) { 
     1002                    // Rebuild query from cache 
    9321003                    $query = $this->_constructQueryFromCache($cached); 
     1004                     
     1005                    // Assign building/execution specific params 
     1006                    $this->_params['exec'] = $params; 
     1007             
     1008                    // Initialize prepared parameters array 
     1009                    $this->_execParams = $this->getParams(); 
     1010                     
     1011                    // Fix possible array parameter values in SQL params 
     1012                    $this->fixArrayParameterValues($this->getInternalParams()); 
    9331013                } else { 
     1014                    // Generate SQL or pick already processed one 
    9341015                    $query = $this->getSqlQuery($params); 
     1016                     
     1017                    // Convert query into a serialized form 
    9351018                    $serializedQuery = $this->getCachedForm($query); 
     1019                     
     1020                    // Save cached query 
    9361021                    $queryCacheDriver->save($hash, $serializedQuery, $this->getQueryCacheLifeSpan()); 
    9371022                } 
     
    9421027            $query = $this->_view->getSelectSql(); 
    9431028        } 
     1029         
     1030        // Get prepared SQL params for execution 
     1031        $params = $this->getInternalParams(); 
    9441032 
    9451033        if ($this->isLimitSubqueryUsed() && 
     
    9531041 
    9541042        $stmt = $this->_conn->execute($query, $params); 
     1043 
    9551044        return $stmt; 
    9561045    } 
     
    9651054    public function execute($params = array(), $hydrationMode = null) 
    9661055    { 
     1056        // Clean any possible processed params 
     1057        $this->_execParams = array(); 
     1058 
    9671059        if (empty($this->_dqlParts['from']) && empty($this->_sqlParts['from'])) { 
    9681060            throw new Doctrine_Query_Exception('You must have at least one component specified in your from.'); 
     
    9751067        } 
    9761068 
    977         $params = $this->getParams($params); 
     1069        // Retrieve DQL params 
     1070        $dqlParams = $this->getParams($params); 
    9781071 
    9791072        if ($this->_resultCache && $this->_type == self::SELECT) { 
     
    9821075            $dql = $this->getDql(); 
    9831076            // calculate hash for dql query 
    984             $hash = md5($dql . var_export($params, true)); 
     1077            $hash = md5($dql . var_export($dqlParams, true)); 
    9851078 
    9861079            $cached = ($this->_expireResultCache) ? false : $cacheDriver->fetch($hash); 
     
    13451438        $this->_params['where'] = array_merge($this->_params['where'], $params); 
    13461439 
    1347         return $expr . ($not === true ? ' NOT ':'') . ' IN (' . implode(', ', $a) . ')'; 
     1440        return $expr . ($not === true ? ' NOT' : '') . ' IN (' . implode(', ', $a) . ')'; 
    13481441    } 
    13491442 
     
    20812174        return $this->getSqlQuery($params); 
    20822175    } 
     2176     
     2177     
     2178    /** 
     2179     * toString magic call 
     2180     * this method is automatically called when Doctrine_Query object is trying to be used as a string 
     2181     * So, it it converted into its DQL correspondant 
     2182     * 
     2183     * @return string DQL string 
     2184     */ 
     2185    public function __toString() 
     2186    { 
     2187        return $this->getDql(); 
     2188    } 
    20832189} 
  • branches/1.1/lib/Doctrine/Query/Part.php

    r3884 r5014  
    4646    { 
    4747        $this->query = $query; 
     48 
    4849        if ( ! $tokenizer) { 
    4950            $tokenizer = new Doctrine_Query_Tokenizer(); 
  • branches/1.1/lib/Doctrine/Query/Select.php

    r4252 r5014  
    11<?php 
    22/* 
    3  *  $Id: From.php 1080 2007-02-10 18:17:08Z romanb $ 
     3 *  $Id: Select.php 1080 2007-02-10 18:17:08Z romanb $ 
    44 * 
    55 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  • branches/1.1/lib/Doctrine/Query/Where.php

    r5001 r5014  
    3333class Doctrine_Query_Where extends Doctrine_Query_Condition 
    3434{ 
    35     public function load($where)  
     35    public function load($where) 
    3636    { 
     37        // Handle operator ("AND" | "OR"), reducing overhead of this method processment 
     38        $possibleOp = strtolower($where); 
     39 
     40        if ($possibleOp == 'and' || $possibleOp == 'or') 
     41        { 
     42            return $where; 
     43        } 
     44 
    3745        $where = $this->_tokenizer->bracketTrim(trim($where)); 
    3846        $conn  = $this->query->getConnection(); 
     
    5260 
    5361        if (count($terms) > 1) { 
    54             $first = array_shift($terms); 
    55             $value = array_pop($terms); 
    56             $operator = trim(substr($where, strlen($first), -strlen($value))); 
    57             $table = null; 
    58             $field = null; 
     62            $leftExpr = array_shift($terms); 
     63            $rightExpr = array_pop($terms); 
     64            $operator = trim(substr($where, strlen($leftExpr), -strlen($rightExpr))); 
    5965 
    60             if (strpos($first, "'") === false && strpos($first, '(') === false) { 
     66            if (strpos($leftExpr, "'") === false && strpos($leftExpr, '(') === false) { 
    6167                // normal field reference found 
    62                 $a = explode('.', $first); 
    63          
    64                 $field = array_pop($a); 
     68                $a = explode('.', $leftExpr); 
     69                array_pop($a); // Discard the field name (not needed!) 
    6570                $reference = implode('.', $a); 
    66                  
     71 
    6772                if (empty($reference)) { 
    68                     $map = $this->query->getRootDeclaration();   
    69                      
     73                    $map = $this->query->getRootDeclaration(); 
    7074                    $alias = $this->query->getTableAlias($this->query->getRootAlias()); 
    71                     $table = $map['table']; 
    7275                } else { 
    7376                    $map = $this->query->load($reference, false); 
    74      
    7577                    $alias = $this->query->getTableAlias($reference); 
    76                     $table = $map['table']; 
    7778                } 
    7879            } 
    79             $first = $this->query->parseClause($first); 
    80              
    81             $sql = $first . ' ' . $operator . ' ' . $this->parseValue($value, $table, $field); 
    82          
    83             return $sql;   
     80 
     81            $sql = $this->_buildSql($leftExpr, $operator, $rightExpr); 
     82 
     83            //echo '<pre>Built SQL: '.$sql.'</pre>'; 
     84 
     85            return $sql; 
    8486        } else { 
    8587            return $where; 
    8688        } 
    8789    } 
     90     
    8891 
    89     public function parseValue($value, Doctrine_Table $table = null, $field = null) 
     92    protected function _buildSql($leftExpr, $operator, $rightExpr) 
     93    { 
     94        // Left Expression 
     95        $leftExpr = $this->query->parseClause($leftExpr); 
     96 
     97        $op = strtolower($operator); 
     98 
     99        // Right Expression 
     100        $rightExpr = (($rightExpr == '?' || substr($rightExpr, 0 , 1) == ':') && ($op == 'in' || $op == 'not in')) 
     101            ? $this->_buildWhereInArraySqlPart($rightExpr) 
     102            : $this->parseValue($rightExpr); 
     103 
     104        return $leftExpr . ' ' . $operator . ' ' . $rightExpr; 
     105    } 
     106     
     107 
     108    protected function _buildWhereInArraySqlPart($rightExpr) 
     109    { 
     110        $params = $this->query->getInternalParams(); 
     111        $value = array(); 
     112 
     113        for ($i = $this->query->getProcessedParamIndex(), $l = count($params); $i < $l; $i++) { 
     114            if (is_array($params[$i])) { 
     115                $value = array_fill(0, count($params[$i]), $rightExpr); 
     116                $this->query->adjustProcessedParam($i); 
     117 
     118                break; 
     119            } 
     120        } 
     121 
     122        return '(' . (count($value) > 0 ? implode(', ', $value) : $rightExpr) . ')'; 
     123    } 
     124 
     125 
     126    public function parseValue($rightExpr) 
    90127    { 
    91128        $conn = $this->query->getConnection(); 
    92129 
    93130        // If value is contained in paranthesis 
    94         if (substr($value, 0, 1) == '(') { 
     131        if (substr($rightExpr, 0, 1) == '(') { 
    95132            // trim brackets 
    96             $trimmed = $this->_tokenizer->bracketTrim($value); 
     133            $trimmed = $this->_tokenizer->bracketTrim($rightExpr); 
    97134 
    98135            // If subquery found which begins with FROM and SELECT 
     
    105142                $sql   = $q->getSql(); 
    106143                $this->query->mergeSubqueryBack($q); 
    107                 $value = '(' . $sql . ')'; 
     144                $rightExpr = '(' . $sql . ')'; 
    108145 
    109146            // If custom sql for custom subquery 
     
    111148            // FROM User u WHERE u.id = SQL:(select id from user where id = 1) 
    112149            } elseif (substr($trimmed, 0, 4) == 'SQL:') { 
    113                 $value = '(' . substr($trimmed, 4) . ')'; 
     150                $rightExpr = '(' . substr($trimmed, 4) . ')'; 
    114151            // simple in expression found 
    115152            } else { 
     
    117154 
    118155                $value = array(); 
    119  
    120156                $index = false; 
    121157 
     
    124160                } 
    125161 
    126                 $value = '(' . implode(', ', $value) . ')'; 
     162                $rightExpr = '(' . implode(', ', $value) . ')'; 
    127163            } 
    128164        } else { 
    129             $value = $this->parseLiteralValue($value); 
     165            $rightExpr = $this->parseLiteralValue($rightExpr); 
    130166        } 
    131         return $value; 
     167 
     168        return $rightExpr; 
    132169    } 
    133170 
  • branches/1.1/lib/Doctrine/RawSql.php

    r4768 r5014  
    155155                        $parts[$type][0] = $part; 
    156156                    } else { 
    157                         // why does this add to index 0 and not append to the  
     157                        // why does this add to index 0 and not append to the 
    158158                        // array. If it had done that one could have used  
    159159                        // parseQueryPart. 
     
    177177    public function getSqlQuery($params = array()) 
    178178    {         
     179        // Assign building/execution specific params 
     180        $this->_params['exec'] = $params; 
     181 
     182        // Initialize prepared parameters array 
     183        $this->_execParams = $this->getParams(); 
     184 
     185        // Initialize prepared parameters array 
     186        $this->fixArrayParameterValues($this->_execParams); 
     187 
    179188        $select = array(); 
    180189 
     
    314323    { 
    315324        $q = $this->getCountQuery(); 
    316  
    317         if ( ! is_array($params)) { 
    318             $params = array($params); 
    319         } 
    320  
    321         $params = array_merge($this->_params['join'], $this->_params['where'], $this->_params['having'], $params); 
    322  
     325        $params = $this->getCountQueryParams($params); 
    323326        $results = $this->getConnection()->fetchAll($q, $params); 
    324327 
  • branches/1.1/lib/Doctrine/Relation/Nest.php

    r4890 r5014  
    118118 
    119119            $params = ($this->definition['equal']) ? array($id, $id) : array($id); 
     120 
    120121            $res = $q->execute($params); 
    121122 
  • branches/1.1/tests/Cache/FileTestCase.php

    r4030 r5014  
    11<?php 
     2 
     3 
    24class Doctrine_Cache_File_TestCase extends Doctrine_UnitTestCase { 
    35    public function setUp() { 
  • branches/1.1/tests/Data/ImportTestCase.php

    r5008 r5014  
    6868 
    6969            $user = $query->execute()->getFirst(); 
    70              
     70 
    7171            $this->assertEqual($user->name, 'jwage'); 
    7272            $this->assertEqual($user->Phonenumber->count(), 1); 
     
    136136            $this->conn->clear(); 
    137137 
    138             $query = new Doctrine_Query(); 
     138            $query = Doctrine_Query::create(); 
    139139            $query->from('User u, u.Phonenumber') 
    140140                  ->where('u.name = ?', 'jwage2'); 
  • branches/1.1/tests/Query/CacheTestCase.php

    r4794 r5014  
    3737    { 
    3838        $cache = new Doctrine_Cache_Array(); 
    39         $q = new Doctrine_Query(); 
    40         $q->select('u.name')->from('User u')->leftJoin('u.Phonenumber p')->where('u.name = ?', 'walhala') 
    41                 ->useQueryCache($cache); 
    42          
     39 
     40        $q = Doctrine_Query::create() 
     41            ->select('u.id, u.name, p.id') 
     42            ->from('User u') 
     43            ->leftJoin('u.Phonenumber p') 
     44            ->where('u.name = ?', 'walhala') 
     45            ->useQueryCache($cache); 
     46 
    4347        $coll = $q->execute(); 
    4448         
     
    5559    { 
    5660        $cache = new Doctrine_Cache_Array(); 
     61         
    5762        Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_QUERY_CACHE, $cache); 
    5863         
    59         $q = new Doctrine_Query(); 
    60         $q->select('u.name')->from('User u')->leftJoin('u.Phonenumber p'); 
    61          
     64        $q = Doctrine_Query::create() 
     65            ->select('u.id, u.name, p.id') 
     66            ->from('User u') 
     67            ->leftJoin('u.Phonenumber p'); 
     68 
    6269        $coll = $q->execute(); 
    6370         
     
    7178    } 
    7279 
    73     public function testResultSetCacheAddsResultSetsIntoCache() 
     80    /*public function testResultSetCacheAddsResultSetsIntoCache() 
    7481    { 
    7582        $q = new Doctrine_Query(); 
     
    243250        $this->assertEqual($cache->count(), 0); 
    244251        $this->assertEqual(count($coll), 0); 
    245     } 
     252    }*/ 
    246253     
    247254} 
  • branches/1.1/tests/Query/SelectTestCase.php

    r4847 r5014  
    245245    } 
    246246 
     247    public function testWhereInSupportInDql() 
     248    { 
     249        $q = Doctrine_Query::create() 
     250            ->select('u.id, p.id') 
     251            ->from('User u') 
     252            ->leftJoin('u.Phonenumber p') 
     253            ->where('u.id IN ?'); 
     254 
     255        $params = array(array(4, 5, 6)); 
     256 
     257        $this->assertEqual( 
     258            $q->getSqlQuery($params), 
     259            'SELECT e.id AS e__id, p.id AS p__id FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE e.id IN (?, ?, ?) AND (e.type = 0)' 
     260        ); 
     261 
     262        $users = $q->execute($params, Doctrine::HYDRATE_ARRAY); 
     263         
     264        $this->assertEqual(count($users), 3); 
     265    } 
    247266} 
  • branches/1.1/tests/Query/WhereTestCase.php

    r4768 r5014  
    3636    public function prepareData()  
    3737    { } 
     38 
    3839    public function prepareTables()  
    3940    { 
     
    4243    } 
    4344 
    44     public function testDirectParameterSetting()  
     45    public function testDirectParameterSetting() 
    4546    { 
    4647        $this->connection->clear(); 
     
    108109        $this->assertEqual($users[1]->name, 'someone.2'); 
    109110    } 
    110     public function testDirectMultipleParameterSetting2()  
    111     { 
    112         $q = new Doctrine_Query(); 
    113  
    114         $q->from('User')->where('User.id IN (?, ?)', array(1, 2)); 
    115          
    116         $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id FROM entity e WHERE e.id IN (?, ?) AND (e.type = 0)'); 
     111     
     112    public function testDirectMultipleParameterSetting2() 
     113    { 
     114        $q = Doctrine_Query::create() 
     115            ->from('User') 
     116            ->where('User.id IN (?, ?)', array(1, 2)); 
     117 
     118        $this->assertEqual($q->getSqlQuery(), 'SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id FROM entity e WHERE e.id IN (?, ?) AND (e.type = 0)'); 
    117119 
    118120        $users = $q->execute(); 
     
    131133        $this->assertEqual($users[1]->name, 'someone.2'); 
    132134    } 
    133     public function testNotInExpression()  
     135     
     136    public function testNotInExpression() 
    134137    { 
    135138        $q = new Doctrine_Query(); 
     
    141144        $this->assertEqual($users[0]->name, 'someone.2'); 
    142145    } 
     146 
    143147    public function testExistsExpression()  
    144148    { 
     
    179183        $this->assertEqual($users[1]->name, 'someone.2'); 
    180184    } 
     185 
    181186    public function testComponentAliases()  
    182187    { 
     
    192197 
    193198    } 
     199 
    194200    public function testComponentAliases2()  
    195201    { 
     
    203209        $this->assertEqual($users[0]->name, 'someone'); 
    204210    } 
     211 
    205212    public function testOperatorWithNoTrailingSpaces() 
    206213    { 
     
    214221        $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id FROM entity e WHERE e.name = 'someone' AND (e.type = 0)"); 
    215222    } 
     223 
    216224    public function testOperatorWithNoTrailingSpaces2()  
    217225    { 
     
    225233        $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id FROM entity e WHERE e.name = 'foo.bar' AND (e.type = 0)"); 
    226234    } 
     235 
    227236    public function testOperatorWithSingleTrailingSpace()  
    228237    { 
     
    236245        $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id FROM entity e WHERE e.name = 'foo.bar' AND (e.type = 0)"); 
    237246    } 
     247 
    238248    public function testOperatorWithSingleTrailingSpace2()  
    239249    { 
     
    247257        $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id FROM entity e WHERE e.name = 'foo.bar' AND (e.type = 0)"); 
    248258    } 
     259 
    249260    public function testDeepComponentReferencingIsSupported() 
    250261    { 
     
    255266        $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id FROM entity e LEFT JOIN groupuser g ON e.id = g.user_id LEFT JOIN entity e2 ON e2.id = g.group_id AND e2.type = 1 WHERE e2.name = 'some group' AND (e.type = 0)"); 
    256267    } 
     268 
    257269    public function testDeepComponentReferencingIsSupported2() 
    258270    { 
  • branches/1.1/tests/QueryTestCase.php

    r4848 r5014  
    3434{ 
    3535 
     36    public function testWhereInSupportInDql() 
     37    { 
     38        $q = Doctrine_Query::create() 
     39            ->from('User u') 
     40            ->where('u.id IN ?', array(array(1, 2, 3))) 
     41            ->whereNotIn('u.name', array('', 'a')) 
     42            ->addWhere('u.id NOT IN ?', array(array(4, 5, 6, 7))); 
     43 
     44        $this->assertEqual( 
     45            $q->getSqlQuery(), 
     46            'SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id FROM entity e WHERE e.id IN (?, ?, ?) AND e.name NOT IN (?, ?) AND e.id NOT IN (?, ?, ?, ?) AND (e.type = 0)' 
     47        ); 
     48    } 
     49     
     50     
     51    public function testWhereInSupportInDql2() 
     52    { 
     53        $q = Doctrine_Query::create() 
     54            ->from('User u') 
     55            ->where('u.id IN ?', array(1)); 
     56 
     57        $this->assertEqual( 
     58            $q->getSqlQuery(), 
     59            'SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id FROM entity e WHERE e.id IN (?) AND (e.type = 0)' 
     60        ); 
     61    } 
     62 
     63     
    3664    public function testGetQueryHookResetsTheManuallyAddedDqlParts() 
    3765    { 
     
    275303} 
    276304 
     305 
    277306class MyQuery extends Doctrine_Query 
    278307{ 
  • branches/1.1/tests/Relation/NestTestCase.php

    r3884 r5014  
    3535    public function prepareData()  
    3636    { } 
     37 
    3738    public function prepareTables() 
    3839    { 
     
    4142        parent::prepareTables(); 
    4243    } 
     44 
    4345    public function testInitJoinTableSelfReferencingInsertingData()  
    4446    { 
     
    7981        $this->assertEqual(($count + 13), $this->conn->count()); 
    8082    } 
     83 
    8184    public function testNestRelationsFetchingData() 
    8285    {     
     
    8891        $this->assertTrue($e->Entity[0] instanceof Entity); 
    8992        $this->assertTrue($e->Entity[1] instanceof Entity); 
    90  
     93         
    9194        $this->assertEqual($e->Entity[0]->name, 'Friend 1'); 
    9295        $this->assertEqual($e->Entity[1]->name, 'Friend 2'); 
     
    127130        $this->assertTrue($e->Entity[1] instanceof Entity); 
    128131 
    129  
    130  
    131132        $this->assertEqual(count($this->conn), ($count + 1)); 
    132133 
     
    161162        $this->assertEqual($coll->count(), 1); 
    162163    } 
     164 
    163165    public function testNestRelationsParsing() 
    164166    { 
     
    201203        $this->connection->clear(); 
    202204    } 
     205 
    203206    public function testEqualNestRelationsLoading() 
    204207    { 
     
    207210        $this->assertEqual($nest->Relatives->count(), 5); 
    208211    } 
     212 
    209213    public function testNestRelationsQuerying() 
    210214    { 
     
    219223        $this->assertEqual($n[0]->Parents->count(), 3); 
    220224    } 
     225 
    221226    public function testNestRelationsQuerying2() 
    222227    { 
  • branches/1.1/tests/run.php

    r5002 r5014  
    308308// Query Tests 
    309309$query_tests = new GroupTest('Query Tests','query'); 
     310$query_tests->addTestCase(new Doctrine_Query_TestCase()); 
    310311$query_tests->addTestCase(new Doctrine_Query_Condition_TestCase()); 
    311312$query_tests->addTestCase(new Doctrine_Query_MultiJoin_TestCase()); 
     
    332333$query_tests->addTestCase(new Doctrine_Query_JoinCondition_TestCase()); 
    333334$query_tests->addTestCase(new Doctrine_Query_MultipleAggregateValue_TestCase()); 
    334 $query_tests->addTestCase(new Doctrine_Query_TestCase()); 
    335335$query_tests->addTestCase(new Doctrine_Query_MysqlSubquery_TestCase()); 
    336336$query_tests->addTestCase(new Doctrine_Query_PgsqlSubquery_TestCase()); 
  • branches/1.1/tests/Ticket/424BTestCase.php

    r3884 r5014  
    7878        $alan  = $this->newUser(3, 'Alan',  array($groupB, $groupC)); 
    7979 
    80         $q = new Doctrine_Query(); 
     80        $q = Doctrine_Query::create(); 
    8181        $gu = $q->from('mmrGroupUser_B')->execute(); 
    8282        $this->assertEqual(count($gu), 6); 
    8383 
    8484        // Direct query 
    85         $q = new Doctrine_Query(); 
     85        $q = Doctrine_Query::create(); 
    8686        $gu = $q->from('mmrGroupUser_B')->where('group_id = ?', $groupA->id)->execute(); 
    8787        $this->assertEqual(count($gu), 2); 
    8888 
    8989        // Query by join 
    90         $q = new Doctrine_Query(); 
    91         $userOfGroupAByName = $q->from('mmrUser_B u, u.Group g') 
    92                                 ->where('g.name = ?', array($groupA->name)); 
    93         $q->execute(); 
     90        $q = Doctrine_Query::create() 
     91            ->from('mmrUser_B u, u.Group g') 
     92            ->where('g.name = ?', array($groupA->name)); 
     93 
     94        $userOfGroupAByName = $q->execute(); 
     95 
    9496        $this->assertEqual(count($userOfGroupAByName), 2); 
    9597 
  • branches/1.1/tests/Ticket/424CTestCase.php

    r3884 r5014  
    7676      $alan  = $this->newUser(3, 'Alan',  array($groupB, $groupC)); 
    7777 
    78       $q = new Doctrine_Query();             
     78      $q = Doctrine_Query::create(); 
    7979      $gu = $q->from('mmrGroupUser_C')->execute(); 
    8080      $this->assertEqual(count($gu), 6); 
    8181 
    8282      // Direct query 
    83       $q = new Doctrine_Query();             
     83      $q = Doctrine_Query::create(); 
    8484      $gu = $q->from('mmrGroupUser_C')->where('group_id = ?', $groupA->id)->execute(); 
    8585      $this->assertEqual(count($gu), 2); 
    8686 
    8787      // Query by join 
    88       $q = new Doctrine_Query(); 
    89       $userOfGroupAByName = $q->from('mmrUser_C u, u.Group g') 
    90                               ->where('g.name = ?', array($groupA->name)); 
     88      $q = Doctrine_Query::create() 
     89            ->from('mmrUser_C u, u.Group g') 
     90            ->where('g.name = ?', array($groupA->name)); 
    9191 
    92       $q->execute(); 
     92      $userOfGroupAByName = $q->execute(); 
    9393 
    9494      $this->assertEqual(count($userOfGroupAByName), 2);