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
f7602a3b
Commit
f7602a3b
authored
Aug 15, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DQL Limit rewrite
parent
2e0330bf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
18 deletions
+73
-18
Query.php
Doctrine/Query.php
+46
-13
CollectionOffsetTestCase.php
tests/CollectionOffsetTestCase.php
+2
-2
QueryLimitTestCase.php
tests/QueryLimitTestCase.php
+20
-1
QueryTestCase.php
tests/QueryTestCase.php
+2
-1
run.php
tests/run.php
+3
-1
No files found.
Doctrine/Query.php
View file @
f7602a3b
...
...
@@ -242,40 +242,73 @@ class Doctrine_Query extends Doctrine_Hydrate {
final
public
function
getQuery
()
{
if
(
empty
(
$this
->
parts
[
"select"
])
||
empty
(
$this
->
parts
[
"from"
]))
return
false
;
$needsSubQuery
=
false
;
$subquery
=
''
;
if
(
!
empty
(
$this
->
parts
[
'limit'
]))
$needsSubQuery
=
true
;
// build the basic query
$q
=
"SELECT "
.
implode
(
", "
,
$this
->
parts
[
"select"
])
.
" FROM "
;
foreach
(
$this
->
parts
[
"from"
]
as
$tname
=>
$bool
)
{
$a
[]
=
$tname
;
}
$q
.=
implode
(
", "
,
$a
);
$k
=
array_keys
(
$this
->
tables
);
$table
=
$this
->
tables
[
$k
[
0
]];
if
(
$needsSubQuery
)
$subquery
=
'SELECT '
.
$table
->
getTableName
()
.
"."
.
$table
->
getIdentifier
()
.
' FROM '
.
$table
->
getTableName
();
if
(
!
empty
(
$this
->
parts
[
'join'
]))
{
foreach
(
$this
->
parts
[
'join'
]
as
$part
)
{
$q
.=
" "
.
implode
(
' '
,
$part
);
}
if
(
$needsSubQuery
)
{
foreach
(
$this
->
parts
[
'join'
]
as
$parts
)
{
foreach
(
$parts
as
$part
)
{
if
(
substr
(
$part
,
0
,
9
)
!==
'LEFT JOIN'
)
$subquery
.=
" "
.
$part
;
}
}
}
}
$string
=
$this
->
applyInheritance
();
if
(
!
empty
(
$this
->
parts
[
"where"
]))
{
$q
.=
" WHERE "
.
implode
(
" AND "
,
$this
->
parts
[
"where"
]);
if
(
!
empty
(
$string
))
$q
.=
" AND ("
.
$string
.
")"
;
}
else
{
if
(
!
empty
(
$string
))
$q
.=
" WHERE ("
.
$string
.
")"
;
if
(
!
empty
(
$string
))
$this
->
parts
[
'where'
][]
=
'('
.
$string
.
')'
;
if
(
$needsSubQuery
)
{
$subquery
.=
(
!
empty
(
$this
->
parts
[
'where'
]))
?
" WHERE "
.
implode
(
" AND "
,
$this
->
parts
[
"where"
])
:
''
;
$subquery
.=
(
!
empty
(
$this
->
parts
[
'groupby'
]))
?
" GROUP BY "
.
implode
(
", "
,
$this
->
parts
[
"groupby"
])
:
''
;
$subquery
.=
(
!
empty
(
$this
->
parts
[
'having'
]))
?
" HAVING "
.
implode
(
" "
,
$this
->
parts
[
"having"
])
:
''
;
$subquery
.=
(
!
empty
(
$this
->
parts
[
'orderby'
]))
?
" ORDER BY "
.
implode
(
" "
,
$this
->
parts
[
"orderby"
])
:
''
;
}
if
(
!
empty
(
$this
->
parts
[
"limit"
])
||
!
empty
(
$this
->
parts
[
"offset"
])
&&
$needsSubQuery
)
{
$subquery
=
$this
->
session
->
modifyLimitQuery
(
$subquery
,
$this
->
parts
[
"limit"
],
$this
->
parts
[
"offset"
]);
$field
=
$table
->
getTableName
()
.
'.'
.
$table
->
getIdentifier
();
array_unshift
(
$this
->
parts
[
'where'
],
$field
.
' IN ('
.
$subquery
.
')'
);
}
$q
.=
(
!
empty
(
$this
->
parts
[
'where'
]))
?
" WHERE "
.
implode
(
" AND "
,
$this
->
parts
[
"where"
])
:
''
;
$q
.=
(
!
empty
(
$this
->
parts
[
'groupby'
]))
?
" GROUP BY "
.
implode
(
", "
,
$this
->
parts
[
"groupby"
])
:
''
;
$q
.=
(
!
empty
(
$this
->
parts
[
'having'
]))
?
" HAVING "
.
implode
(
" "
,
$this
->
parts
[
"having"
])
:
''
;
$q
.=
(
!
empty
(
$this
->
parts
[
'orderby'
]))
?
" ORDER BY "
.
implode
(
" "
,
$this
->
parts
[
"orderby"
])
:
''
;
if
(
!
empty
(
$this
->
parts
[
"limit"
])
||
!
empty
(
$this
->
offset
))
$q
=
$this
->
session
->
modifyLimitQuery
(
$q
,
$this
->
parts
[
"limit"
],
$this
->
offset
);
// return to the previous state
if
(
!
empty
(
$string
))
array_pop
(
$this
->
parts
[
'where'
]);
if
(
$needsSubQuery
)
array_shift
(
$this
->
parts
[
'where'
]);
return
$q
;
}
...
...
@@ -294,7 +327,7 @@ class Doctrine_Query extends Doctrine_Hydrate {
if
(
$this
->
aggregate
)
{
$keys
=
array_keys
(
$this
->
tables
);
$query
=
$this
->
getQuery
();
$stmt
=
$this
->
tables
[
$keys
[
0
]]
->
getSession
()
->
select
(
$query
,
$this
->
parts
[
"limit"
],
$this
->
offset
);
$stmt
=
$this
->
tables
[
$keys
[
0
]]
->
getSession
()
->
select
(
$query
,
$this
->
parts
[
"limit"
],
$this
->
parts
[
"offset"
]
);
$data
=
$stmt
->
fetch
(
PDO
::
FETCH_ASSOC
);
if
(
count
(
$data
)
==
1
)
{
return
current
(
$data
);
...
...
@@ -374,7 +407,7 @@ class Doctrine_Query extends Doctrine_Hydrate {
$this
->
parts
[
"limit"
]
=
trim
(
$part
);
break
;
case
"OFFSET"
:
$this
->
offset
=
trim
(
$part
);
$this
->
parts
[
"offset"
]
=
trim
(
$part
);
break
;
endswitch
;
}
...
...
tests/CollectionOffsetTestCase.php
View file @
f7602a3b
...
...
@@ -45,10 +45,10 @@ class Doctrine_Collection_OffsetTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
count
(
$users
),
1
);
$coll
=
$users
[
0
]
->
Phonenumber
;
$this
->
assertEqual
(
count
(
$coll
),
1
);
$this
->
assertEqual
(
count
(
$coll
),
3
);
$coll
[
1
];
$this
->
assertEqual
(
count
(
$coll
),
2
);
$this
->
assertEqual
(
count
(
$coll
),
3
);
$this
->
assertEqual
(
$coll
[
1
]
->
phonenumber
,
"456 456"
);
}
...
...
tests/QueryLimitTestCase.php
View file @
f7602a3b
...
...
@@ -2,7 +2,26 @@
class
Doctrine_Query_Limit_TestCase
extends
Doctrine_UnitTestCase
{
public
function
testLimit
()
{
$this
->
query
->
from
(
"User.Phonenumber"
);
$this
->
query
->
limit
(
20
);
$this
->
query
->
limit
(
5
);
$sql
=
$this
->
query
->
getQuery
();
$users
=
$this
->
query
->
execute
();
$count
=
$this
->
dbh
->
count
();
$this
->
assertEqual
(
$users
->
count
(),
5
);
$users
[
0
]
->
Phonenumber
[
0
];
$this
->
assertEqual
(
$count
,
$this
->
dbh
->
count
());
$this
->
query
->
offset
(
2
);
$users
=
$this
->
query
->
execute
();
$count
=
$this
->
dbh
->
count
();
$this
->
assertEqual
(
$users
->
count
(),
5
);
$users
[
3
]
->
Phonenumber
[
0
];
$this
->
assertEqual
(
$count
,
$this
->
dbh
->
count
());
}
}
?>
tests/QueryTestCase.php
View file @
f7602a3b
...
...
@@ -34,6 +34,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this->assertEqual($users->count(), 8);
}
*/
public
function
testMultipleFetching
()
{
$count
=
$this
->
dbh
->
count
();
$this
->
session
->
getTable
(
'User'
)
->
clear
();
...
...
@@ -990,7 +991,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
public
function
testLimit
()
{
$query
=
new
Doctrine_Query
(
$this
->
session
);
$coll
=
$query
->
query
(
"FROM User LIMIT 3"
);
$coll
=
$query
->
query
(
"FROM User
(id)
LIMIT 3"
);
$this
->
assertEqual
(
$query
->
limit
,
3
);
$this
->
assertEqual
(
$coll
->
count
(),
3
);
}
...
...
tests/run.php
View file @
f7602a3b
...
...
@@ -53,7 +53,7 @@ $test->addTestCase(new Doctrine_ViewTestCase());
$test
->
addTestCase
(
new
Doctrine_Cache_Query_SqliteTestCase
());
$test
->
addTestCase
(
new
Doctrine_QueryTestCase
());
$test
->
addTestCase
(
new
Doctrine_RawSql_TestCase
());
...
...
@@ -67,6 +67,8 @@ $test->addTestCase(new Doctrine_ValidatorTestCase());
$test
->
addTestCase
(
new
Doctrine_CollectionTestCase
());
$test
->
addTestCase
(
new
Doctrine_QueryTestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_Limit_TestCase
());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
...
...
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