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
480cb5ac
Commit
480cb5ac
authored
Dec 28, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better expression support
parent
2c7642a7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
38 deletions
+71
-38
Lib.php
lib/Doctrine/Lib.php
+13
-13
Query.php
lib/Doctrine/Query.php
+46
-18
Having.php
lib/Doctrine/Query/Having.php
+5
-5
Where.php
lib/Doctrine/Query/Where.php
+7
-2
No files found.
lib/Doctrine/Lib.php
View file @
480cb5ac
...
...
@@ -137,19 +137,19 @@ class Doctrine_Lib {
$e
=
explode
(
"
\n
"
,
$sql
);
$color
=
"367FAC"
;
$l
=
$sql
;
$l
=
str_replace
(
"SELECT
"
,
"<font color='
$color
'><b>SELECT
</b></font><br \> "
,
$l
);
$l
=
str_replace
(
"FROM
"
,
"<font color='
$color
'><b>FROM
</b></font><br \>"
,
$l
);
$l
=
str_replace
(
"
LEFT JOIN"
,
"<br \><font color='
$color
'><b>LEFT JOIN
</b></font>"
,
$l
);
$l
=
str_replace
(
"
INNER JOIN"
,
"<br \><font color='
$color
'><b>INNER JOIN
</b></font>"
,
$l
);
$l
=
str_replace
(
"
WHERE"
,
"<br \><font color='
$color
'><b>WHERE
</b></font>"
,
$l
);
$l
=
str_replace
(
"
GROUP BY"
,
"<br \><font color='
$color
'><b>GROUP BY
</b></font>"
,
$l
);
$l
=
str_replace
(
"
HAVING"
,
"<br \><font color='
$color
'><b>HAVING
</b></font>"
,
$l
);
$l
=
str_replace
(
"
AS"
,
"<font color='
$color
'><b>AS
</b></font><br \> "
,
$l
);
$l
=
str_replace
(
"
ON"
,
"<font color='
$color
'><b>ON
</b></font>"
,
$l
);
$l
=
str_replace
(
"
ORDER BY"
,
"<font color='
$color
'><b>ORDER BY
</b></font><br \>"
,
$l
);
$l
=
str_replace
(
"
LIMIT"
,
"<font color='
$color
'><b>LIMIT
</b></font><br \>"
,
$l
);
$l
=
str_replace
(
"
OFFSET"
,
"<font color='
$color
'><b>OFFSET
</b></font><br \>"
,
$l
);
$l
=
str_replace
(
" "
,
"<dd>"
,
$l
);
$l
=
str_replace
(
"SELECT
"
,
"<font color='
$color
'><b>SELECT
</b></font><br \> "
,
$l
);
$l
=
str_replace
(
"FROM
"
,
"<font color='
$color
'><b>FROM
</b></font><br \>"
,
$l
);
$l
=
str_replace
(
"
LEFT JOIN "
,
"<br \><font color='
$color
'><b> LEFT JOIN
</b></font>"
,
$l
);
$l
=
str_replace
(
"
INNER JOIN "
,
"<br \><font color='
$color
'><b> INNER JOIN
</b></font>"
,
$l
);
$l
=
str_replace
(
"
WHERE "
,
"<br \><font color='
$color
'><b> WHERE
</b></font>"
,
$l
);
$l
=
str_replace
(
"
GROUP BY "
,
"<br \><font color='
$color
'><b> GROUP BY
</b></font>"
,
$l
);
$l
=
str_replace
(
"
HAVING "
,
"<br \><font color='
$color
'><b> HAVING
</b></font>"
,
$l
);
$l
=
str_replace
(
"
AS "
,
"<font color='
$color
'><b> AS
</b></font><br \> "
,
$l
);
$l
=
str_replace
(
"
ON "
,
"<font color='
$color
'><b> ON
</b></font>"
,
$l
);
$l
=
str_replace
(
"
ORDER BY "
,
"<font color='
$color
'><b> ORDER BY
</b></font><br \>"
,
$l
);
$l
=
str_replace
(
"
LIMIT "
,
"<font color='
$color
'><b> LIMIT
</b></font><br \>"
,
$l
);
$l
=
str_replace
(
"
OFFSET "
,
"<font color='
$color
'><b> OFFSET
</b></font><br \>"
,
$l
);
$l
=
str_replace
(
" "
,
"<dd>"
,
$l
);
return
$l
;
}
...
...
lib/Doctrine/Query.php
View file @
480cb5ac
...
...
@@ -144,31 +144,40 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
$pos
=
strpos
(
$func
,
'('
);
$name
=
substr
(
$func
,
0
,
$pos
);
switch
(
$name
)
{
case
'MAX'
:
case
'MIN'
:
case
'COUNT'
:
case
'AVG'
:
case
'SUM'
:
$reference
=
substr
(
$func
,
(
$pos
+
1
),
-
1
);
$e2
=
explode
(
' '
,
$reference
);
if
(
method_exists
(
$this
->
conn
->
expression
,
$name
))
{
$argStr
=
substr
(
$func
,
(
$pos
+
1
),
-
1
);
$args
=
explode
(
','
,
$argStr
);
$e2
=
explode
(
' '
,
$args
[
0
]);
$distinct
=
''
;
if
(
count
(
$e2
)
>
1
)
{
if
(
strtoupper
(
$e2
[
0
])
==
'DISTINCT'
)
$distinct
=
'DISTINCT '
;
$
reference
=
$e2
[
1
];
$
args
[
0
]
=
$e2
[
1
];
}
$parts
=
explode
(
'.'
,
$reference
);
$parts
=
explode
(
'.'
,
$args
[
0
]);
$owner
=
$parts
[
0
];
$alias
=
(
isset
(
$e
[
1
]))
?
$e
[
1
]
:
$name
;
$this
->
pendingAggregates
[
$parts
[
0
]][]
=
array
(
$name
,
$parts
[
1
],
$distinct
,
$alias
);
break
;
default
:
throw
new
Doctrine_Query_Exception
(
'Unknown aggregate function '
.
$name
);
$e3
=
explode
(
'.'
,
$alias
);
if
(
count
(
$e3
)
>
1
)
{
$alias
=
$e3
[
1
];
$owner
=
$e3
[
0
];
}
$this
->
pendingAggregates
[
$owner
][]
=
array
(
$name
,
$args
,
$distinct
,
$alias
);
}
else
{
throw
new
Doctrine_Query_Exception
(
'Unknown aggregate function '
.
$name
);
}
}
public
function
processPendingAggregates
(
$componentAlias
)
{
...
...
@@ -179,10 +188,29 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
$table
=
$this
->
tables
[
$tableAlias
];
foreach
(
$this
->
pendingAggregates
[
$componentAlias
]
as
$args
)
{
list
(
$name
,
$arg
,
$distinct
,
$alias
)
=
$args
;
foreach
(
$this
->
pendingAggregates
[
$componentAlias
]
as
$parts
)
{
list
(
$name
,
$args
,
$distinct
,
$alias
)
=
$parts
;
$arglist
=
array
();
foreach
(
$args
as
$arg
)
{
$e
=
explode
(
'.'
,
$arg
);
if
(
count
(
$e
)
>
1
)
{
$tableAlias
=
$this
->
getTableAlias
(
$e
[
0
]);
$table
=
$this
->
tables
[
$tableAlias
];
if
(
!
$table
->
hasColumn
(
$e
[
1
]))
{
throw
new
Doctrine_Query_Exception
(
'Unknown column '
.
$e
[
1
]);
}
$arglist
[]
=
$tableAlias
.
'.'
.
$e
[
1
];
}
else
{
$arglist
[]
=
$e
[
0
];
}
}
$this
->
parts
[
"select"
][]
=
$name
.
'('
.
$distinct
.
$tableAlias
.
'.'
.
$arg
.
') AS '
.
$tableAlias
.
'__'
.
count
(
$this
->
aggregateMap
);
$this
->
parts
[
'select'
][]
=
$name
.
'('
.
$distinct
.
implode
(
', '
,
$arglist
)
.
') AS '
.
$tableAlias
.
'__'
.
count
(
$this
->
aggregateMap
);
$this
->
aggregateMap
[]
=
$table
;
}
...
...
lib/Doctrine/Query/Having.php
View file @
480cb5ac
...
...
@@ -49,16 +49,16 @@ class Doctrine_Query_Having extends Doctrine_Query_Condition {
* @return string
*/
final
public
function
load
(
$having
)
{
$e
=
Doctrine_Query
::
bracketExplode
(
$having
,
" "
,
"("
,
")"
);
$e
=
Doctrine_Query
::
bracketExplode
(
$having
,
' '
,
'('
,
')'
);
$r
=
array_shift
(
$e
);
$t
=
explode
(
"("
,
$r
);
$t
=
explode
(
'('
,
$r
);
$count
=
count
(
$t
);
$r
=
$this
->
parseAggregateFunction
(
$r
);
$operator
=
array_shift
(
$e
);
$value
=
implode
(
" "
,
$e
);
$r
.=
" "
.
$operator
.
" "
.
$value
;
$value
=
implode
(
' '
,
$e
);
$r
.=
' '
.
$operator
.
' '
.
$value
;
return
$r
;
}
...
...
@@ -68,7 +68,7 @@ class Doctrine_Query_Having extends Doctrine_Query_Condition {
* @return string
*/
public
function
__toString
()
{
return
(
!
empty
(
$this
->
parts
))
?
implode
(
" AND "
,
$this
->
parts
)
:
''
;
return
(
!
empty
(
$this
->
parts
))
?
implode
(
' AND '
,
$this
->
parts
)
:
''
;
}
}
lib/Doctrine/Query/Where.php
View file @
480cb5ac
...
...
@@ -42,7 +42,7 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
$pos
=
strpos
(
$field
,
"("
);
$pos
=
strpos
(
$field
,
'('
);
if
(
$pos
!==
false
)
{
$func
=
substr
(
$field
,
0
,
$pos
);
...
...
@@ -209,7 +209,12 @@ 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
)
:
''
;
}
...
...
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