DQL core refactored
This commit is contained in:
parent
b50aceec1d
commit
f26217c87a
@ -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, '(');
|
||||
@ -1132,7 +1132,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
|
||||
public function distinct($flag = true)
|
||||
{
|
||||
$this->_parts['distinct'] = (bool) $flag;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -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)) {
|
||||
@ -183,8 +183,8 @@ class Doctrine_RawSql extends Doctrine_Hydrate
|
||||
$q .= ( ! empty($this->parts['groupby']))? ' GROUP BY ' . implode(', ', $this->parts['groupby']) : '';
|
||||
$q .= ( ! empty($this->parts['having']))? ' HAVING ' . implode(' ', $this->parts['having']) : '';
|
||||
$q .= ( ! empty($this->parts['orderby']))? ' ORDER BY ' . implode(' ', $this->parts['orderby']) : '';
|
||||
$q .= ( ! empty($this->parts['limit']))? ' LIMIT ' . implode(' ', $this->parts['limit']) : '';
|
||||
$q .= ( ! empty($this->parts['offset']))? ' OFFSET ' . implode(' ', $this->parts['offset']) : '';
|
||||
$q .= ( ! empty($this->parts['limit']))? ' LIMIT ' . implode(' ', $this->parts['limit']) : '';
|
||||
$q .= ( ! empty($this->parts['offset']))? ' OFFSET ' . implode(' ', $this->parts['offset']) : '';
|
||||
|
||||
if ( ! empty($string)) {
|
||||
array_pop($this->parts['where']);
|
||||
@ -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
|
||||
*/
|
||||
@ -150,18 +148,18 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
||||
*
|
||||
* -- treeOptions the tree options
|
||||
*/
|
||||
protected $options = array('name' => null,
|
||||
'tableName' => null,
|
||||
'sequenceName' => null,
|
||||
'inheritanceMap' => array(),
|
||||
'enumMap' => array(),
|
||||
'engine' => null,
|
||||
'charset' => null,
|
||||
'collation' => null,
|
||||
'treeImpl' => null,
|
||||
'treeOptions' => null,
|
||||
'indexes' => array(),
|
||||
);
|
||||
protected $options = array('name' => null,
|
||||
'tableName' => null,
|
||||
'sequenceName' => null,
|
||||
'inheritanceMap' => array(),
|
||||
'enumMap' => array(),
|
||||
'engine' => null,
|
||||
'charset' => null,
|
||||
'collation' => null,
|
||||
'treeImpl' => null,
|
||||
'treeOptions' => null,
|
||||
'indexes' => array(),
|
||||
);
|
||||
/**
|
||||
* @var Doctrine_Tree $tree tree object associated with 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
|
||||
|
@ -18,7 +18,7 @@
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.com>.
|
||||
*/
|
||||
Doctrine::autoload("Doctrine_Access");
|
||||
Doctrine::autoload('Doctrine_Access');
|
||||
/**
|
||||
* Doctrine_Collection
|
||||
* Collection of Doctrine_Record objects.
|
||||
@ -34,33 +34,29 @@ Doctrine::autoload("Doctrine_Access");
|
||||
class Doctrine_Collection extends Doctrine_Access implements Countable, IteratorAggregate, Serializable
|
||||
{
|
||||
/**
|
||||
* @var array $data an array containing the data access objects of this collection
|
||||
* @var array $data an array containing the records of this collection
|
||||
*/
|
||||
protected $data = array();
|
||||
/**
|
||||
* @var Doctrine_Table $table each collection has only records of specified table
|
||||
*/
|
||||
protected $table;
|
||||
protected $_table;
|
||||
/**
|
||||
* @var array $_snapshot a snapshot of the fetched data
|
||||
*/
|
||||
protected $_snapshot = array();
|
||||
/**
|
||||
* @var Doctrine_Record $reference collection can belong to a record
|
||||
*/
|
||||
protected $reference;
|
||||
/**
|
||||
* @var string $reference_field the reference field of the collection
|
||||
* @var string $referenceField the reference field of the collection
|
||||
*/
|
||||
protected $reference_field;
|
||||
protected $referenceField;
|
||||
/**
|
||||
* @var Doctrine_Relation the record this collection is related to, if any
|
||||
*/
|
||||
protected $relation;
|
||||
/**
|
||||
* @var boolean $expandable whether or not this collection has been expanded
|
||||
*/
|
||||
protected $expandable = true;
|
||||
/**
|
||||
* @var array $expanded
|
||||
*/
|
||||
protected $expanded = array();
|
||||
/**
|
||||
* @var string $keyColumn the name of the column that is used for collection key mapping
|
||||
*/
|
||||
@ -70,7 +66,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
*/
|
||||
protected static $null;
|
||||
|
||||
protected $aggregateValues = array();
|
||||
|
||||
/**
|
||||
* constructor
|
||||
@ -83,7 +78,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
$table = Doctrine_Manager::getInstance()
|
||||
->getTable($table);
|
||||
}
|
||||
$this->table = $table;
|
||||
$this->_table = $table;
|
||||
|
||||
$name = $table->getAttribute(Doctrine::ATTR_COLL_KEY);
|
||||
if ($name !== null) {
|
||||
@ -108,28 +103,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
*/
|
||||
public function getTable()
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
/**
|
||||
* setAggregateValue
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function setAggregateValue($name, $value)
|
||||
{
|
||||
$this->aggregateValues[$name] = $value;
|
||||
}
|
||||
/**
|
||||
* getAggregateValue
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAggregateValue($name)
|
||||
{
|
||||
return $this->aggregateValues[$name];
|
||||
return $this->_table;
|
||||
}
|
||||
/**
|
||||
* this method is automatically called when this Doctrine_Collection is serialized
|
||||
@ -168,45 +142,28 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
$this->$name = $values;
|
||||
}
|
||||
|
||||
$this->table = $connection->getTable($this->table);
|
||||
$this->_table = $connection->getTable($this->_table);
|
||||
|
||||
$this->expanded = array();
|
||||
$this->expandable = true;
|
||||
|
||||
$name = $this->table->getAttribute(Doctrine::ATTR_COLL_KEY);
|
||||
$name = $this->_table->getAttribute(Doctrine::ATTR_COLL_KEY);
|
||||
if ($name !== null) {
|
||||
$this->keyColumn = $name;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* isExpanded
|
||||
*
|
||||
* whether or not an offset batch has been expanded
|
||||
* @return boolean
|
||||
*/
|
||||
public function isExpanded($offset)
|
||||
{
|
||||
return isset($this->expanded[$offset]);
|
||||
}
|
||||
/**
|
||||
* isExpandable
|
||||
*
|
||||
* whether or not this collection is expandable
|
||||
* @return boolean
|
||||
*/
|
||||
public function isExpandable()
|
||||
{
|
||||
return $this->expandable;
|
||||
}
|
||||
/**
|
||||
* setKeyColumn
|
||||
* sets the key column for this collection
|
||||
*
|
||||
* @param string $column
|
||||
* @return void
|
||||
* @return Doctrine_Collection
|
||||
*/
|
||||
public function setKeyColumn($column)
|
||||
{
|
||||
$this->keyColumn = $column;
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* getKeyColumn
|
||||
@ -219,6 +176,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
return $this->column;
|
||||
}
|
||||
/**
|
||||
* getData
|
||||
* returns all the records as an array
|
||||
*
|
||||
* @return array
|
||||
@ -227,13 +185,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
/**
|
||||
* @param array $data
|
||||
*/
|
||||
public function addData(array $data)
|
||||
{
|
||||
$this->data[] = $data;
|
||||
}
|
||||
/**
|
||||
* getFirst
|
||||
* returns the first record in the collection
|
||||
@ -269,15 +220,15 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
|| $relation instanceof Doctrine_Relation_LocalKey
|
||||
) {
|
||||
|
||||
$this->reference_field = $relation->getForeign();
|
||||
$this->referenceField = $relation->getForeign();
|
||||
|
||||
$value = $record->get($relation->getLocal());
|
||||
|
||||
foreach ($this->getNormalIterator() as $record) {
|
||||
if ($value !== null) {
|
||||
$record->set($this->reference_field, $value, false);
|
||||
$record->set($this->referenceField, $value, false);
|
||||
} else {
|
||||
$record->set($this->reference_field, $this->reference, false);
|
||||
$record->set($this->referenceField, $this->reference, false);
|
||||
}
|
||||
}
|
||||
} elseif ($relation instanceof Doctrine_Relation_Association) {
|
||||
@ -293,127 +244,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
{
|
||||
return $this->reference;
|
||||
}
|
||||
/**
|
||||
* expand
|
||||
* expands the collection
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function expand($key)
|
||||
{
|
||||
$where = array();
|
||||
$params = array();
|
||||
$limit = null;
|
||||
$offset = null;
|
||||
|
||||
switch (get_class($this)) {
|
||||
case "Doctrine_Collection_Offset":
|
||||
$limit = $this->getLimit();
|
||||
$offset = (floor($key / $limit) * $limit);
|
||||
|
||||
if ( ! $this->expandable && isset($this->expanded[$offset])) {
|
||||
return false;
|
||||
}
|
||||
$fields = implode(", ",$this->table->getColumnNames());
|
||||
break;
|
||||
default:
|
||||
if ( ! $this->expandable) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! isset($this->reference)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$id = $this->reference->obtainIdentifier();
|
||||
|
||||
if (empty($id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (get_class($this)) {
|
||||
case "Doctrine_Collection_Immediate":
|
||||
$fields = implode(", ",$this->table->getColumnNames());
|
||||
break;
|
||||
default:
|
||||
$fields = implode(", ",$this->table->getPrimaryKeys());
|
||||
};
|
||||
};
|
||||
|
||||
if (isset($this->relation)) {
|
||||
if ($this->relation instanceof Doctrine_Relation_ForeignKey) {
|
||||
$params[] = $this->reference->getIncremented();
|
||||
$where[] = $this->reference_field." = ?";
|
||||
|
||||
if ( ! isset($offset)) {
|
||||
$ids = $this->getPrimaryKeys();
|
||||
|
||||
if ( ! empty($ids)) {
|
||||
$where[] = $this->table->getIdentifier()." NOT IN (".substr(str_repeat("?, ",count($ids)),0,-2).")";
|
||||
$params = array_merge($params,$ids);
|
||||
}
|
||||
|
||||
$this->expandable = false;
|
||||
}
|
||||
|
||||
} elseif ($this->relation instanceof Doctrine_Relation_Association) {
|
||||
|
||||
$asf = $this->relation->getAssociationFactory();
|
||||
$query = 'SELECT '.$foreign." FROM ".$asf->getTableName()." WHERE ".$local."=".$this->getIncremented();
|
||||
|
||||
$table = $fk->getTable();
|
||||
$graph = new Doctrine_Query($table->getConnection());
|
||||
|
||||
$q = 'FROM ' . $table->getComponentName() . ' WHERE ' . $table->getComponentName() . '.' . $table->getIdentifier()." IN ($query)";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$query = "SELECT ".$fields." FROM ".$this->table->getTableName();
|
||||
|
||||
// apply column aggregation inheritance
|
||||
$map = $this->table->inheritanceMap;
|
||||
foreach ($map as $k => $v) {
|
||||
$where[] = $k." = ?";
|
||||
$params[] = $v;
|
||||
}
|
||||
if ( ! empty($where)) {
|
||||
$query .= " WHERE ".implode(" AND ",$where);
|
||||
}
|
||||
|
||||
$coll = $this->table->execute($query, $params, $limit, $offset);
|
||||
|
||||
if ( ! isset($offset)) {
|
||||
foreach ($coll as $record) {
|
||||
if (isset($this->reference_field)) {
|
||||
$record->set($this->reference_field,$this->reference, false);
|
||||
}
|
||||
$this->reference->addReference($record, $this->relation);
|
||||
}
|
||||
} else {
|
||||
$i = $offset;
|
||||
|
||||
foreach ($coll as $record) {
|
||||
if (isset($this->reference)) {
|
||||
$this->reference->addReference($record, $this->relation, $i);
|
||||
} else {
|
||||
$this->data[$i] = $record;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
$this->expanded[$offset] = true;
|
||||
|
||||
// check if the fetched collection's record count is smaller
|
||||
// than the query limit, if so this collection has been expanded to its max size
|
||||
|
||||
if (count($coll) < $limit) {
|
||||
$this->expandable = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $coll;
|
||||
}
|
||||
/**
|
||||
* remove
|
||||
* removes a specified collection element
|
||||
@ -464,11 +294,11 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
if ($key === null) {
|
||||
$record = $this->table->create();
|
||||
if ($key === null || ! isset($this->data[$key])) {
|
||||
$record = $this->_table->create();
|
||||
|
||||
if (isset($this->reference_field)) {
|
||||
$record->set($this->reference_field, $this->reference, false);
|
||||
if (isset($this->referenceField)) {
|
||||
$record->set($this->referenceField, $this->reference, false);
|
||||
}
|
||||
|
||||
$this->data[] = $record;
|
||||
@ -476,25 +306,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
return $record;
|
||||
}
|
||||
|
||||
|
||||
if ( ! isset($this->data[$key])) {
|
||||
$this->expand($key);
|
||||
|
||||
if ( ! isset($this->data[$key])) {
|
||||
$this->data[$key] = $this->table->create();
|
||||
}
|
||||
if (isset($this->reference_field)) {
|
||||
$value = $this->reference->get($this->relation->getLocal());
|
||||
|
||||
if ($value !== null) {
|
||||
$this->data[$key]->set($this->reference_field, $value, false);
|
||||
} else {
|
||||
|
||||
$this->data[$key]->set($this->reference_field, $this->reference, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->data[$key];
|
||||
}
|
||||
|
||||
@ -504,7 +315,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
public function getPrimaryKeys()
|
||||
{
|
||||
$list = array();
|
||||
$name = $this->table->getIdentifier();
|
||||
$name = $this->_table->getIdentifier();
|
||||
|
||||
foreach ($this->data as $record) {
|
||||
if (is_array($record) && isset($record[$name])) {
|
||||
@ -512,7 +323,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
} else {
|
||||
$list[] = $record->getIncremented();
|
||||
}
|
||||
};
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
/**
|
||||
@ -542,8 +353,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
*/
|
||||
public function set($key, Doctrine_Record $record)
|
||||
{
|
||||
if (isset($this->reference_field)) {
|
||||
$record->set($this->reference_field, $this->reference, false);
|
||||
if (isset($this->referenceField)) {
|
||||
$record->set($this->referenceField, $this->reference, false);
|
||||
}
|
||||
$this->data[$key] = $record;
|
||||
}
|
||||
@ -553,10 +364,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
* @param string $key optional key for the record
|
||||
* @return boolean
|
||||
*/
|
||||
public function add(Doctrine_Record $record,$key = null)
|
||||
public function add(Doctrine_Record $record, $key = null)
|
||||
{
|
||||
if (isset($this->reference_field)) {
|
||||
$record->set($this->reference_field, $this->reference, false);
|
||||
if (isset($this->referenceField)) {
|
||||
$record->set($this->referenceField, $this->reference, false);
|
||||
}
|
||||
/**
|
||||
* for some weird reason in_array cannot be used here (php bug ?)
|
||||
@ -597,7 +408,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
public function loadRelated($name = null)
|
||||
{
|
||||
$list = array();
|
||||
$query = new Doctrine_Query($this->table->getConnection());
|
||||
$query = new Doctrine_Query($this->_table->getConnection());
|
||||
|
||||
if ( ! isset($name)) {
|
||||
foreach ($this->data as $record) {
|
||||
@ -606,13 +417,13 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
$list[] = $value;
|
||||
}
|
||||
};
|
||||
$query->from($this->table->getComponentName() . '(' . implode(", ",$this->table->getPrimaryKeys()) . ')');
|
||||
$query->where($this->table->getComponentName() . '.id IN (' . substr(str_repeat("?, ", count($list)),0,-2) . ')');
|
||||
$query->from($this->_table->getComponentName() . '(' . implode(", ",$this->_table->getPrimaryKeys()) . ')');
|
||||
$query->where($this->_table->getComponentName() . '.id IN (' . substr(str_repeat("?, ", count($list)),0,-2) . ')');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
$rel = $this->table->getRelation($name);
|
||||
$rel = $this->_table->getRelation($name);
|
||||
|
||||
if ($rel instanceof Doctrine_Relation_LocalKey || $rel instanceof Doctrine_Relation_ForeignKey) {
|
||||
foreach ($this->data as $record) {
|
||||
@ -642,7 +453,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
*/
|
||||
public function populateRelated($name, Doctrine_Collection $coll)
|
||||
{
|
||||
$rel = $this->table->getRelation($name);
|
||||
$rel = $this->_table->getRelation($name);
|
||||
$table = $rel->getTable();
|
||||
$foreign = $rel->getForeign();
|
||||
$local = $rel->getLocal();
|
||||
@ -657,9 +468,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
}
|
||||
} elseif ($rel instanceof Doctrine_Relation_ForeignKey) {
|
||||
foreach ($this->data as $key => $record) {
|
||||
if ($record->state() == Doctrine_Record::STATE_TCLEAN
|
||||
|| $record->state() == Doctrine_Record::STATE_TDIRTY
|
||||
) {
|
||||
if ( ! $record->exists()) {
|
||||
continue;
|
||||
}
|
||||
$sub = new Doctrine_Collection($table);
|
||||
@ -674,14 +483,12 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
$this->data[$key]->setRelated($name, $sub);
|
||||
}
|
||||
} elseif ($rel instanceof Doctrine_Relation_Association) {
|
||||
$identifier = $this->table->getIdentifier();
|
||||
$identifier = $this->_table->getIdentifier();
|
||||
$asf = $rel->getAssociationFactory();
|
||||
$name = $table->getComponentName();
|
||||
|
||||
foreach ($this->data as $key => $record) {
|
||||
if ($record->state() == Doctrine_Record::STATE_TCLEAN
|
||||
|| $record->state() == Doctrine_Record::STATE_TDIRTY
|
||||
) {
|
||||
if ( ! $record->exists()) {
|
||||
continue;
|
||||
}
|
||||
$sub = new Doctrine_Collection($table);
|
||||
@ -705,36 +512,93 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
{
|
||||
return new Doctrine_Collection_Iterator_Normal($this);
|
||||
}
|
||||
/**
|
||||
* takeSnapshot
|
||||
* takes a snapshot from this collection
|
||||
*
|
||||
* snapshots are used for diff processing, for example
|
||||
* when a fetched collection has three elements, then two of those
|
||||
* are being removed the diff would contain one element
|
||||
*
|
||||
* Doctrine_Collection::save() attaches the diff with the help of last
|
||||
* snapshot.
|
||||
*
|
||||
* @return Doctrine_Collection
|
||||
*/
|
||||
public function takeSnapshot()
|
||||
{
|
||||
$this->_snapshot = $this->data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* getSnapshot
|
||||
* returns the data of the last snapshot
|
||||
*
|
||||
* @return array returns the data in last snapshot
|
||||
*/
|
||||
public function getSnapshot()
|
||||
{
|
||||
return $this->_snapshot;
|
||||
}
|
||||
/**
|
||||
* processDiff
|
||||
* processes the difference of the last snapshot and the current data
|
||||
*
|
||||
* an example:
|
||||
* Snapshot with the objects 1, 2 and 4
|
||||
* Current data with objects 2, 3 and 5
|
||||
*
|
||||
* The process would:
|
||||
* 1. remove object 4
|
||||
* 2. add objects 3 and 5
|
||||
*
|
||||
* @return Doctrine_Collection
|
||||
*/
|
||||
public function processDiff()
|
||||
{
|
||||
foreach (array_diff($this->snapshot, $this->data) as $record) {
|
||||
$record->delete();
|
||||
}
|
||||
foreach (array_diff($this->data, $this->snapshot) as $record) {
|
||||
$record->save();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* save
|
||||
* saves all records of this collection
|
||||
*
|
||||
* @return void
|
||||
* @return Doctrine_Collection
|
||||
*/
|
||||
public function save(Doctrine_Connection $conn = null)
|
||||
{
|
||||
if ($conn == null) {
|
||||
$conn = $this->table->getConnection();
|
||||
$conn = $this->_table->getConnection();
|
||||
}
|
||||
$conn->beginTransaction();
|
||||
|
||||
foreach ($this as $key => $record) {
|
||||
$record->save($conn);
|
||||
};
|
||||
}
|
||||
|
||||
$conn->commit();
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* delete
|
||||
* single shot delete
|
||||
* deletes all records from this collection
|
||||
* and uses only one database query to perform this operation
|
||||
*
|
||||
* @return boolean
|
||||
* @return Doctrine_Collection
|
||||
*/
|
||||
public function delete(Doctrine_Connection $conn = null)
|
||||
{
|
||||
if ($conn == null) {
|
||||
$conn = $this->table->getConnection();
|
||||
$conn = $this->_table->getConnection();
|
||||
}
|
||||
|
||||
$conn->beginTransaction();
|
||||
@ -746,6 +610,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
$conn->commit();
|
||||
|
||||
$this->data = array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* getIterator
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.com>.
|
||||
*/
|
||||
Doctrine::autoload('Doctrine_Access');
|
||||
|
||||
/**
|
||||
* Doctrine_Hydrate is a base class for Doctrine_RawSql and Doctrine_Query.
|
||||
* Its purpose is to populate object graphs.
|
||||
@ -32,7 +32,7 @@ Doctrine::autoload('Doctrine_Access');
|
||||
* @version $Revision$
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
*/
|
||||
abstract class Doctrine_Hydrate extends Doctrine_Access
|
||||
class Doctrine_Hydrate
|
||||
{
|
||||
/**
|
||||
* QUERY TYPE CONSTANTS
|
||||
@ -58,23 +58,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
|
||||
* constant for CREATE queries
|
||||
*/
|
||||
const CREATE = 4;
|
||||
/**
|
||||
* @var array $fetchmodes an array containing all fetchmodes
|
||||
*/
|
||||
protected $fetchModes = array();
|
||||
/**
|
||||
* @var array $tables an array containing all the tables used in the query
|
||||
*/
|
||||
protected $tables = array();
|
||||
/**
|
||||
* @var array $collections an array containing all collections
|
||||
* this hydrater has created/will create
|
||||
*/
|
||||
protected $collections = array();
|
||||
/**
|
||||
* @var array $joins an array containing all table joins
|
||||
*/
|
||||
protected $joins = array();
|
||||
|
||||
/**
|
||||
* @var array $params query input parameters
|
||||
*/
|
||||
@ -88,28 +72,28 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
|
||||
*/
|
||||
protected $view;
|
||||
/**
|
||||
* @var boolean $inheritanceApplied
|
||||
* @var array $_aliasMap two dimensional array containing the map for query aliases
|
||||
* Main keys are component aliases
|
||||
*
|
||||
* table table object associated with given alias
|
||||
*
|
||||
* relation the relation object owned by the parent
|
||||
*
|
||||
* parent the alias of the parent
|
||||
*/
|
||||
protected $inheritanceApplied = false;
|
||||
/**
|
||||
* @var boolean $aggregate
|
||||
*/
|
||||
protected $aggregate = false;
|
||||
/**
|
||||
* @var array $compAliases
|
||||
*/
|
||||
protected $compAliases = array();
|
||||
protected $_aliasMap = array();
|
||||
|
||||
/**
|
||||
* @var array $tableAliases
|
||||
*/
|
||||
protected $tableAliases = array();
|
||||
/**
|
||||
* @var array $tableIndexes
|
||||
*
|
||||
*/
|
||||
protected $tableIndexes = array();
|
||||
|
||||
protected $pendingAggregates = array();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected $subqueryAggregates = array();
|
||||
/**
|
||||
* @var array $aggregateMap an array containing all aggregate aliases, keys as dql aliases
|
||||
@ -154,15 +138,6 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
|
||||
$this->conn = $connection;
|
||||
$this->aliasHandler = new Doctrine_Hydrate_Alias();
|
||||
}
|
||||
/**
|
||||
* getComponentAliases
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getComponentAliases()
|
||||
{
|
||||
return $this->compAliases;
|
||||
}
|
||||
/**
|
||||
* getTableAliases
|
||||
*
|
||||
@ -172,47 +147,52 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
|
||||
{
|
||||
return $this->tableAliases;
|
||||
}
|
||||
/**
|
||||
* getTableIndexes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTableIndexes()
|
||||
public function setTableAliases(array $aliases)
|
||||
{
|
||||
return $this->tableIndexes;
|
||||
$this->tableAliases = $aliases;
|
||||
}
|
||||
/**
|
||||
* getTables
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTables()
|
||||
public function getTableAlias($componentAlias)
|
||||
{
|
||||
return $this->tables;
|
||||
return $this->aliasHandler->getShortAlias($componentAlias);
|
||||
}
|
||||
public function addQueryPart($name, $part)
|
||||
{
|
||||
if ( ! isset($this->parts[$name])) {
|
||||
throw new Doctrine_Hydrate_Exception('Unknown query part ' . $name);
|
||||
}
|
||||
$this->parts[$name][] = $part;
|
||||
}
|
||||
public function getDeclaration($name)
|
||||
{
|
||||
if ( ! isset($this->_aliasMap[$name])) {
|
||||
throw new Doctrine_Hydrate_Exception('Unknown component alias ' . $name);
|
||||
}
|
||||
|
||||
return $this->_aliasMap[$name];
|
||||
}
|
||||
public function setQueryPart($name, $part)
|
||||
{
|
||||
if ( ! isset($this->parts[$name])) {
|
||||
throw new Doctrine_Hydrate_Exception('Unknown query part ' . $name);
|
||||
}
|
||||
|
||||
if ($name !== 'limit' && $name !== 'offset') {
|
||||
$this->parts[$name] = array($part);
|
||||
} else {
|
||||
$this->parts[$name] = $part;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* copyAliases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function copyAliases(Doctrine_Hydrate $query)
|
||||
public function copyAliases($query)
|
||||
{
|
||||
$this->compAliases = $query->getComponentAliases();
|
||||
$this->tableAliases = $query->getTableAliases();
|
||||
$this->tableIndexes = $query->getTableIndexes();
|
||||
$this->aliasHandler = $query->aliasHandler;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPathAlias($path)
|
||||
{
|
||||
$s = array_search($path, $this->compAliases);
|
||||
if ($s === false)
|
||||
return $path;
|
||||
|
||||
return $s;
|
||||
}
|
||||
/**
|
||||
* createSubquery
|
||||
*
|
||||
@ -231,12 +211,6 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
|
||||
|
||||
return $obj;
|
||||
}
|
||||
/**
|
||||
* getQuery
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getQuery();
|
||||
/**
|
||||
* limitSubqueryUsed
|
||||
*
|
||||
@ -246,7 +220,14 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getQueryPart($part)
|
||||
{
|
||||
if ( ! isset($this->parts[$part])) {
|
||||
throw new Doctrine_Hydrate_Exception('Unknown query part ' . $part);
|
||||
}
|
||||
|
||||
return $this->parts[$part];
|
||||
}
|
||||
/**
|
||||
* remove
|
||||
*
|
||||
@ -271,25 +252,20 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
|
||||
*/
|
||||
protected function clear()
|
||||
{
|
||||
$this->fetchModes = array();
|
||||
$this->tables = array();
|
||||
$this->parts = array(
|
||||
"select" => array(),
|
||||
"from" => array(),
|
||||
"join" => array(),
|
||||
"where" => array(),
|
||||
"groupby" => array(),
|
||||
"having" => array(),
|
||||
"orderby" => array(),
|
||||
"limit" => false,
|
||||
"offset" => false,
|
||||
);
|
||||
'select' => array(),
|
||||
'from' => array(),
|
||||
'set' => array(),
|
||||
'join' => array(),
|
||||
'where' => array(),
|
||||
'groupby' => array(),
|
||||
'having' => array(),
|
||||
'orderby' => array(),
|
||||
'limit' => false,
|
||||
'offset' => false,
|
||||
);
|
||||
$this->inheritanceApplied = false;
|
||||
$this->aggregate = false;
|
||||
|
||||
$this->collections = array();
|
||||
$this->joins = array();
|
||||
$this->tableIndexes = array();
|
||||
$this->tableAliases = array();
|
||||
$this->aliasHandler->clear();
|
||||
}
|
||||
@ -333,56 +309,6 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
/**
|
||||
* getTableAlias
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
final public function getTableAlias($path)
|
||||
{
|
||||
if (isset($this->compAliases[$path])) {
|
||||
$path = $this->compAliases[$path];
|
||||
}
|
||||
if ( ! isset($this->tableAliases[$path])) {
|
||||
return false;
|
||||
}
|
||||
return $this->tableAliases[$path];
|
||||
}
|
||||
/**
|
||||
* getCollection
|
||||
*
|
||||
* @parma string $name component name
|
||||
* @param integer $index
|
||||
*/
|
||||
private function getCollection($name)
|
||||
{
|
||||
$table = $this->tables[$name];
|
||||
if ( ! isset($this->fetchModes[$name])) {
|
||||
return new Doctrine_Collection($table);
|
||||
}
|
||||
switch ($this->fetchModes[$name]) {
|
||||
case Doctrine::FETCH_BATCH:
|
||||
$coll = new Doctrine_Collection_Batch($table);
|
||||
break;
|
||||
case Doctrine::FETCH_LAZY:
|
||||
$coll = new Doctrine_Collection_Lazy($table);
|
||||
break;
|
||||
case Doctrine::FETCH_OFFSET:
|
||||
$coll = new Doctrine_Collection_Offset($table);
|
||||
break;
|
||||
case Doctrine::FETCH_IMMEDIATE:
|
||||
$coll = new Doctrine_Collection_Immediate($table);
|
||||
break;
|
||||
case Doctrine::FETCH_LAZY_OFFSET:
|
||||
$coll = new Doctrine_Collection_LazyOffset($table);
|
||||
break;
|
||||
default:
|
||||
throw new Doctrine_Exception("Unknown fetchmode");
|
||||
};
|
||||
|
||||
return $coll;
|
||||
}
|
||||
/**
|
||||
* setParams
|
||||
*
|
||||
@ -392,15 +318,14 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
|
||||
$this->params = $params;
|
||||
}
|
||||
/**
|
||||
* execute
|
||||
* executes the dql query and populates all collections
|
||||
* _fetch
|
||||
*
|
||||
* @param string $params
|
||||
* @return Doctrine_Collection the root collection
|
||||
* @param array $params prepared statement parameters
|
||||
* @param integer $fetchMode the fetchmode
|
||||
* @see Doctrine::FETCH_* constants
|
||||
*/
|
||||
public function execute($params = array(), $return = Doctrine::FETCH_RECORD) {
|
||||
$this->collections = array();
|
||||
|
||||
public function _fetch($params = array(), $fetchMode = Doctrine::FETCH_RECORD)
|
||||
{
|
||||
$params = $this->conn->convertBooleans(array_merge($this->params, $params));
|
||||
|
||||
if ( ! $this->view) {
|
||||
@ -409,246 +334,188 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
|
||||
$query = $this->view->getSelectSql();
|
||||
}
|
||||
|
||||
if ($this->isLimitSubqueryUsed() &&
|
||||
if ($this->isLimitSubqueryUsed() &&
|
||||
$this->conn->getDBH()->getAttribute(Doctrine::ATTR_DRIVER_NAME) !== 'mysql') {
|
||||
|
||||
$params = array_merge($params, $params);
|
||||
}
|
||||
$stmt = $this->conn->execute($query, $params);
|
||||
|
||||
if ($this->aggregate) {
|
||||
return $stmt->fetchAll(Doctrine::FETCH_ASSOC);
|
||||
return $this->parseData($stmt);
|
||||
}
|
||||
|
||||
public function setAliasMap($map)
|
||||
{
|
||||
$this->_aliasMap = $map;
|
||||
}
|
||||
public function getAliasMap()
|
||||
{
|
||||
return $this->_aliasMap;
|
||||
}
|
||||
/**
|
||||
* mapAggregateValues
|
||||
* map the aggregate values of given dataset row to a given record
|
||||
*
|
||||
* @param Doctrine_Record $record
|
||||
* @param array $row
|
||||
* @return Doctrine_Record
|
||||
*/
|
||||
public function mapAggregateValues($record, array $row, $alias)
|
||||
{
|
||||
$found = false;
|
||||
// aggregate values have numeric keys
|
||||
if (isset($row[0])) {
|
||||
// map each aggregate value
|
||||
foreach ($row as $index => $value) {
|
||||
$agg = false;
|
||||
|
||||
if (isset($this->pendingAggregates[$alias][$index])) {
|
||||
$agg = $this->pendingAggregates[$alias][$index][3];
|
||||
} elseif (isset($this->subqueryAggregates[$alias][$index])) {
|
||||
$agg = $this->subqueryAggregates[$alias][$index];
|
||||
}
|
||||
$record->mapValue($agg, $value);
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
return $found;
|
||||
}
|
||||
/**
|
||||
* execute
|
||||
* executes the dql query and populates all collections
|
||||
*
|
||||
* @param string $params
|
||||
* @return Doctrine_Collection the root collection
|
||||
*/
|
||||
public function execute($params = array(), $return = Doctrine::FETCH_RECORD)
|
||||
{
|
||||
$array = (array) $this->_fetch($params, $return = Doctrine::FETCH_RECORD);
|
||||
|
||||
if (count($this->tables) == 0) {
|
||||
throw new Doctrine_Query_Exception('No components selected');
|
||||
}
|
||||
|
||||
$keys = array_keys($this->tables);
|
||||
$root = $keys[0];
|
||||
|
||||
$previd = array();
|
||||
|
||||
$coll = $this->getCollection($root);
|
||||
$prev[$root] = $coll;
|
||||
|
||||
if ($this->aggregate) {
|
||||
$return = Doctrine::FETCH_ARRAY;
|
||||
}
|
||||
|
||||
$array = $this->parseData($stmt);
|
||||
|
||||
if ($return == Doctrine::FETCH_ARRAY) {
|
||||
return $array;
|
||||
if (empty($this->_aliasMap)) {
|
||||
throw new Doctrine_Hydrate_Exception("Couldn't execute query. Component alias map was empty.");
|
||||
}
|
||||
// initialize some variables used within the main loop
|
||||
reset($this->_aliasMap);
|
||||
$rootMap = current($this->_aliasMap);
|
||||
$rootAlias = key($this->_aliasMap);
|
||||
$coll = new Doctrine_Collection2($rootMap['table']);
|
||||
$prev[$rootAlias] = $coll;
|
||||
|
||||
$prevRow = array();
|
||||
/**
|
||||
* iterate over the fetched data
|
||||
* here $data is a two dimensional array
|
||||
*/
|
||||
foreach ($array as $data) {
|
||||
/**
|
||||
* remove duplicated data rows and map data into objects
|
||||
*/
|
||||
foreach ($data as $key => $row) {
|
||||
foreach ($data as $tableAlias => $row) {
|
||||
// skip empty rows (not mappable)
|
||||
if (empty($row)) {
|
||||
continue;
|
||||
}
|
||||
//$key = array_search($key, $this->shortAliases);
|
||||
$alias = $this->aliasHandler->getComponentAlias($tableAlias);
|
||||
$map = $this->_aliasMap[$alias];
|
||||
|
||||
foreach ($this->tables as $k => $t) {
|
||||
if ( ! strcasecmp($key, $k)) {
|
||||
$key = $k;
|
||||
}
|
||||
// initialize previous row array if not set
|
||||
if ( ! isset($prevRow[$tableAlias])) {
|
||||
$prevRow[$tableAlias] = array();
|
||||
}
|
||||
|
||||
if ( !isset($this->tables[$key]) ) {
|
||||
throw new Doctrine_Exception('No table named ' . $key . ' found.');
|
||||
}
|
||||
$ids = $this->tables[$key]->getIdentifier();
|
||||
$name = $key;
|
||||
// don't map duplicate rows
|
||||
if ($prevRow[$tableAlias] !== $row) {
|
||||
$identifiable = $this->isIdentifiable($row, $map['table']->getIdentifier());
|
||||
|
||||
if ($this->isIdentifiable($row, $ids)) {
|
||||
if ($name !== $root) {
|
||||
$prev = $this->initRelated($prev, $name);
|
||||
if ($identifiable) {
|
||||
// set internal data
|
||||
$map['table']->setData($row);
|
||||
}
|
||||
// aggregate values have numeric keys
|
||||
if (isset($row[0])) {
|
||||
$component = $this->tables[$name]->getComponentName();
|
||||
|
||||
// if the collection already has objects, get the last object
|
||||
// otherwise create a new one where the aggregate values are being mapped
|
||||
|
||||
if ($prev[$name]->count() > 0) {
|
||||
$record = $prev[$name]->getLast();
|
||||
} else {
|
||||
$record = new $component();
|
||||
$prev[$name]->add($record);
|
||||
}
|
||||
|
||||
$path = array_search($name, $this->tableAliases);
|
||||
$alias = $this->getPathAlias($path);
|
||||
|
||||
// map each aggregate value
|
||||
foreach ($row as $index => $value) {
|
||||
$agg = false;
|
||||
|
||||
if (isset($this->pendingAggregates[$alias][$index])) {
|
||||
$agg = $this->pendingAggregates[$alias][$index][3];
|
||||
} elseif (isset($this->subqueryAggregates[$alias][$index])) {
|
||||
$agg = $this->subqueryAggregates[$alias][$index];
|
||||
}
|
||||
|
||||
$record->mapValue($agg, $value);
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
if ( ! isset($previd[$name])) {
|
||||
$previd[$name] = array();
|
||||
}
|
||||
if ($previd[$name] !== $row) {
|
||||
// set internal data
|
||||
|
||||
$this->tables[$name]->setData($row);
|
||||
|
||||
// initialize a new record
|
||||
$record = $map['table']->getRecord();
|
||||
|
||||
$record = $this->tables[$name]->getRecord();
|
||||
|
||||
// aggregate values have numeric keys
|
||||
if (isset($row[0])) {
|
||||
$path = array_search($name, $this->tableAliases);
|
||||
$alias = $this->getPathAlias($path);
|
||||
|
||||
// map each aggregate value
|
||||
foreach ($row as $index => $value) {
|
||||
$agg = false;
|
||||
|
||||
if (isset($this->pendingAggregates[$alias][$index])) {
|
||||
$agg = $this->pendingAggregates[$alias][$index][3];
|
||||
} elseif (isset($this->subqueryAggregates[$alias][$index])) {
|
||||
$agg = $this->subqueryAggregates[$alias][$index];
|
||||
}
|
||||
$record->mapValue($agg, $value);
|
||||
}
|
||||
// map aggregate values (if any)
|
||||
if($this->mapAggregateValues($record, $row, $alias)) {
|
||||
$identifiable = true;
|
||||
}
|
||||
|
||||
if ($name == $root) {
|
||||
|
||||
if ($alias == $rootAlias) {
|
||||
// add record into root collection
|
||||
|
||||
$coll->add($record);
|
||||
unset($previd);
|
||||
|
||||
|
||||
if ($identifiable) {
|
||||
$coll->add($record);
|
||||
unset($prevRow);
|
||||
}
|
||||
} else {
|
||||
$prev = $this->addRelated($prev, $name, $record);
|
||||
}
|
||||
|
||||
$relation = $map['relation'];
|
||||
$parentAlias = $map['parent'];
|
||||
$parentMap = $this->_aliasMap[$parentAlias];
|
||||
$parent = $prev[$parentAlias]->getLast();
|
||||
|
||||
// check the type of the relation
|
||||
if ($relation->isOneToOne()) {
|
||||
if ( ! $identifiable) {
|
||||
continue;
|
||||
}
|
||||
$prev[$alias] = $record;
|
||||
} else {
|
||||
// one-to-many relation or many-to-many relation
|
||||
if ( ! $prev[$parentAlias]->getLast()->hasReference($relation->getAlias())) {
|
||||
// initialize a new collection
|
||||
$prev[$alias] = new Doctrine_Collection($map['table']);
|
||||
$prev[$alias]->setReference($parent, $relation);
|
||||
} else {
|
||||
// previous entry found from memory
|
||||
$prev[$alias] = $prev[$parentAlias]->getLast()->get($relation->getAlias());
|
||||
}
|
||||
// add record to the current collection
|
||||
if ($identifiable) {
|
||||
$prev[$alias]->add($record);
|
||||
}
|
||||
}
|
||||
// initialize the relation from parent to the current collection/record
|
||||
$parent->set($relation->getAlias(), $prev[$alias]);
|
||||
}
|
||||
|
||||
// following statement is needed to ensure that mappings
|
||||
// are being done properly when the result set doesn't
|
||||
// contain the rows in 'right order'
|
||||
|
||||
if ($prev[$name] !== $record) {
|
||||
$prev[$name] = $record;
|
||||
|
||||
if ($prev[$alias] !== $record) {
|
||||
$prev[$alias] = $record;
|
||||
}
|
||||
}
|
||||
|
||||
$previd[$name] = $row;
|
||||
$prevRow[$tableAlias] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
return $coll;
|
||||
}
|
||||
/**
|
||||
* initRelation
|
||||
*
|
||||
* @param array $prev
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public function initRelated(array $prev, $name)
|
||||
{
|
||||
$pointer = $this->joins[$name];
|
||||
$path = array_search($name, $this->tableAliases);
|
||||
$tmp = explode('.', $path);
|
||||
$alias = end($tmp);
|
||||
|
||||
if ( ! isset($prev[$pointer]) ) {
|
||||
return $prev;
|
||||
}
|
||||
$fk = $this->tables[$pointer]->getRelation($alias);
|
||||
|
||||
if ( ! $fk->isOneToOne()) {
|
||||
if ($prev[$pointer]->getLast() instanceof Doctrine_Record) {
|
||||
if ( ! $prev[$pointer]->getLast()->hasReference($alias)) {
|
||||
$prev[$name] = $this->getCollection($name);
|
||||
$prev[$pointer]->getLast()->initReference($prev[$name],$fk);
|
||||
} else {
|
||||
$prev[$name] = $prev[$pointer]->getLast()->get($alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $prev;
|
||||
}
|
||||
/**
|
||||
* addRelated
|
||||
*
|
||||
* @param array $prev
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public function addRelated(array $prev, $name, Doctrine_Record $record)
|
||||
{
|
||||
$pointer = $this->joins[$name];
|
||||
|
||||
$path = array_search($name, $this->tableAliases);
|
||||
$tmp = explode('.', $path);
|
||||
$alias = end($tmp);
|
||||
|
||||
$fk = $this->tables[$pointer]->getRelation($alias);
|
||||
|
||||
if ($fk->isOneToOne()) {
|
||||
$prev[$pointer]->getLast()->set($fk->getAlias(), $record);
|
||||
|
||||
$prev[$name] = $record;
|
||||
} else {
|
||||
// one-to-many relation or many-to-many relation
|
||||
|
||||
if ( ! $prev[$pointer]->getLast()->hasReference($alias)) {
|
||||
$prev[$name] = $this->getCollection($name);
|
||||
$prev[$pointer]->getLast()->initReference($prev[$name], $fk);
|
||||
|
||||
} else {
|
||||
// previous entry found from memory
|
||||
$prev[$name] = $prev[$pointer]->getLast()->get($alias);
|
||||
}
|
||||
|
||||
$prev[$pointer]->getLast()->addReference($record, $fk);
|
||||
}
|
||||
return $prev;
|
||||
}
|
||||
/**
|
||||
* isIdentifiable
|
||||
* returns whether or not a given data row is identifiable (it contains
|
||||
* all id fields specified in the second argument)
|
||||
* all primary key fields specified in the second argument)
|
||||
*
|
||||
* @param array $row
|
||||
* @param mixed $ids
|
||||
* @param mixed $primaryKeys
|
||||
* @return boolean
|
||||
*/
|
||||
public function isIdentifiable(array $row, $ids)
|
||||
public function isIdentifiable(array $row, $primaryKeys)
|
||||
{
|
||||
if (is_array($ids)) {
|
||||
foreach ($ids as $id) {
|
||||
if ($row[$id] == null)
|
||||
return true;
|
||||
if (is_array($primaryKeys)) {
|
||||
foreach ($primaryKeys as $id) {
|
||||
if ($row[$id] == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( ! isset($row[$ids])) {
|
||||
return true;
|
||||
if ( ! isset($row[$primaryKeys])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* getType
|
||||
@ -679,12 +546,13 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
|
||||
// get the inheritance maps
|
||||
$array = array();
|
||||
|
||||
foreach ($this->tables as $alias => $table) {
|
||||
$array[$alias][] = $table->inheritanceMap;
|
||||
foreach ($this->_aliasMap as $componentAlias => $data) {
|
||||
$tableAlias = $this->getTableAlias($componentAlias);
|
||||
$array[$tableAlias][] = $data['table']->inheritanceMap;
|
||||
}
|
||||
|
||||
// apply inheritance maps
|
||||
$str = "";
|
||||
$str = '';
|
||||
$c = array();
|
||||
|
||||
$index = 0;
|
||||
@ -742,32 +610,19 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
|
||||
foreach ($data as $key => $value) {
|
||||
$e = explode('__', $key);
|
||||
|
||||
$field = strtolower(array_pop($e));
|
||||
$component = strtolower(implode('__', $e));
|
||||
$field = strtolower(array_pop($e));
|
||||
$tableAlias = strtolower(implode('__', $e));
|
||||
|
||||
$data[$component][$field] = $value;
|
||||
$data[$tableAlias][$field] = $value;
|
||||
|
||||
unset($data[$key]);
|
||||
};
|
||||
}
|
||||
$array[] = $data;
|
||||
};
|
||||
}
|
||||
|
||||
$stmt->closeCursor();
|
||||
return $array;
|
||||
}
|
||||
/**
|
||||
* returns a Doctrine_Table for given name
|
||||
*
|
||||
* @param string $name component name
|
||||
* @return Doctrine_Table|boolean
|
||||
*/
|
||||
public function getTable($name)
|
||||
{
|
||||
if (isset($this->tables[$name])) {
|
||||
return $this->tables[$name];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* @return string returns a string representation of this object
|
||||
*/
|
||||
|
@ -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);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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
|
||||
*
|
||||
@ -88,7 +91,7 @@ abstract class Doctrine_Query_Condition extends Doctrine_Query_Part
|
||||
if (strpos($value, '\'') === false) {
|
||||
// parse booleans
|
||||
$value = $this->query->getConnection()
|
||||
->dataDict->parseBoolean($value);
|
||||
->dataDict->parseBoolean($value);
|
||||
|
||||
$a = explode('.', $value);
|
||||
|
||||
|
@ -31,7 +31,7 @@ Doctrine::autoload("Doctrine_Query_Part");
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
*/
|
||||
class Doctrine_Query_From extends Doctrine_Query_Part
|
||||
{
|
||||
{
|
||||
/**
|
||||
* DQL FROM PARSER
|
||||
* parses the from part of the query string
|
||||
@ -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;
|
||||
}
|
||||
return implode(', ', $r);
|
||||
if ($append) {
|
||||
$this->query->addQueryPart('groupby', implode(', ', $r));
|
||||
} else {
|
||||
$this->query->setQueryPart('groupby', 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) {
|
||||
|
41
lib/Doctrine/Query/Limit.php
Normal file
41
lib/Doctrine/Query/Limit.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
41
lib/Doctrine/Query/Offset.php
Normal file
41
lib/Doctrine/Query/Offset.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?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,20 +127,20 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
|
||||
throw new Doctrine_Query_Exception('Unknown DQL function: '.$func);
|
||||
}
|
||||
} else {
|
||||
$table = $this->query->load($reference, false);
|
||||
$alias = $this->query->getTableAlias($reference);
|
||||
$table = $this->query->getTable($alias);
|
||||
|
||||
$field = $table->getColumnName($field);
|
||||
$map = $this->query->load($reference, false);
|
||||
|
||||
$alias = $this->query->getTableAlias($reference);
|
||||
$table = $map['table'];
|
||||
|
||||
$field = $table->getColumnName($field);
|
||||
// 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
|
||||
$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, "'"));
|
||||
$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):'';
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class Doctrine_Record_Filter
|
||||
*/
|
||||
public function getRecord()
|
||||
{
|
||||
return $this->_record;
|
||||
return $this->_record;
|
||||
}
|
||||
/**
|
||||
* cleanData
|
||||
@ -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,9 +113,10 @@ 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;
|
||||
}
|
||||
break;
|
||||
@ -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];
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ class Doctrine_Relation_Association extends Doctrine_Relation
|
||||
*/
|
||||
public function fetchRelatedFor(Doctrine_Record $record)
|
||||
{
|
||||
$id = $record->getIncremented();
|
||||
$id = $record->getIncremented();
|
||||
if (empty($id)) {
|
||||
$coll = new Doctrine_Collection($this->getTable());
|
||||
} else {
|
||||
|
@ -792,7 +792,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
||||
$alias = $name;
|
||||
}
|
||||
|
||||
$this->bound[$alias] = array('field' => $field,
|
||||
$this->bound[$alias] = array('field' => $field,
|
||||
'type' => $type,
|
||||
'class' => $name,
|
||||
'alias' => $alias);
|
||||
@ -1125,32 +1125,38 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
||||
*/
|
||||
public function getRecord()
|
||||
{
|
||||
$this->data = array_change_key_case($this->data, CASE_LOWER);
|
||||
|
||||
$key = $this->getIdentifier();
|
||||
|
||||
if ( ! is_array($key)) {
|
||||
$key = array($key);
|
||||
}
|
||||
|
||||
foreach ($key as $k) {
|
||||
if ( ! isset($this->data[$k])) {
|
||||
throw new Doctrine_Table_Exception("Primary key value for $k wasn't found");
|
||||
if ( ! empty($this->data)) {
|
||||
$this->data = array_change_key_case($this->data, CASE_LOWER);
|
||||
|
||||
$key = $this->getIdentifier();
|
||||
|
||||
if ( ! is_array($key)) {
|
||||
$key = array($key);
|
||||
}
|
||||
$id[] = $this->data[$k];
|
||||
}
|
||||
|
||||
$id = implode(' ', $id);
|
||||
|
||||
if (isset($this->identityMap[$id])) {
|
||||
$record = $this->identityMap[$id];
|
||||
$record->hydrate($this->data);
|
||||
|
||||
foreach ($key as $k) {
|
||||
if ( ! isset($this->data[$k])) {
|
||||
throw new Doctrine_Table_Exception("Primary key value for $k wasn't found");
|
||||
}
|
||||
$id[] = $this->data[$k];
|
||||
}
|
||||
|
||||
$id = implode(' ', $id);
|
||||
|
||||
if (isset($this->identityMap[$id])) {
|
||||
$record = $this->identityMap[$id];
|
||||
$record->hydrate($this->data);
|
||||
} else {
|
||||
$recordName = $this->getClassnameToReturn();
|
||||
$record = new $recordName($this);
|
||||
$this->identityMap[$id] = $record;
|
||||
}
|
||||
$this->data = array();
|
||||
} else {
|
||||
$recordName = $this->getClassnameToReturn();
|
||||
$record = new $recordName($this);
|
||||
$this->identityMap[$id] = $record;
|
||||
$record = new $recordName($this, true);
|
||||
}
|
||||
$this->data = array();
|
||||
|
||||
|
||||
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'");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user