Commit 880ca14f authored by zYne's avatar zYne

added PDO based attributes, fixed DQL aggregate value handling with left joins...

added PDO based attributes, fixed DQL aggregate value handling with left joins + added some new tests
Ticket: 263
parent 729bba87
...@@ -72,111 +72,110 @@ final class Doctrine ...@@ -72,111 +72,110 @@ final class Doctrine
const ERR_MANAGER_PARSE = -33; const ERR_MANAGER_PARSE = -33;
const ERR_LOADMODULE = -34; const ERR_LOADMODULE = -34;
const ERR_INSUFFICIENT_DATA = -35; const ERR_INSUFFICIENT_DATA = -35;
/**
* class naming error
*/
const ERR_CLASS_NAME = -36; const ERR_CLASS_NAME = -36;
/**
* PDO derived constants
*/
const CASE_LOWER = 2;
const CASE_NATURAL = 0;
const CASE_UPPER = 1;
const CURSOR_FWDONLY = 0;
const CURSOR_SCROLL = 1;
const ERRMODE_EXCEPTION = 2;
const ERRMODE_SILENT = 0;
const ERRMODE_WARNING = 1;
const FETCH_ASSOC = 2;
const FETCH_BOTH = 4;
const FETCH_BOUND = 6;
const FETCH_CLASS = 8;
const FETCH_CLASSTYPE = 262144;
const FETCH_COLUMN = 7;
const FETCH_FUNC = 10;
const FETCH_GROUP = 65536;
const FETCH_INTO = 9;
const FETCH_LAZY = 1;
const FETCH_NAMED = 11;
const FETCH_NUM = 3;
const FETCH_OBJ = 5;
const FETCH_ORI_ABS = 4;
const FETCH_ORI_FIRST = 2;
const FETCH_ORI_LAST = 3;
const FETCH_ORI_NEXT = 0;
const FETCH_ORI_PRIOR = 1;
const FETCH_ORI_REL = 5;
const FETCH_SERIALIZE = 524288;
const FETCH_UNIQUE = 196608;
const NULL_EMPTY_STRING = 1;
const NULL_NATURAL = 0;
const NULL_TO_STRING = NULL;
const PARAM_BOOL = 5;
const PARAM_INPUT_OUTPUT = -2147483648;
const PARAM_INT = 1;
const PARAM_LOB = 3;
const PARAM_NULL = 0;
const PARAM_STMT = 4;
const PARAM_STR = 2;
/** /**
* ATTRIBUTE CONSTANTS * ATTRIBUTE CONSTANTS
*/ */
/** /**
* event listener attribute * PDO derived attributes
*/ */
const ATTR_LISTENER = 1; const ATTR_AUTOCOMMIT = 0;
/** const ATTR_PREFETCH = 1;
* portability attribute const ATTR_TIMEOUT = 2;
*/ const ATTR_ERRMODE = 3;
const ATTR_PORTABILITY = 9; const ATTR_SERVER_VERSION = 4;
/** const ATTR_CLIENT_VERSION = 5;
* quote identifier attribute const ATTR_SERVER_INFO = 6;
*/ const ATTR_CONNECTION_STATUS = 7;
const ATTR_QUOTE_IDENTIFIER = 3; const ATTR_CASE = 8;
/** const ATTR_CURSOR_NAME = 9;
* field case attribute const ATTR_CURSOR = 10;
*/ const ATTR_ORACLE_NULLS = 11;
const ATTR_FIELD_CASE = 4; const ATTR_PERSISTENT = 12;
/** const ATTR_STATEMENT_CLASS = 13;
* index name format attribute const ATTR_FETCH_TABLE_NAMES = 14;
*/ const ATTR_FETCH_CATALOG_NAMES = 15;
const ATTR_IDXNAME_FORMAT = 5; const ATTR_DRIVER_NAME = 16;
/** const ATTR_STRINGIFY_FETCHES = 17;
* sequence name format attribute const ATTR_MAX_COLUMN_LEN = 18;
*/ /**
const ATTR_SEQNAME_FORMAT = 6; * Doctrine constants
/** */
* sequence column name attribute const ATTR_LISTENER = 100;
*/ const ATTR_QUOTE_IDENTIFIER = 101;
const ATTR_SEQCOL_NAME = 7; const ATTR_FIELD_CASE = 102;
/** const ATTR_IDXNAME_FORMAT = 103;
* validation attribute const ATTR_SEQNAME_FORMAT = 104;
*/ const ATTR_SEQCOL_NAME = 105;
const ATTR_VLD = 12; const ATTR_PORTABILITY = 106;
/** const ATTR_VLD = 107;
* collection key attribute const ATTR_COLL_KEY = 108;
*/ const ATTR_QUERY_LIMIT = 109;
const ATTR_COLL_KEY = 15; const ATTR_AUTO_LENGTH_VLD = 110;
/** const ATTR_AUTO_TYPE_VLD = 111;
* query limit const ATTR_DEFAULT_TABLE_TYPE = 112;
*/ const ATTR_DEF_TEXT_LENGTH = 113;
const ATTR_QUERY_LIMIT = 17; const ATTR_DEF_VARCHAR_LENGTH = 114;
/** const ATTR_DEF_TABLESPACE = 115;
* automatic length validations attribute const ATTR_EMULATE_DATABASE = 116;
*/ const ATTR_DB_NAME_FORMAT = 117;
const ATTR_AUTO_LENGTH_VLD = 19;
/**
* automatic type validations attribute
*/
const ATTR_AUTO_TYPE_VLD = 20;
/**
* default table type attribute
*/
const ATTR_DEFAULT_TABLE_TYPE = 21;
const ATTR_DEF_TEXT_LENGTH = 30;
const ATTR_DEF_VARCHAR_LENGTH = 31;
const ATTR_DEF_TABLESPACE = 32;
const ATTR_EMULATE_DATABASE = 33;
const ATTR_DB_NAME_FORMAT = 34;
/** TODO: REMOVE THE FOLLOWING CONSTANTS AND UPDATE THE DOCS ! */ /** TODO: REMOVE THE FOLLOWING CONSTANTS AND UPDATE THE DOCS ! */
/**
* fetchmode attribute const ATTR_FETCHMODE = 118;
*/ const ATTR_BATCH_SIZE = 119;
const ATTR_FETCHMODE = 2; const ATTR_LOCKMODE = 120;
/** const ATTR_NAME_PREFIX = 121;
* batch size attribute const ATTR_CREATE_TABLES = 122;
*/ const ATTR_COLL_LIMIT = 123;
const ATTR_BATCH_SIZE = 8; const ATTR_ACCESSORS = 124;
/** const ATTR_ACCESSOR_PREFIX_GET = 125;
* locking attribute const ATTR_ACCESSOR_PREFIX_SET = 126;
*/
const ATTR_LOCKMODE = 11;
/**
* name prefix attribute
*/
const ATTR_NAME_PREFIX = 13;
/**
* create tables attribute
*/
const ATTR_CREATE_TABLES = 14;
/**
* collection limit attribute
*/
const ATTR_COLL_LIMIT = 16;
/**
* accessor invoking attribute
*/
const ATTR_ACCESSORS = 18;
/**
* accessor invoking prefix get
*/
const ATTR_ACCESSOR_PREFIX_GET = 22;
/**
* accessor invoking prefix set
*/
const ATTR_ACCESSOR_PREFIX_SET = 23;
...@@ -207,11 +206,6 @@ final class Doctrine ...@@ -207,11 +206,6 @@ final class Doctrine
* mode for batch fetching * mode for batch fetching
*/ */
const FETCH_BATCH = 1; const FETCH_BATCH = 1;
/**
* LAZY FETCHING
* mode for lazy fetching
*/
const FETCH_LAZY = 2;
/** /**
* LAZY FETCHING * LAZY FETCHING
* mode for offset fetching * mode for offset fetching
......
...@@ -216,7 +216,7 @@ abstract class Doctrine_Configurable ...@@ -216,7 +216,7 @@ abstract class Doctrine_Configurable
{ {
$attribute = (int) $attribute; $attribute = (int) $attribute;
if ($attribute < 1 || $attribute > 23) if ($attribute < 0)
throw new Doctrine_Exception('Unknown attribute.'); throw new Doctrine_Exception('Unknown attribute.');
if ( ! isset($this->attributes[$attribute])) { if ( ! isset($this->attributes[$attribute])) {
......
...@@ -1100,12 +1100,12 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { ...@@ -1100,12 +1100,12 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
$s1 = substr_count($term[$i],"$e1"); $s1 = substr_count($term[$i],"$e1");
$s2 = substr_count($term[$i],"$e2"); $s2 = substr_count($term[$i],"$e2");
if(substr($term[$i],0,1) == "(") { if (substr($term[$i],0,1) == "(") {
if($s1 == $s2) { if($s1 == $s2) {
$i++; $i++;
} }
} else { } else {
if( ! (substr_count($term[$i], "'") & 1) && if ( ! (substr_count($term[$i], "'") & 1) &&
! (substr_count($term[$i], "\"") & 1) && ! (substr_count($term[$i], "\"") & 1) &&
! (substr_count($term[$i], "") & 1) ! (substr_count($term[$i], "") & 1)
) { $i++; } ) { $i++; }
...@@ -1120,7 +1120,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { ...@@ -1120,7 +1120,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
$i++; $i++;
} }
} else { } else {
if( ! (substr_count($term[$i], "'") & 1) && if ( ! (substr_count($term[$i], "'") & 1) &&
! (substr_count($term[$i], "\"") & 1) && ! (substr_count($term[$i], "\"") & 1) &&
! (substr_count($term[$i], "") & 1) ! (substr_count($term[$i], "") & 1)
) { $i++; } ) { $i++; }
...@@ -1303,14 +1303,16 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { ...@@ -1303,14 +1303,16 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
if( ! isset($this->tables[$tableName])) { if( ! isset($this->tables[$tableName])) {
$this->tables[$tableName] = $table; $this->tables[$tableName] = $table;
if($loadFields) { if ($loadFields) {
$skip = false; $skip = false;
if( ! empty($this->pendingFields)) if ( ! empty($this->pendingFields) ||
! empty($this->pendingAggregates)) {
$skip = true; $skip = true;
}
if($componentAlias) { if ($componentAlias) {
$this->compAliases[$componentAlias] = $currPath; $this->compAliases[$componentAlias] = $currPath;
if(isset($this->pendingFields[$componentAlias])) { if(isset($this->pendingFields[$componentAlias])) {
...@@ -1323,7 +1325,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { ...@@ -1323,7 +1325,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
} }
} }
if( ! $skip) { if ( ! $skip) {
$this->parseFields($fullname, $tableName, $e2, $currPath); $this->parseFields($fullname, $tableName, $e2, $currPath);
} }
} }
......
<?php <?php
class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase { /*
public function prepareData() { } * $Id$
*
* 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_AggregateValue_TestCase
*
* @package Doctrine
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase
{
public function prepareData()
{
}
public function testInitData() { public function testInitData()
{
$users = new Doctrine_Collection('User'); $users = new Doctrine_Collection('User');
$users[0]->name = 'John'; $users[0]->name = 'John';
...@@ -20,7 +55,8 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase { ...@@ -20,7 +55,8 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase {
$users->save(); $users->save();
} }
public function testRecordSupportsValueMapping() { public function testRecordSupportsValueMapping()
{
$record = new User(); $record = new User();
try { try {
...@@ -39,7 +75,8 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase { ...@@ -39,7 +75,8 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase {
} }
$this->assertEqual($i, 3); $this->assertEqual($i, 3);
} }
public function testAggregateValueIsMappedToNewRecordOnEmptyResultSet() { public function testAggregateValueIsMappedToNewRecordOnEmptyResultSet()
{
$q = new Doctrine_Query(); $q = new Doctrine_Query();
$q->select('COUNT(u.id) count')->from('User u'); $q->select('COUNT(u.id) count')->from('User u');
...@@ -49,7 +86,8 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase { ...@@ -49,7 +86,8 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($users->count(), 1); $this->assertEqual($users->count(), 1);
$this->assertEqual($users[0]->state(), Doctrine_Record::STATE_TCLEAN); $this->assertEqual($users[0]->state(), Doctrine_Record::STATE_TCLEAN);
} }
public function testAggregateValueIsMappedToRecord() { public function testAggregateValueIsMappedToRecord()
{
$q = new Doctrine_Query(); $q = new Doctrine_Query();
$q->select('u.name, COUNT(u.id) count')->from('User u')->groupby('u.name'); $q->select('u.name, COUNT(u.id) count')->from('User u')->groupby('u.name');
...@@ -64,7 +102,8 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase { ...@@ -64,7 +102,8 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($users[0]->count, 2); $this->assertEqual($users[0]->count, 2);
$this->assertEqual($users[1]->count, 2); $this->assertEqual($users[1]->count, 2);
} }
public function testAggregateValueMappingSupportsLeftJoins() { public function testAggregateValueMappingSupportsLeftJoins()
{
$q = new Doctrine_Query(); $q = new Doctrine_Query();
$q->select('u.name, COUNT(p.id) count')->from('User u')->leftJoin('u.Phonenumber p')->groupby('u.id'); $q->select('u.name, COUNT(p.id) count')->from('User u')->leftJoin('u.Phonenumber p')->groupby('u.id');
...@@ -78,7 +117,19 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase { ...@@ -78,7 +117,19 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($users[2]->Phonenumber[0]->count, 2); $this->assertEqual($users[2]->Phonenumber[0]->count, 2);
$this->assertEqual($users[3]->Phonenumber[0]->count, 1); $this->assertEqual($users[3]->Phonenumber[0]->count, 1);
} }
public function testAggregateValueMappingSupportsInnerJoins() { public function testAggregateValueMappingSupportsLeftJoins2()
{
$q = new Doctrine_Query();
$q->select('MAX(u.name)')->from('User u')->leftJoin('u.Phonenumber p')->groupby('u.id');
$this->assertEqual($q->getQuery(), 'SELECT MAX(e.name) AS e__0 FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0) GROUP BY e.id');
$users = $q->execute();
$this->assertEqual($users->count(), 1);
}
public function testAggregateValueMappingSupportsInnerJoins()
{
$q = new Doctrine_Query(); $q = new Doctrine_Query();
$q->select('u.name, COUNT(p.id) count')->from('User u')->innerJoin('u.Phonenumber p')->groupby('u.id'); $q->select('u.name, COUNT(p.id) count')->from('User u')->innerJoin('u.Phonenumber p')->groupby('u.id');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment