Commit f26217c8 authored by zYne's avatar zYne

DQL core refactored

parent b50aceec
......@@ -20,7 +20,7 @@
*/
Doctrine::autoload('Doctrine_Hydrate');
/**
* Doctrine_Query2
* Doctrine_Query
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
......@@ -30,7 +30,7 @@ Doctrine::autoload('Doctrine_Hydrate');
* @version $Revision: 1296 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
class Doctrine_Query extends Doctrine_Hydrate2 implements Countable
{
/**
* @param array $subqueryAliases the table aliases needed in some LIMIT subqueries
......@@ -88,7 +88,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
*/
public static function create()
{
return new Doctrine_Query2();
return new Doctrine_Query();
}
/**
* isSubquery
......@@ -205,7 +205,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
*/
public function parseSelect($dql)
{
$refs = Doctrine_Query::bracketExplode($dql, ',');
$refs = Doctrine_Tokenizer::bracketExplode($dql, ',');
foreach ($refs as $reference) {
if (strpos($reference, '(') !== false) {
......@@ -237,7 +237,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
*/
public function parseSubselect($reference)
{
$e = Doctrine_Query::bracketExplode($reference, ' ');
$e = Doctrine_Tokenizer::bracketExplode($reference, ' ');
$alias = $e[1];
if (count($e) > 2) {
......@@ -253,7 +253,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
}
public function parseAggregateFunction2($func)
{
$e = Doctrine_Query::bracketExplode($func, ' ');
$e = Doctrine_Tokenizer::bracketExplode($func, ' ');
$func = $e[0];
$pos = strpos($func, '(');
......
......@@ -87,30 +87,30 @@ class Doctrine_RawSql extends Doctrine_Hydrate
foreach ($e as $k => $part) {
$low = strtolower($part);
switch (strtolower($part)) {
case "select":
case "from":
case "where":
case "limit":
case "offset":
case "having":
case 'select':
case 'from':
case 'where':
case 'limit':
case 'offset':
case 'having':
$p = $low;
if ( ! isset($parts[$low])) {
$parts[$low] = array();
}
break;
case "order":
case "group":
case 'order':
case 'group':
$i = ($k + 1);
if (isset($e[$i]) && strtolower($e[$i]) === "by") {
if (isset($e[$i]) && strtolower($e[$i]) === 'by') {
$p = $low;
$p .= "by";
$parts[$low."by"] = array();
$p .= 'by';
$parts[$low.'by'] = array();
} else {
$parts[$p][] = $part;
}
break;
case "by":
case 'by':
continue;
default:
if ( ! isset($parts[$p][0])) {
......@@ -118,11 +118,11 @@ class Doctrine_RawSql extends Doctrine_Hydrate
} else {
$parts[$p][0] .= ' '.$part;
}
};
};
}
}
$this->parts = $parts;
$this->parts["select"] = array();
$this->parts['select'] = array();
return $this;
}
......@@ -149,12 +149,12 @@ class Doctrine_RawSql extends Doctrine_Hydrate
if ($e[1] == '*') {
foreach ($this->tables[$e[0]]->getColumnNames() as $name) {
$field = $e[0].".".$name;
$this->parts["select"][$field] = $field." AS ".$e[0]."__".$name;
$field = $e[0] . '.' . $name;
$this->parts['select'][$field] = $field . ' AS ' . $e[0] . '__' . $name;
}
} else {
$field = $e[0].".".$e[1];
$this->parts["select"][$field] = $field." AS ".$e[0]."__".$e[1];
$field = $e[0] . '.' . $e[1];
$this->parts['select'][$field] = $field . ' AS ' . $e[0] . '__' . $e[1];
}
}
......@@ -163,13 +163,13 @@ class Doctrine_RawSql extends Doctrine_Hydrate
foreach ($this->tableAliases as $alias) {
foreach ($this->tables[$alias]->getPrimaryKeys() as $key) {
$field = $alias . '.' . $key;
if ( ! isset($this->parts["select"][$field])) {
$this->parts["select"][$field] = $field." AS ".$alias."__".$key;
if ( ! isset($this->parts['select'][$field])) {
$this->parts['select'][$field] = $field . ' AS ' . $alias . '__' . $key;
}
}
}
$q = 'SELECT '.implode(', ', $this->parts['select']);
$q = 'SELECT ' . implode(', ', $this->parts['select']);
$string = $this->applyInheritance();
if ( ! empty($string)) {
......@@ -216,8 +216,10 @@ class Doctrine_RawSql extends Doctrine_Hydrate
foreach ($e as $k => $component) {
$currPath .= '.' . $component;
if ($k == 0)
if ($k == 0) {
$currPath = substr($currPath,1);
}
if (isset($this->tableAliases[$currPath])) {
$alias = $this->tableAliases[$currPath];
......@@ -230,12 +232,12 @@ class Doctrine_RawSql extends Doctrine_Hydrate
}
$table = $this->conn->getTable($component);
$this->tables[$alias] = $table;
$this->fetchModes[$alias] = Doctrine::FETCH_IMMEDIATE;
$this->tableAliases[$currPath] = $alias;
if ($k !== 0) {
$this->joins[$alias] = $prevAlias;
}
$prevAlias = $alias;
$prevPath = $currPath;
}
......
......@@ -19,9 +19,11 @@
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Table represents a database table
* each Doctrine_Table holds the information of foreignKeys and associations
* Doctrine_Table
*
* This class represents a database table.
* Each Doctrine_Table holds the information of foreignKeys and associations
* to other tables.
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @package Doctrine
......@@ -54,10 +56,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
* @var integer $identifierType the type of identifier this table uses
*/
private $identifierType;
/**
* @var string $query cached simple query
*/
private $query;
/**
* @var Doctrine_Connection $conn Doctrine_Connection object that created this table
*/
......@@ -284,19 +282,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$this->identifier = $pk;
}
}
};
/**
if ( ! isset($definition['values'])) {
throw new Doctrine_Table_Exception('No values set for enum column ' . $name);
}
if ( ! is_array($definition['values'])) {
throw new Doctrine_Table_Exception('Enum column values should be specified as an array.');
}
*/
}
} else {
throw new Doctrine_Table_Exception("Class '$name' has no table definition.");
......@@ -313,9 +299,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
array_pop($names);
$this->options['parents'] = $names;
$this->query = 'SELECT ' . implode(', ', array_keys($this->columns)) . ' FROM ' . $this->getTableName();
$this->repository = new Doctrine_Table_Repository($this);
}
/**
......@@ -1043,7 +1026,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$id = array_values($id);
}
$query = $this->query . ' WHERE ' . implode(' = ? AND ', $this->primaryKeys) . ' = ?';
$query = 'SELECT ' . implode(', ', array_keys($this->columns)) . ' FROM ' . $this->getTableName() . ' WHERE ' . implode(' = ? AND ', $this->primaryKeys) . ' = ?';
$query = $this->applyInheritance($query);
$params = array_merge($id, array_values($this->options['inheritanceMap']));
......@@ -1430,15 +1413,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$data = $stmt->fetch(PDO::FETCH_NUM);
return isset($data[0])?$data[0]:1;
}
/**
* returns simple cached query
*
* @return string
*/
final public function getQuery()
{
return $this->query;
}
/**
* returns internal data, used by Doctrine_Record instances
* when retrieving data from database
......
This diff is collapsed.
......@@ -999,7 +999,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
case Doctrine_Record::STATE_TCLEAN:
// do nothing
break;
};
}
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onSave($record);
}
......
This diff is collapsed.
......@@ -50,8 +50,9 @@ class Doctrine_Hydrate_Alias
$name = substr($alias, 0, 1);
$i = ((int) substr($alias, 1));
if ($i == 0)
if ($i == 0) {
$i = 1;
}
$newIndex = ($this->shortAliasIndexes[$name] + $i);
......@@ -65,6 +66,15 @@ class Doctrine_Hydrate_Alias
{
return (isset($this->shortAliases[$tableName]));
}
public function getComponentAlias($tableAlias)
{
if ( ! isset($this->shortAliases[$tableAlias])) {
throw new Doctrine_Hydrate_Exception('Unknown table alias ' . $tableAlias);
}
return $this->shortAliases[$tableAlias];
}
public function getShortAliasIndex($alias)
{
if ( ! isset($this->shortAliasIndexes[$alias])) {
......@@ -72,7 +82,7 @@ class Doctrine_Hydrate_Alias
}
return $this->shortAliasIndexes[$alias];
}
public function generateShortAlias($tableName)
public function generateShortAlias($componentAlias, $tableName)
{
$char = strtolower(substr($tableName, 0, 1));
......@@ -84,18 +94,35 @@ class Doctrine_Hydrate_Alias
while (isset($this->shortAliases[$alias])) {
$alias = $char . ++$this->shortAliasIndexes[$alias];
}
$this->shortAliases[$alias] = $tableName;
$this->shortAliases[$alias] = $componentAlias;
return $alias;
}
public function getShortAlias($tableName)
/**
* getShortAlias
* some database such as Oracle need the identifier lengths to be < ~30 chars
* hence Doctrine creates as short identifier aliases as possible
*
* this method is used for the creation of short table aliases, its also
* smart enough to check if an alias already exists for given component (componentAlias)
*
* @param string $componentAlias the alias for the query component to search table alias for
* @param string $tableName the table name from which the table alias is being created
* @return string the generated / fetched short alias
*/
public function getShortAlias($componentAlias, $tableName = null)
{
$alias = array_search($tableName, $this->shortAliases);
$alias = array_search($componentAlias, $this->shortAliases);
if ($alias !== false) {
return $alias;
}
return $this->generateShortAlias($tableName);
if ($tableName === null) {
throw new Doctrine_Hydrate_Exception("Couldn't get short alias for " . $componentAlias);
}
return $this->generateShortAlias($componentAlias, $tableName);
}
}
......@@ -63,13 +63,14 @@ class Doctrine_Lib
*/
public static function getRecordAsString(Doctrine_Record $record)
{
$r[] = "<pre>";
$r[] = "Component : ".$record->getTable()->getComponentName();
$r[] = "ID : ".$record->obtainIdentifier();
$r[] = "References : ".count($record->getReferences());
$r[] = "State : ".Doctrine_Lib::getRecordStateAsString($record->getState());
$r[] = "OID : ".$record->getOID();
$r[] = "</pre>";
$r[] = '<pre>';
$r[] = 'Component : ' . $record->getTable()->getComponentName();
$r[] = 'ID : ' . $record->obtainIdentifier();
$r[] = 'References : ' . count($record->getReferences());
$r[] = 'State : ' . Doctrine_Lib::getRecordStateAsString($record->getState());
$r[] = 'OID : ' . $record->getOID();
$r[] = 'data : ' . Doctrine::dump($record->getData(), false);
$r[] = '</pre>';
return implode("\n",$r)."<br />";
}
/**
......@@ -84,12 +85,12 @@ class Doctrine_Lib
public static function getCollectionAsXml(Doctrine_Collection $collection, SimpleXMLElement $incomming_xml = null){
$collection_name = Doctrine_Lib::plurelize($collection->getTable()->name);
$collectionName = Doctrine_Lib::plurelize($collection->getTable()->name);
if (!isset($incomming_xml)) {
$xml = new SimpleXMLElement("<" . $collection_name . "></" . $collection_name . ">");
if ( ! isset($incomming_xml)) {
$xml = new SimpleXMLElement("<" . $collectionName . "></" . $collectionName . ">");
} else {
$xml = $incomming_xml->addChild($collection_name);
$xml = $incomming_xml->addChild($collectionName);
}
foreach ($collection as $key => $record) {
Doctrine_Lib::getRecordAsXml($record, $xml);
......
This diff is collapsed.
......@@ -39,32 +39,32 @@ abstract class Doctrine_Query_Condition extends Doctrine_Query_Part
* @param string $str
* @return string
*/
final public function parse($str)
public function _parse($str)
{
$tmp = trim($str);
$parts = Doctrine_Query::bracketExplode($str, array(' \&\& ', ' AND '), '(', ')');
$parts = Doctrine_Tokenizer::bracketExplode($str, array(' \&\& ', ' AND '), '(', ')');
if (count($parts) > 1) {
$ret = array();
foreach ($parts as $part) {
$part = Doctrine_Query::bracketTrim($part, '(', ')');
$ret[] = $this->parse($part);
$part = Doctrine_Tokenizer::bracketTrim($part, '(', ')');
$ret[] = $this->_parse($part);
}
$r = implode(' AND ',$ret);
$r = implode(' AND ', $ret);
} else {
$parts = Doctrine_Query::bracketExplode($str, array(' \|\| ', ' OR '), '(', ')');
$parts = Doctrine_Tokenizer::bracketExplode($str, array(' \|\| ', ' OR '), '(', ')');
if (count($parts) > 1) {
$ret = array();
foreach ($parts as $part) {
$part = Doctrine_Query::bracketTrim($part, '(', ')');
$ret[] = $this->parse($part);
$part = Doctrine_Tokenizer::bracketTrim($part, '(', ')');
$ret[] = $this->_parse($part);
}
$r = implode(' OR ', $ret);
} else {
if (substr($parts[0],0,1) == '(' && substr($parts[0],-1) == ')') {
return $this->parse(substr($parts[0],1,-1));
if (substr($parts[0],0,1) == '(' && substr($parts[0], -1) == ')') {
return $this->_parse(substr($parts[0], 1, -1));
} else {
return $this->load($parts[0]);
}
......@@ -73,6 +73,9 @@ abstract class Doctrine_Query_Condition extends Doctrine_Query_Part
return '(' . $r . ')';
}
/**
* parses a literal value and returns the parsed value
*
......
......@@ -39,11 +39,10 @@ class Doctrine_Query_From extends Doctrine_Query_Part
* @param string $str
* @return void
*/
final public function parse($str)
public function parse($str)
{
$str = trim($str);
$parts = Doctrine_Query::bracketExplode($str, 'JOIN');
$parts = Doctrine_Tokenizer::bracketExplode($str, 'JOIN');
$operator = false;
......@@ -52,8 +51,10 @@ class Doctrine_Query_From extends Doctrine_Query_Part
$operator = ':';
case 'LEFT':
array_shift($parts);
break;
}
$last = '';
foreach ($parts as $k => $part) {
......@@ -70,7 +71,7 @@ class Doctrine_Query_From extends Doctrine_Query_Part
}
$part = implode(' ', $e);
foreach (Doctrine_Query::bracketExplode($part, ',') as $reference) {
foreach (Doctrine_Tokenizer::bracketExplode($part, ',') as $reference) {
$reference = trim($reference);
$e = explode('.', $reference);
......@@ -83,6 +84,7 @@ class Doctrine_Query_From extends Doctrine_Query_Part
$operator = ($last == 'INNER') ? ':' : '.';
}
return $this->query;
}
}
......@@ -39,7 +39,7 @@ class Doctrine_Query_Groupby extends Doctrine_Query_Part
* @param string $str
* @return void
*/
final public function parse($str)
public function parse($str, $append = false)
{
$r = array();
foreach (explode(',', $str) as $reference) {
......@@ -47,10 +47,15 @@ class Doctrine_Query_Groupby extends Doctrine_Query_Part
$e = explode('.', $reference);
$field = array_pop($e);
$ref = implode('.', $e);
$table = $this->query->load($ref);
$component = $table->getComponentName();
$r[] = $this->query->getTableAlias($ref).".".$field;
$this->query->load($ref);
$r[] = $this->query->getTableAlias($ref) . '.' . $field;
}
if ($append) {
$this->query->addQueryPart('groupby', implode(', ', $r));
} else {
$this->query->setQueryPart('groupby', implode(', ', $r));
}
return implode(', ', $r);
return $this->query;
}
}
......@@ -32,6 +32,15 @@ Doctrine::autoload('Doctrine_Query_Condition');
*/
class Doctrine_Query_Having extends Doctrine_Query_Condition
{
public function parse($str, $append = false)
{
if ($append) {
$this->query->addQueryPart('having', $this->_parse($str));
} else {
$this->query->setQueryPart('having', $this->_parse($str));
}
return $this->query;
}
/**
* DQL Aggregate Function parser
*
......@@ -47,7 +56,7 @@ class Doctrine_Query_Having extends Doctrine_Query_Condition
$name = substr($func, 0, $pos);
$func = substr($func, ($pos + 1), -1);
$params = Doctrine_Query::bracketExplode($func, ',', '(', ')');
$params = Doctrine_Tokenizer::bracketExplode($func, ',', '(', ')');
foreach ($params as $k => $param) {
$params[$k] = $this->parseAggregateFunction($param);
......@@ -64,8 +73,8 @@ class Doctrine_Query_Having extends Doctrine_Query_Condition
if (count($a) > 1) {
$field = array_pop($a);
$reference = implode('.', $a);
$table = $this->query->load($reference, false);
$field = $table->getColumnName($field);
$map = $this->query->load($reference, false);
$field = $map['table']->getColumnName($field);
$func = $this->query->getTableAlias($reference) . '.' . $field;
} else {
$field = end($a);
......@@ -86,7 +95,7 @@ class Doctrine_Query_Having extends Doctrine_Query_Condition
*/
final public function load($having)
{
$e = Doctrine_Query::bracketExplode($having, ' ', '(', ')');
$e = Doctrine_Tokenizer::bracketExplode($having, ' ', '(', ')');
$r = array_shift($e);
$t = explode('(', $r);
......
......@@ -36,7 +36,7 @@ class Doctrine_Query_JoinCondition extends Doctrine_Query_Condition
{
$condition = trim($condition);
$e = Doctrine_Query::sqlExplode($condition);
$e = Doctrine_Tokenizer::sqlExplode($condition);
if(count($e) > 2) {
$a = explode('.', $e[0]);
......@@ -46,15 +46,15 @@ class Doctrine_Query_JoinCondition extends Doctrine_Query_Condition
$value = $e[2];
$alias = $this->query->getTableAlias($reference);
$table = $this->query->getTable($alias);
$map = $this->query->getDeclaration($reference);
$table = $map['table'];
// check if value is enumerated value
$enumIndex = $table->enumIndex($field, trim($value, "'"));
if (substr($value, 0, 1) == '(') {
// trim brackets
$trimmed = Doctrine_Query::bracketTrim($value);
$trimmed = Doctrine_Tokenizer::bracketTrim($value);
if (substr($trimmed, 0, 4) == 'FROM' || substr($trimmed, 0, 6) == 'SELECT') {
// subquery found
......@@ -64,7 +64,7 @@ class Doctrine_Query_JoinCondition extends Doctrine_Query_Condition
$value = '(' . substr($trimmed, 4) . ')';
} else {
// simple in expression found
$e = Doctrine_Query::sqlExplode($trimmed, ',');
$e = Doctrine_Tokenizer::sqlExplode($trimmed, ',');
$value = array();
foreach ($e as $part) {
......
<?php
/*
* $Id: Where.php 1352 2007-05-15 10:07:05Z zYne $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Query_Limit
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 1352 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_Query_Limit extends Doctrine_Query_Part
{
public function parse($limit)
{
$this->query->setQueryPart('limit', (int) $limit);
return $this->query;
}
}
<?php
/*
* $Id: Where.php 1352 2007-05-15 10:07:05Z zYne $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Query_Offset
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 1352 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_Query_Offset extends Doctrine_Query_Part
{
public function parse($offset)
{
$this->query->setQueryPart('offset', (int) $offset);
return $this->query;
}
}
......@@ -39,7 +39,7 @@ class Doctrine_Query_Orderby extends Doctrine_Query_Part
* @param string $str
* @return void
*/
public function parse($str)
public function parse($str, $append = false)
{
$ret = array();
......@@ -53,12 +53,10 @@ class Doctrine_Query_Orderby extends Doctrine_Query_Part
$reference = implode('.', $a);
$name = end($a);
$this->query->load($reference, false);
$alias = $this->query->getTableAlias($reference);
$map = $this->query->load($reference, false);
$tableAlias = $this->query->getTableAlias($reference);
$tname = $this->query->getTable($alias)->getTableName();
$r = $alias . '.' . $field;
$r = $tableAlias . '.' . $field;
} else {
......@@ -72,6 +70,11 @@ class Doctrine_Query_Orderby extends Doctrine_Query_Part
$ret[] = $r;
}
return implode(', ', $ret);
if ($append) {
$this->query->addQueryPart('orderby', implode(', ', $ret));
} else {
$this->query->setQueryPart('orderby', implode(', ', $ret));
}
return $this->query;
}
}
......@@ -34,11 +34,11 @@ class Doctrine_Query_Set extends Doctrine_Query_Part
{
public function parse($dql)
{
$parts = Doctrine_Query::sqlExplode($dql, ',');
$parts = Doctrine_Tokenizer::sqlExplode($dql, ',');
$result = array();
foreach ($parts as $part) {
$set = Doctrine_Query::sqlExplode($part, '=');
$set = Doctrine_Tokenizer::sqlExplode($part, '=');
$e = explode('.', trim($set[0]));
$field = array_pop($e);
......@@ -46,12 +46,15 @@ class Doctrine_Query_Set extends Doctrine_Query_Part
$reference = implode('.', $e);
$alias = $this->query->getTableAlias($reference);
$table = $this->query->getTable($alias);
$result[] = $table->getColumnName($field) . ' = ' . $set[1];
$map = $this->query->getDeclaration($reference);
$result[] = $map['table']->getColumnName($field) . ' = ' . $set[1];
}
return implode(', ', $result);
$this->query->addQueryPart('set', implode(', ', $result));
return $this->query;
}
}
......@@ -32,6 +32,15 @@ Doctrine::autoload('Doctrine_Query_Condition');
*/
class Doctrine_Query_Where extends Doctrine_Query_Condition
{
public function parse($str, $append = false)
{
if ($append) {
$this->query->addQueryPart('where', $this->_parse($str));
} else {
$this->query->setQueryPart('where', $this->_parse($str));
}
return $this->query;
}
/**
* load
* returns the parsed query part
......@@ -43,7 +52,7 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
{
$where = trim($where);
$e = Doctrine_Query::sqlExplode($where);
$e = Doctrine_Tokenizer::sqlExplode($where);
if (count($e) > 1) {
$tmp = $e[0] . ' ' . $e[1];
......@@ -56,7 +65,7 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
}
if (count($e) < 3) {
$e = Doctrine_Query::sqlExplode($where, array('=', '<', '>', '!='));
$e = Doctrine_Tokenizer::sqlExplode($where, array('=', '<', '>', '!='));
}
$r = array_shift($e);
......@@ -83,7 +92,6 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
$field = array_pop($a);
$reference = implode('.', $a);
$table = $this->query->load($reference, false);
$field = $table->getColumnName($field);
array_pop($a);
......@@ -119,9 +127,10 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
throw new Doctrine_Query_Exception('Unknown DQL function: '.$func);
}
} else {
$table = $this->query->load($reference, false);
$map = $this->query->load($reference, false);
$alias = $this->query->getTableAlias($reference);
$table = $this->query->getTable($alias);
$table = $map['table'];
$field = $table->getColumnName($field);
// check if value is enumerated value
......@@ -129,10 +138,9 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
if (substr($value, 0, 1) == '(') {
// trim brackets
$trimmed = Doctrine_Query::bracketTrim($value);
$trimmed = Doctrine_Tokenizer::bracketTrim($value);
if (substr($trimmed, 0, 4) == 'FROM' || substr($trimmed, 0, 6) == 'SELECT') {
// subquery found
$q = new Doctrine_Query();
$value = '(' . $q->isSubquery(true)->parseQuery($trimmed)->getQuery() . ')';
......@@ -141,11 +149,12 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
$value = '(' . substr($trimmed, 4) . ')';
} else {
// simple in expression found
$e = Doctrine_Query::sqlExplode($trimmed, ',');
$e = Doctrine_Tokenizer::sqlExplode($trimmed, ',');
$value = array();
foreach ($e as $part) {
$index = $table->enumIndex($field, trim($part, "'"));
if ($index !== false) {
$value[] = $index;
} else {
......@@ -198,10 +207,11 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
$pos = strpos($where, '(');
if ($pos == false)
if ($pos == false) {
throw new Doctrine_Query_Exception("Unknown expression, expected '('");
}
$sub = Doctrine_Query::bracketTrim(substr($where, $pos));
$sub = Doctrine_Tokenizer::bracketTrim(substr($where, $pos));
return $operator . ' (' . $this->query->createSubquery()->parseQuery($sub, false)->getQuery() . ')';
}
......@@ -226,14 +236,4 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
}
return $operator;
}
/**
* __toString
* return string representation of this object
*
* @return string
*/
public function __toString()
{
return ( ! empty($this->parts))?implode(' AND ', $this->parts):'';
}
}
......@@ -100,8 +100,9 @@ class Doctrine_Record_Filter
if (is_string($tmp[$name])) {
$value = unserialize($tmp[$name]);
if ($value === false)
if ($value === false) {
throw new Doctrine_Record_Exception('Unserialization of ' . $name . ' failed.');
}
} else {
$value = $tmp[$name];
}
......@@ -112,8 +113,9 @@ class Doctrine_Record_Filter
if ($tmp[$name] !== self::$null) {
$value = gzuncompress($tmp[$name]);
if ($value === false)
if ($value === false) {
throw new Doctrine_Record_Exception('Uncompressing of ' . $name . ' failed.');
}
$this->_data[$name] = $value;
}
......@@ -212,8 +214,9 @@ class Doctrine_Record_Filter
$a[$v] = $this->_table->enumIndex($v,$this->_data[$v]);
break;
default:
if ($this->_data[$v] instanceof Doctrine_Record)
if ($this->_data[$v] instanceof Doctrine_Record) {
$this->_data[$v] = $this->_data[$v]->getIncremented();
}
$a[$v] = $this->_data[$v];
}
......
......@@ -1125,6 +1125,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/
public function getRecord()
{
if ( ! empty($this->data)) {
$this->data = array_change_key_case($this->data, CASE_LOWER);
$key = $this->getIdentifier();
......@@ -1151,6 +1152,11 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$this->identityMap[$id] = $record;
}
$this->data = array();
} else {
$recordName = $this->getClassnameToReturn();
$record = new $recordName($this, true);
}
return $record;
}
......
......@@ -111,7 +111,7 @@ class Doctrine_Hydrate_TestCase extends Doctrine_UnitTestCase
}
*/
}
class Doctrine_Hydrate_Mock extends Doctrine_Hydrate2
class Doctrine_Hydrate_Mock extends Doctrine_Hydrate
{
protected $data;
......
......@@ -77,7 +77,7 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase
}
public function testAggregateValueIsMappedToNewRecordOnEmptyResultSet()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('COUNT(u.id) count')->from('User u');
......@@ -88,7 +88,7 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase
}
public function testAggregateValueIsMappedToRecord()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('u.name, COUNT(u.id) count')->from('User u')->groupby('u.name');
......@@ -105,7 +105,7 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase
public function testAggregateValueMappingSupportsLeftJoins()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('u.name, COUNT(p.id) count')->from('User u')->leftJoin('u.Phonenumber p')->groupby('u.id');
......@@ -120,7 +120,7 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase
}
public function testAggregateValueMappingSupportsLeftJoins2()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('MAX(u.name)')->from('User u')->leftJoin('u.Phonenumber p')->groupby('u.id');
......@@ -131,7 +131,7 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase
}
public function testAggregateValueMappingSupportsMultipleValues()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('u.name, COUNT(p.id) count, MAX(p.id) max')->from('User u')->innerJoin('u.Phonenumber p')->groupby('u.id');
......@@ -141,7 +141,7 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase
}
public function testAggregateValueMappingSupportsInnerJoins()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('u.name, COUNT(p.id) count')->from('User u')->innerJoin('u.Phonenumber p')->groupby('u.id');
......
......@@ -35,13 +35,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase
{
public function testDeleteAllWithColumnAggregationInheritance()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('DELETE FROM User');
$this->assertEqual($q->getQuery(), 'DELETE FROM entity WHERE (type = 0)');
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->delete()->from('User');
......@@ -49,13 +49,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase
}
public function testDeleteAll()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('DELETE FROM Entity');
$this->assertEqual($q->getQuery(), 'DELETE FROM entity');
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->delete()->from('Entity');
......@@ -63,13 +63,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase
}
public function testDeleteWithCondition()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('DELETE FROM Entity WHERE id = 3');
$this->assertEqual($q->getQuery(), 'DELETE FROM entity WHERE id = 3');
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->delete()->from('Entity')->where('id = 3');
......@@ -77,13 +77,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase
}
public function testDeleteWithLimit()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('DELETE FROM Entity LIMIT 20');
$this->assertEqual($q->getQuery(), 'DELETE FROM entity LIMIT 20');
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->delete()->from('Entity')->limit(20);
......@@ -91,13 +91,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase
}
public function testDeleteWithLimitAndOffset()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('DELETE FROM Entity LIMIT 10 OFFSET 20');
$this->assertEqual($q->getQuery(), 'DELETE FROM entity LIMIT 10 OFFSET 20');
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->delete()->from('Entity')->limit(10)->offset(20);
......
......@@ -34,7 +34,7 @@ class Doctrine_Query_From_TestCase extends Doctrine_UnitTestCase
{
public function testLeftJoin()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from('User u LEFT JOIN u.Group');
......@@ -43,7 +43,7 @@ class Doctrine_Query_From_TestCase extends Doctrine_UnitTestCase
public function testDefaultJoinIsLeftJoin()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from('User u JOIN u.Group');
......@@ -52,7 +52,7 @@ class Doctrine_Query_From_TestCase extends Doctrine_UnitTestCase
public function testInnerJoin()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from('User u INNER JOIN u.Group');
......@@ -61,7 +61,7 @@ class Doctrine_Query_From_TestCase extends Doctrine_UnitTestCase
public function testMultipleLeftJoin()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from('User u LEFT JOIN u.Group LEFT JOIN u.Phonenumber');
......@@ -69,7 +69,7 @@ class Doctrine_Query_From_TestCase extends Doctrine_UnitTestCase
}
public function testMultipleLeftJoin2()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from('User u LEFT JOIN u.Group LEFT JOIN u.Phonenumber');
......@@ -77,7 +77,7 @@ class Doctrine_Query_From_TestCase extends Doctrine_UnitTestCase
}
public function testMultipleInnerJoin()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('u.name')->from('User u INNER JOIN u.Group INNER JOIN u.Phonenumber');
......@@ -85,7 +85,7 @@ class Doctrine_Query_From_TestCase extends Doctrine_UnitTestCase
}
public function testMultipleInnerJoin2()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('u.name')->from('User u INNER JOIN u.Group, u.Phonenumber');
......@@ -97,7 +97,7 @@ class Doctrine_Query_From_TestCase extends Doctrine_UnitTestCase
}
public function testMixingOfJoins()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('u.name, g.name, p.phonenumber')->from('User u INNER JOIN u.Group g LEFT JOIN u.Phonenumber p');
......
......@@ -32,14 +32,14 @@
*/
class Doctrine_Query_Having_TestCase extends Doctrine_UnitTestCase {
public function testAggregateFunctionsInHavingReturnValidSql() {
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p HAVING COUNT(p.id) > 2');
$this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0) HAVING COUNT(p.id) > 2');
}
public function testAggregateFunctionsInHavingReturnValidSql2() {
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery("SELECT u.name FROM User u LEFT JOIN u.Phonenumber p HAVING MAX(u.name) = 'zYne'");
......
......@@ -39,7 +39,7 @@ class Doctrine_Query_IdentifierQuoting_TestCase extends Doctrine_UnitTestCase {
public function testQuerySupportsIdentifierQuoting() {
$this->connection->setAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER, true);
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('SELECT MAX(u.id), MIN(u.name) FROM User u');
......@@ -47,7 +47,7 @@ class Doctrine_Query_IdentifierQuoting_TestCase extends Doctrine_UnitTestCase {
}
public function testQuerySupportsIdentifierQuotingWithJoins() {
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p');
......@@ -55,7 +55,7 @@ class Doctrine_Query_IdentifierQuoting_TestCase extends Doctrine_UnitTestCase {
}
public function testLimitSubqueryAlgorithmSupportsIdentifierQuoting() {
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('SELECT u.name FROM User u INNER JOIN u.Phonenumber p')->limit(5);
......
......@@ -38,7 +38,7 @@ class Doctrine_Query_JoinCondition_TestCase extends Doctrine_UnitTestCase
{ }
public function testJoinConditionsAreSupportedForOneToManyLeftJoins()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery("SELECT u.name, p.id FROM User u LEFT JOIN u.Phonenumber p ON p.phonenumber = '123 123'");
......@@ -46,7 +46,7 @@ class Doctrine_Query_JoinCondition_TestCase extends Doctrine_UnitTestCase
}
public function testJoinConditionsAreSupportedForOneToManyInnerJoins()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery("SELECT u.name, p.id FROM User u INNER JOIN u.Phonenumber p ON p.phonenumber = '123 123'");
......@@ -54,7 +54,7 @@ class Doctrine_Query_JoinCondition_TestCase extends Doctrine_UnitTestCase
}
public function testJoinConditionsAreSupportedForManyToManyLeftJoins()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery("SELECT u.name, g.id FROM User u LEFT JOIN u.Group g ON g.id > 2");
......@@ -62,7 +62,7 @@ class Doctrine_Query_JoinCondition_TestCase extends Doctrine_UnitTestCase
}
public function testJoinConditionsAreSupportedForManyToManyInnerJoins()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery("SELECT u.name, g.id FROM User u INNER JOIN u.Group g ON g.id > 2");
......
......@@ -58,7 +58,7 @@ class Doctrine_Query_Join_TestCase extends Doctrine_UnitTestCase
}
public function testRecordHydrationWorksWithDeeplyNestedStructures()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('c.*, c2.*, d.*')
->from('Record_Country c')->leftJoin('c.City c2')->leftJoin('c2.District d')
......@@ -77,7 +77,7 @@ class Doctrine_Query_Join_TestCase extends Doctrine_UnitTestCase
}
public function testManyToManyJoinUsesProperTableAliases()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('u.name')->from('User u INNER JOIN u.Group g');
......@@ -86,7 +86,7 @@ class Doctrine_Query_Join_TestCase extends Doctrine_UnitTestCase
public function testSelfReferentialAssociationJoinsAreSupported()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('e.name')->from('Entity e INNER JOIN e.Entity e2');
......
......@@ -45,7 +45,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
public function testLimitWithOneToOneLeftJoin()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('u.id, e.*')->from('User u, u.Email e')->limit(5);
$users = $q->execute();
......@@ -55,7 +55,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
}
public function testLimitWithOneToOneInnerJoin()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('u.id, e.*')->from('User u, u:Email e')->limit(5);
$users = $q->execute();
......@@ -64,7 +64,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
}
public function testLimitWithOneToManyLeftJoin()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('u.id, p.*')->from('User u, u.Phonenumber p')->limit(5);
$sql = $q->getQuery();
......@@ -91,7 +91,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
public function testLimitWithOneToManyLeftJoinAndCondition()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('User.name')->from('User')->where("User.Phonenumber.phonenumber LIKE '%123%'")->limit(5);
$users = $q->execute();
......@@ -111,7 +111,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
public function testLimitWithOneToManyLeftJoinAndOrderBy()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('User.name')->from('User')->where("User.Phonenumber.phonenumber LIKE '%123%'")->orderby('User.Email.address')->limit(5);
......@@ -128,7 +128,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
public function testLimitWithOneToManyInnerJoin()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('u.id, p.*')->from('User u INNER JOIN u.Phonenumber p');
$q->limit(5);
......@@ -156,7 +156,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
public function testLimitWithPreparedQueries()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('u.id, p.id')->from('User u LEFT JOIN u.Phonenumber p');
$q->where('u.name = ?');
$q->limit(5);
......@@ -170,7 +170,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($q->getQuery(),
'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 (SELECT DISTINCT e2.id FROM entity e2 WHERE e2.name = ? AND (e2.type = 0) LIMIT 5) AND e.name = ? AND (e.type = 0)');
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('u.id, p.id')->from('User u LEFT JOIN u.Phonenumber p');
$q->where("u.name LIKE ? || u.name LIKE ?");
$q->limit(5);
......@@ -188,7 +188,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
}
public function testConnectionFlushing()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from('User.Phonenumber');
$q->where('User.name = ?');
$q->limit(5);
......@@ -200,7 +200,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
}
public function testLimitWithManyToManyColumnAggInheritanceLeftJoin()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from('User.Group')->limit(5);
$users = $q->execute();
......@@ -227,7 +227,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from("User")->where("User.Group.id = ?")->orderby("User.id ASC")->limit(5);
......@@ -236,7 +236,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($users->count(), 3);
$this->connection->clear();
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from('User')->where('User.Group.id = ?')->orderby('User.id DESC');
$users = $q->execute(array($user->Group[1]->id));
......@@ -248,7 +248,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
$this->manager->setAttribute(Doctrine::ATTR_QUERY_LIMIT, Doctrine::LIMIT_ROWS);
$this->connection->clear();
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from("User")->where("User.Group.id = ?")->orderby("User.id DESC")->limit(5);
$users = $q->execute(array(3));
......@@ -260,7 +260,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
public function testLimitWithManyToManyAndColumnAggregationInheritance()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from('User u, u.Group g')->where('g.id > 1')->orderby('u.name DESC')->limit(10);
}
......@@ -279,7 +279,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
$coll[3]->name = "photo 4";
$this->connection->flush();
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from("Photo")->where("Photo.Tag.id = ?")->orderby("Photo.id DESC")->limit(100);
$photos = $q->execute(array(1));
......
......@@ -34,7 +34,7 @@ class Doctrine_Query_Orderby_TestCase extends Doctrine_UnitTestCase
{
public function testOrderByAggregateValueIsSupported()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('u.name, COUNT(p.phonenumber) count')
->from('User u')
......@@ -45,7 +45,7 @@ class Doctrine_Query_Orderby_TestCase extends Doctrine_UnitTestCase
}
public function testOrderByRandomIsSupported()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('u.name, RANDOM() rand')
->from('User u')
......
......@@ -34,7 +34,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
{
public function testAggregateFunctionWithDistinctKeyword()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('SELECT COUNT(DISTINCT u.name) FROM User u');
......@@ -43,7 +43,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
public function testAggregateFunction()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('SELECT COUNT(u.id) FROM User u');
......@@ -52,7 +52,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
public function testSelectPartSupportsMultipleAggregateFunctions()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('SELECT MAX(u.id), MIN(u.name) FROM User u');
......@@ -60,7 +60,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
}
public function testMultipleAggregateFunctionsWithMultipleComponents()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('SELECT MAX(u.id), MIN(u.name), COUNT(p.id) FROM User u, u.Phonenumber p');
......@@ -68,7 +68,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
}
public function testEmptySelectPart()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
try {
$q->select(null);
......@@ -80,7 +80,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
}
public function testUnknownAggregateFunction()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
try {
$q->parseQuery('SELECT UNKNOWN(u.id) FROM User');
......@@ -91,7 +91,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
}
public function testAggregateFunctionValueHydration()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('SELECT u.id, COUNT(p.id) FROM User u, u.Phonenumber p GROUP BY u.id');
......@@ -107,7 +107,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
public function testSingleComponentWithAsterisk()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('SELECT u.* FROM User u');
......@@ -115,7 +115,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
}
public function testSingleComponentWithMultipleColumns()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('SELECT u.name, u.type FROM User u');
......@@ -123,7 +123,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
}
public function testMultipleComponentsWithAsterisk()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('SELECT u.*, p.* FROM User u, u.Phonenumber p');
......@@ -131,7 +131,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
}
public function testMultipleComponentsWithMultipleColumns()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('SELECT u.id, u.name, p.id FROM User u, u.Phonenumber p');
......@@ -140,7 +140,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
public function testAggregateFunctionValueHydrationWithAliases()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('SELECT u.id, COUNT(p.id) count FROM User u, u.Phonenumber p GROUP BY u.id');
......@@ -154,7 +154,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
}
public function testMultipleAggregateFunctionValueHydrationWithAliases()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('SELECT u.id, COUNT(p.id) count, MAX(p.phonenumber) max FROM User u, u.Phonenumber p GROUP BY u.id');
......@@ -175,7 +175,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
{
$this->connection->clear();
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery('SELECT u.id, COUNT(p.id) count, MAX(p.phonenumber) max FROM User u, u.Phonenumber p GROUP BY u.id');
......
......@@ -36,7 +36,7 @@ class Doctrine_Query_Subquery_TestCase extends Doctrine_UnitTestCase
public function testSubqueryWithWherePartAndInExpression()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from('User')->where("User.id NOT IN (SELECT User.id FROM User WHERE User.name = 'zYne')");
$this->assertEqual($q->getQuery(),
......@@ -49,7 +49,7 @@ class Doctrine_Query_Subquery_TestCase extends Doctrine_UnitTestCase
}
public function testSubqueryAllowsSelectingOfAnyField()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from('User u')->where('u.id NOT IN (SELECT g.user_id FROM Groupuser g)');
$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 NOT IN (SELECT g.user_id AS g__user_id FROM groupuser g) AND (e.type = 0)");
......@@ -58,7 +58,7 @@ class Doctrine_Query_Subquery_TestCase extends Doctrine_UnitTestCase
public function testSubqueryInSelectPart()
{
// ticket #307
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery("SELECT u.name, (SELECT COUNT(p.id) FROM Phonenumber p WHERE p.entity_id = u.id) pcount FROM User u WHERE u.name = 'zYne' LIMIT 1");
......@@ -77,7 +77,7 @@ class Doctrine_Query_Subquery_TestCase extends Doctrine_UnitTestCase
public function testSubqueryInSelectPart2()
{
// ticket #307
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery("SELECT u.name, (SELECT COUNT(w.id) FROM User w WHERE w.id = u.id) pcount FROM User u WHERE u.name = 'zYne' LIMIT 1");
......
......@@ -35,13 +35,13 @@ class Doctrine_Query_Update_TestCase extends Doctrine_UnitTestCase
{
public function testUpdateAllWithColumnAggregationInheritance()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery("UPDATE User u SET u.name = 'someone'");
$this->assertEqual($q->getQuery(), "UPDATE entity SET name = 'someone' WHERE (type = 0)");
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->update('User u')->set('u.name', "'someone'");
......@@ -49,13 +49,13 @@ class Doctrine_Query_Update_TestCase extends Doctrine_UnitTestCase
}
public function testUpdateWorksWithMultipleColumns()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery("UPDATE User u SET u.name = 'someone', u.email_id = 5");
$this->assertEqual($q->getQuery(), "UPDATE entity SET name = 'someone', email_id = 5 WHERE (type = 0)");
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->update('User u')->set('u.name', "'someone'")->set('u.email_id', 5);
......@@ -63,7 +63,7 @@ class Doctrine_Query_Update_TestCase extends Doctrine_UnitTestCase
}
public function testUpdateSupportsConditions()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->parseQuery("UPDATE User u SET u.name = 'someone' WHERE u.id = 5");
......
......@@ -47,7 +47,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
$user->name = 'someone';
$user->save();
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from('User')->addWhere('User.id = ?',1);
......@@ -63,7 +63,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
$user->name = 'someone.2';
$user->save();
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from('User')->addWhere('User.id IN (?, ?)', array(1, 2));
......@@ -75,7 +75,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
}
public function testDirectMultipleParameterSetting2()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from('User')->where('User.id IN (?, ?)', array(1, 2));
......@@ -98,7 +98,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
}
public function testNotInExpression()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from('User u')->addWhere('u.id NOT IN (?)', array(1));
$users = $q->execute();
......@@ -108,7 +108,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
}
public function testExistsExpression()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$user = new User();
$user->name = 'someone with a group';
......@@ -129,7 +129,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
public function testNotExistsExpression()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
// find all users which don't have groups
try {
......@@ -145,7 +145,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
}
public function testComponentAliases()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from('User u')->addWhere('u.id IN (?, ?)', array(1,2));
......@@ -158,7 +158,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
}
public function testComponentAliases2()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->from('User u')->addWhere('u.name = ?', array('someone'));
......@@ -169,7 +169,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
}
public function testOperatorWithNoTrailingSpaces()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('User.id')->from('User')->where("User.name='someone'");
......@@ -180,7 +180,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
}
public function testOperatorWithNoTrailingSpaces2()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('User.id')->from('User')->where("User.name='foo.bar'");
......@@ -191,7 +191,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
}
public function testOperatorWithSingleTrailingSpace()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('User.id')->from('User')->where("User.name= 'foo.bar'");
......@@ -202,7 +202,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
}
public function testOperatorWithSingleTrailingSpace2()
{
$q = new Doctrine_Query2();
$q = new Doctrine_Query();
$q->select('User.id')->from('User')->where("User.name ='foo.bar'");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment