Doctrine::ATTR_QUERY_LIMIT constant added
This commit is contained in:
parent
fa633fb7dd
commit
2dd3e9743a
23
Doctrine.php
23
Doctrine.php
@ -149,6 +149,25 @@ final class Doctrine {
|
||||
* collection limit attribute
|
||||
*/
|
||||
const ATTR_COLL_LIMIT = 16;
|
||||
/**
|
||||
* query limit
|
||||
*/
|
||||
const ATTR_QUERY_LIMIT = 17;
|
||||
|
||||
|
||||
/**
|
||||
* LIMIT CONSTANTS
|
||||
*/
|
||||
|
||||
/**
|
||||
* constant for row limiting
|
||||
*/
|
||||
const LIMIT_ROWS = 1;
|
||||
/**
|
||||
* constant for record limiting
|
||||
*/
|
||||
const LIMIT_RECORDS = 2;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -312,10 +331,10 @@ final class Doctrine {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* method for making a single file of most used doctrine components
|
||||
* method for making a single file of most used doctrine runtime components
|
||||
*
|
||||
* including the compiled file instead of multiple files (in worst
|
||||
* cases dozens of files) can improve performance by order of magnitude
|
||||
* cases dozens of files) can improve performance by an order of magnitude
|
||||
*
|
||||
* @throws Doctrine_Exception
|
||||
* @return void
|
||||
|
@ -120,7 +120,8 @@ abstract class Doctrine_Configurable {
|
||||
|
||||
break;
|
||||
case Doctrine::ATTR_VLD:
|
||||
|
||||
case Doctrine::ATTR_QUERY_LIMIT:
|
||||
|
||||
break;
|
||||
case Doctrine::ATTR_CACHE:
|
||||
if($value != Doctrine::CACHE_SQLITE && $value != Doctrine::CACHE_NONE)
|
||||
@ -154,7 +155,7 @@ abstract class Doctrine_Configurable {
|
||||
final public function getAttribute($attribute) {
|
||||
$attribute = (int) $attribute;
|
||||
|
||||
if($attribute < 1 || $attribute > 16)
|
||||
if($attribute < 1 || $attribute > 17)
|
||||
throw new InvalidKeyException();
|
||||
|
||||
if( ! isset($this->attributes[$attribute])) {
|
||||
|
@ -79,10 +79,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
|
||||
if( ! $init) {
|
||||
$init = true;
|
||||
$attributes = array(
|
||||
Doctrine::ATTR_CACHE_DIR => "%ROOT%".DIRECTORY_SEPARATOR."cachedir",
|
||||
Doctrine::ATTR_FETCHMODE => Doctrine::FETCH_IMMEDIATE,
|
||||
Doctrine::ATTR_CACHE_TTL => 100,
|
||||
Doctrine::ATTR_CACHE_SIZE => 100,
|
||||
Doctrine::ATTR_CACHE => Doctrine::CACHE_NONE,
|
||||
Doctrine::ATTR_BATCH_SIZE => 5,
|
||||
Doctrine::ATTR_COLL_LIMIT => 5,
|
||||
@ -91,7 +88,8 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
|
||||
Doctrine::ATTR_PK_TYPE => Doctrine::INCREMENT_KEY,
|
||||
Doctrine::ATTR_LOCKMODE => 1,
|
||||
Doctrine::ATTR_VLD => false,
|
||||
Doctrine::ATTR_CREATE_TABLES => true
|
||||
Doctrine::ATTR_CREATE_TABLES => true,
|
||||
Doctrine::ATTR_QUERY_LIMIT => Doctrine::LIMIT_RECORDS
|
||||
);
|
||||
foreach($attributes as $attribute => $value) {
|
||||
$old = $this->getAttribute($attribute);
|
||||
|
@ -263,8 +263,10 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
|
||||
|
||||
$needsSubQuery = false;
|
||||
$subquery = '';
|
||||
$k = array_keys($this->tables);
|
||||
$table = $this->tables[$k[0]];
|
||||
|
||||
if( ! empty($this->parts['limit']) && $this->needsSubquery) {
|
||||
if( ! empty($this->parts['limit']) && $this->needsSubquery && $table->getAttribute(Doctrine::ATTR_QUERY_LIMIT) == Doctrine::LIMIT_RECORDS) {
|
||||
$needsSubQuery = true;
|
||||
$this->limitSubqueryUsed = true;
|
||||
}
|
||||
@ -277,8 +279,6 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
|
||||
$a[] = $tname;
|
||||
}
|
||||
$q .= implode(", ",$a);
|
||||
$k = array_keys($this->tables);
|
||||
$table = $this->tables[$k[0]];
|
||||
|
||||
if($needsSubQuery)
|
||||
$subquery = 'SELECT DISTINCT '.$table->getTableName().".".$table->getIdentifier().
|
||||
@ -317,15 +317,16 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
|
||||
$subquery .= ( ! empty($this->parts['having']))?" HAVING ".implode(" ",$this->parts["having"]):'';
|
||||
}
|
||||
|
||||
$modifyLimit = false;
|
||||
$modifyLimit = true;
|
||||
if( ! empty($this->parts["limit"]) || ! empty($this->parts["offset"])) {
|
||||
|
||||
if($needsSubQuery) {
|
||||
$subquery = $this->connection->modifyLimitQuery($subquery,$this->parts["limit"],$this->parts["offset"]);
|
||||
|
||||
$field = $table->getTableName().'.'.$table->getIdentifier();
|
||||
array_unshift($this->parts['where'], $field.' IN ('.$subquery.')');
|
||||
} else
|
||||
$modifyLimit = true;
|
||||
$modifyLimit = false;
|
||||
}
|
||||
}
|
||||
|
||||
$q .= ( ! empty($this->parts['where']))?" WHERE ".implode(" AND ",$this->parts["where"]):'';
|
||||
|
@ -189,6 +189,20 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase {
|
||||
|
||||
$this->assertEqual($users->count(), 3);
|
||||
}
|
||||
public function testLimitAttribute() {
|
||||
$this->manager->setAttribute(Doctrine::ATTR_QUERY_LIMIT, Doctrine::LIMIT_ROWS);
|
||||
|
||||
$this->connection->clear();
|
||||
$q = new Doctrine_Query();
|
||||
$q->from("User")->where("User.Group.id = ?")->orderby("User.id DESC")->limit(5);
|
||||
$users = $q->execute(array(3));
|
||||
|
||||
$this->assertEqual($users->count(), 3);
|
||||
|
||||
$this->assertEqual($q->getQuery(), "SELECT entity.id AS entity__id, entity.name AS entity__name, entity.loginname AS entity__loginname, entity.password AS entity__password, entity.type AS entity__type, entity.created AS entity__created, entity.updated AS entity__updated, entity.email_id AS entity__email_id FROM entity LEFT JOIN groupuser ON entity.id = groupuser.user_id LEFT JOIN entity AS entity2 ON entity2.id = groupuser.group_id WHERE entity2.id = ? AND (entity.type = 0 AND (entity2.type = 1 OR entity2.type IS NULL)) ORDER BY entity.id DESC LIMIT 5");
|
||||
|
||||
$this->manager->setAttribute(Doctrine::ATTR_QUERY_LIMIT, Doctrine::LIMIT_RECORDS);
|
||||
}
|
||||
public function testLimitWithNormalManyToMany() {
|
||||
$coll = new Doctrine_Collection($this->connection->getTable("Photo"));
|
||||
$tag = new Tag();
|
||||
|
Loading…
Reference in New Issue
Block a user