Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
52017850
Commit
52017850
authored
May 26, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
58a5ca0c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
20 deletions
+50
-20
Hydrate.php
lib/Doctrine/Hydrate.php
+5
-7
Query.php
lib/Doctrine/Query.php
+45
-13
No files found.
lib/Doctrine/Hydrate.php
View file @
52017850
...
@@ -82,7 +82,7 @@ class Doctrine_Hydrate
...
@@ -82,7 +82,7 @@ class Doctrine_Hydrate
*
*
* parent the alias of the parent
* parent the alias of the parent
*
*
*
subAgg the subquery
aggregates of this component
*
agg the
aggregates of this component
*/
*/
protected
$_aliasMap
=
array
();
protected
$_aliasMap
=
array
();
/**
/**
...
@@ -118,7 +118,7 @@ class Doctrine_Hydrate
...
@@ -118,7 +118,7 @@ class Doctrine_Hydrate
*/
*/
protected
$type
=
self
::
SELECT
;
protected
$type
=
self
::
SELECT
;
protected
$_tableAliases
=
array
();
protected
$_tableAliases
=
array
();
/**
/**
* @var array $_tableAliasSeeds A simple array keys representing table aliases and values
* @var array $_tableAliasSeeds A simple array keys representing table aliases and values
* as table alias seeds. The seeds are used for generating short table
* as table alias seeds. The seeds are used for generating short table
...
@@ -529,14 +529,12 @@ class Doctrine_Hydrate
...
@@ -529,14 +529,12 @@ class Doctrine_Hydrate
$found
=
false
;
$found
=
false
;
// aggregate values have numeric keys
// aggregate values have numeric keys
if
(
isset
(
$row
[
0
]))
{
if
(
isset
(
$row
[
0
]))
{
// map each aggregate value
// map each aggregate value
foreach
(
$row
as
$index
=>
$value
)
{
foreach
(
$row
as
$index
=>
$value
)
{
$agg
=
false
;
$agg
=
false
;
if
(
isset
(
$this
->
pendingAggregates
[
$alias
][
$index
]))
{
if
(
isset
(
$this
->
_aliasMap
[
$alias
][
'agg'
][
$index
]))
{
$agg
=
$this
->
pendingAggregates
[
$alias
][
$index
][
3
];
$agg
=
$this
->
_aliasMap
[
$alias
][
'agg'
][
$index
];
}
elseif
(
isset
(
$this
->
_aliasMap
[
$alias
][
'subAgg'
][
$index
]))
{
$agg
=
$this
->
_aliasMap
[
$alias
][
'subAgg'
][
$index
];
}
}
$record
->
mapValue
(
$agg
,
$value
);
$record
->
mapValue
(
$agg
,
$value
);
$found
=
true
;
$found
=
true
;
...
...
lib/Doctrine/Query.php
View file @
52017850
...
@@ -37,8 +37,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
...
@@ -37,8 +37,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
* @param boolean $needsSubquery
* @param boolean $needsSubquery
*/
*/
protected
$needsSubquery
=
false
;
protected
$needsSubquery
=
false
;
protected
$_status
=
array
(
'needsSubquery'
=>
true
);
/**
/**
* @param boolean $isSubquery whether or not this query object is a subquery of another
* @param boolean $isSubquery whether or not this query object is a subquery of another
* query object
* query object
...
@@ -46,8 +44,10 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
...
@@ -46,8 +44,10 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
protected
$isSubquery
;
protected
$isSubquery
;
protected
$isLimitSubqueryUsed
=
false
;
protected
$isLimitSubqueryUsed
=
false
;
/**
protected
$neededTables
=
array
();
* @var array $_neededTableAliases an array containing the needed table aliases
*/
protected
$_neededTables
=
array
();
/**
/**
* @var array $pendingFields
* @var array $pendingFields
*/
*/
...
@@ -58,7 +58,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
...
@@ -58,7 +58,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
*/
*/
protected
$pendingSubqueries
=
array
();
protected
$pendingSubqueries
=
array
();
/**
/**
* @var array $_parsers an array of parser objects
* @var array $_parsers an array of parser objects
, each DQL query part has its own parser
*/
*/
protected
$_parsers
=
array
();
protected
$_parsers
=
array
();
/**
/**
...
@@ -191,10 +191,10 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
...
@@ -191,10 +191,10 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$this
->
isSubquery
=
(
bool
)
$bool
;
$this
->
isSubquery
=
(
bool
)
$bool
;
return
$this
;
return
$this
;
}
}
/**
/**
* getAggregateAlias
* getAggregateAlias
*
*
* @param string $dqlAlias the dql alias of an aggregate value
* @return string
* @return string
*/
*/
public
function
getAggregateAlias
(
$dqlAlias
)
public
function
getAggregateAlias
(
$dqlAlias
)
...
@@ -241,16 +241,20 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
...
@@ -241,16 +241,20 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
*/
*/
public
function
parseQueryPart
(
$queryPartName
,
$queryPart
,
$append
=
false
)
public
function
parseQueryPart
(
$queryPartName
,
$queryPart
,
$append
=
false
)
{
{
// sanity check
if
(
$queryPart
===
''
||
$queryPart
===
null
)
{
if
(
$queryPart
===
''
||
$queryPart
===
null
)
{
throw
new
Doctrine_Query_Exception
(
'Empty '
.
$queryPartName
.
' part given.'
);
throw
new
Doctrine_Query_Exception
(
'Empty '
.
$queryPartName
.
' part given.'
);
}
}
// add query part to the dql part array
if
(
$append
)
{
if
(
$append
)
{
$this
->
_dqlParts
[
$queryPartName
][]
=
$queryPart
;
$this
->
_dqlParts
[
$queryPartName
][]
=
$queryPart
;
}
else
{
}
else
{
$this
->
_dqlParts
[
$queryPartName
]
=
array
(
$queryPart
);
$this
->
_dqlParts
[
$queryPartName
]
=
array
(
$queryPart
);
}
}
if
(
!
$this
->
_options
[
'resultSetCache'
]
&&
!
$this
->
_options
[
'parserCache'
])
{
// check for cache
if
(
!
$this
->
_options
[
'resultSetCache'
]
&&
!
$this
->
_options
[
'parserCache'
])
{
$parser
=
$this
->
getParser
(
$queryPartName
);
$parser
=
$this
->
getParser
(
$queryPartName
);
$sql
=
$parser
->
parse
(
$queryPart
);
$sql
=
$parser
->
parse
(
$queryPart
);
...
@@ -343,7 +347,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
...
@@ -343,7 +347,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
// subselect found in SELECT part
// subselect found in SELECT part
$this
->
parseSubselect
(
$reference
);
$this
->
parseSubselect
(
$reference
);
}
else
{
}
else
{
$this
->
parseAggregateFunction
2
(
$reference
);
$this
->
parseAggregateFunction
(
$reference
);
}
}
}
else
{
}
else
{
...
@@ -381,7 +385,16 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
...
@@ -381,7 +385,16 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$this
->
pendingSubqueries
[]
=
array
(
$subquery
,
$alias
);
$this
->
pendingSubqueries
[]
=
array
(
$subquery
,
$alias
);
}
}
public
function
parseAggregateFunction2
(
$func
)
/**
* parseAggregateFunction
* parses an aggregate function and returns the parsed form
*
* @see Doctrine_Expression
* @param string $func DQL aggregate function
* @throws Doctrine_Query_Exception if unknown aggregate function given
* @return array parsed form of given function
*/
public
function
parseAggregateFunction
(
$func
)
{
{
$e
=
Doctrine_Tokenizer
::
bracketExplode
(
$func
,
' '
);
$e
=
Doctrine_Tokenizer
::
bracketExplode
(
$func
,
' '
);
$func
=
$e
[
0
];
$func
=
$e
[
0
];
...
@@ -436,6 +449,15 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
...
@@ -436,6 +449,15 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
throw
new
Doctrine_Query_Exception
(
'Unknown function '
.
$func
.
'.'
);
throw
new
Doctrine_Query_Exception
(
'Unknown function '
.
$func
.
'.'
);
}
}
}
}
/**
* processPendingSubqueries
* processes pending subqueries
*
* subqueries can only be processed when the query is fully constructed
* since some subqueries may be correlated
*
* @return void
*/
public
function
processPendingSubqueries
()
public
function
processPendingSubqueries
()
{
{
foreach
(
$this
->
pendingSubqueries
as
$value
)
{
foreach
(
$this
->
pendingSubqueries
as
$value
)
{
...
@@ -452,10 +474,17 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
...
@@ -452,10 +474,17 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$this
->
parts
[
'select'
][]
=
'('
.
$sql
.
') AS '
.
$sqlAlias
;
$this
->
parts
[
'select'
][]
=
'('
.
$sql
.
') AS '
.
$sqlAlias
;
$this
->
aggregateMap
[
$alias
]
=
$sqlAlias
;
$this
->
aggregateMap
[
$alias
]
=
$sqlAlias
;
$this
->
_aliasMap
[
$componentAlias
][
'
subA
gg'
][]
=
$alias
;
$this
->
_aliasMap
[
$componentAlias
][
'
a
gg'
][]
=
$alias
;
}
}
$this
->
pendingSubqueries
=
array
();
$this
->
pendingSubqueries
=
array
();
}
}
/**
* processPendingAggregates
* processes pending aggregate values for given component alias
*
* @param string $componentAlias dql component alias
* @return void
*/
public
function
processPendingAggregates
(
$componentAlias
)
public
function
processPendingAggregates
(
$componentAlias
)
{
{
$tableAlias
=
$this
->
getTableAlias
(
$componentAlias
);
$tableAlias
=
$this
->
getTableAlias
(
$componentAlias
);
...
@@ -501,8 +530,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
...
@@ -501,8 +530,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$arglist
[]
=
$e
[
0
];
$arglist
[]
=
$e
[
0
];
}
}
}
}
$index
=
count
(
$this
->
aggregateMap
);
$sqlAlias
=
$tableAlias
.
'__'
.
count
(
$this
->
aggregateMap
)
;
$sqlAlias
=
$tableAlias
.
'__'
.
$index
;
if
(
substr
(
$name
,
0
,
1
)
!==
'('
)
{
if
(
substr
(
$name
,
0
,
1
)
!==
'('
)
{
$this
->
parts
[
'select'
][]
=
$name
.
'('
.
$distinct
.
implode
(
', '
,
$arglist
)
.
') AS '
.
$sqlAlias
;
$this
->
parts
[
'select'
][]
=
$name
.
'('
.
$distinct
.
implode
(
', '
,
$arglist
)
.
') AS '
.
$sqlAlias
;
...
@@ -510,6 +539,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
...
@@ -510,6 +539,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$this
->
parts
[
'select'
][]
=
$name
.
' AS '
.
$sqlAlias
;
$this
->
parts
[
'select'
][]
=
$name
.
' AS '
.
$sqlAlias
;
}
}
$this
->
aggregateMap
[
$alias
]
=
$sqlAlias
;
$this
->
aggregateMap
[
$alias
]
=
$sqlAlias
;
$this
->
_aliasMap
[
$componentAlias
][
'agg'
][
$index
]
=
$alias
;
$this
->
neededTables
[]
=
$tableAlias
;
$this
->
neededTables
[]
=
$tableAlias
;
}
}
}
}
...
@@ -539,8 +570,9 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
...
@@ -539,8 +570,9 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
}
}
/**
/**
* buildFromPart
* buildFromPart
* builds the from part of the query and returns it
*
*
* @return string
* @return string
the query sql from part
*/
*/
public
function
buildFromPart
()
public
function
buildFromPart
()
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment