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
bd776a68
Commit
bd776a68
authored
Nov 05, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DQL: support for DISTINCT keyword in aggregate functions, fixes #220
parent
ba4c83ef
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
8 deletions
+23
-8
Query.php
lib/Doctrine/Query.php
+13
-3
Relation.php
lib/Doctrine/Schema/Relation.php
+2
-5
QuerySelectTestCase.php
tests/QuerySelectTestCase.php
+8
-0
No files found.
lib/Doctrine/Query.php
View file @
bd776a68
...
...
@@ -147,10 +147,20 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
case
'COUNT'
:
case
'AVG'
:
$reference
=
substr
(
$func
,
(
$pos
+
1
),
-
1
);
$e2
=
explode
(
' '
,
$reference
);
$distinct
=
''
;
if
(
count
(
$e2
)
>
1
)
{
if
(
strtoupper
(
$e2
[
0
])
==
'DISTINCT'
)
$distinct
=
'DISTINCT '
;
$reference
=
$e2
[
1
];
}
$parts
=
explode
(
'.'
,
$reference
);
$alias
=
(
isset
(
$e
[
1
]))
?
$e
[
1
]
:
$name
;
$this
->
pendingAggregates
[
$parts
[
0
]][]
=
array
(
$alias
,
$parts
[
1
]);
$this
->
pendingAggregates
[
$parts
[
0
]][]
=
array
(
$alias
,
$parts
[
1
]
,
$distinct
);
break
;
default
:
throw
new
Doctrine_Query_Exception
(
'Unknown aggregate function '
.
$name
);
...
...
@@ -167,9 +177,9 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
$table
=
$this
->
components
[
$componentPath
];
foreach
(
$this
->
pendingAggregates
[
$componentAlias
]
as
$args
)
{
list
(
$name
,
$arg
)
=
$args
;
list
(
$name
,
$arg
,
$distinct
)
=
$args
;
$this
->
parts
[
"select"
][]
=
$name
.
'('
.
$tableAlias
.
'.'
.
$arg
.
') AS '
.
$tableAlias
.
'__'
.
count
(
$this
->
aggregateMap
);
$this
->
parts
[
"select"
][]
=
$name
.
'('
.
$
distinct
.
$
tableAlias
.
'.'
.
$arg
.
') AS '
.
$tableAlias
.
'__'
.
count
(
$this
->
aggregateMap
);
$this
->
aggregateMap
[]
=
$table
;
}
...
...
lib/Doctrine/Schema/Relation.php
View file @
bd776a68
...
...
@@ -104,17 +104,14 @@ class Doctrine_Schema_Relation extends Doctrine_Schema_Object {
$this
->
referencedColumn
=
$referencedColumn
;
}
/**
*
* @return
* @access public
* @return string
*/
public
function
__toString
(
)
{
return
"Relation between '"
.
$this
->
referencingColumn
.
"' and '"
.
$this
->
referencedTable
.
"'.'"
.
$this
->
referencingColumn
.
"'"
;
return
"Relation between '"
.
$this
->
referencingColumn
.
"' and '"
.
$this
->
referencedTable
.
"'.'"
.
$this
->
referencingColumn
.
"'"
;
}
/**
*
* @return bool
* @access public
*/
public
function
isValid
(
)
{
...
...
tests/QuerySelectTestCase.php
View file @
bd776a68
<?php
class
Doctrine_Query_Select_TestCase
extends
Doctrine_UnitTestCase
{
public
function
prepareTables
()
{
}
public
function
testAggregateFunctionWithDistinctKeyword
()
{
$q
=
new
Doctrine_Query
();
$q
->
parseQuery
(
'SELECT COUNT(DISTINCT u.name) FROM User u'
);
$this
->
assertEqual
(
$q
->
getQuery
(),
'SELECT COUNT(DISTINCT e.name) AS e__0 FROM entity e WHERE (e.type = 0)'
);
}
public
function
testAggregateFunction
()
{
$q
=
new
Doctrine_Query
();
...
...
@@ -9,6 +16,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$q
->
getQuery
(),
'SELECT COUNT(e.id) AS e__0 FROM entity e WHERE (e.type = 0)'
);
}
public
function
testMultipleAggregateFunctions
()
{
$q
=
new
Doctrine_Query
();
...
...
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