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
15088034
Commit
15088034
authored
May 19, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
4e888855
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
67 deletions
+30
-67
Query.php
lib/Doctrine/Query.php
+3
-44
RawSql.php
lib/Doctrine/RawSql.php
+27
-23
No files found.
lib/Doctrine/Query.php
View file @
15088034
...
...
@@ -40,12 +40,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable
* @param boolean $needsSubquery
*/
protected
$needsSubquery
=
false
;
/**
* @param boolean $limitSubqueryUsed
*/
protected
$limitSubqueryUsed
=
false
;
protected
$_status
=
array
(
'needsSubquery'
=>
true
);
/**
* @param boolean $isSubquery whether or not this query object is a subquery of another
...
...
@@ -53,8 +48,6 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable
*/
protected
$isSubquery
;
protected
$isDistinct
=
false
;
protected
$neededTables
=
array
();
/**
* @var array $pendingFields
...
...
@@ -65,15 +58,6 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable
* they cannot be parsed directly (some queries might be correlated)
*/
protected
$pendingSubqueries
=
array
();
/**
* @var boolean $subqueriesProcessed Whether or not pending subqueries have already been processed.
* Consequent calls to getQuery would result badly constructed queries
* without this variable
*
* Since subqueries can be correlated, they can only be processed when
* the main query is fully constructed
*/
protected
$subqueriesProcessed
=
false
;
/**
* @var array $_parsers an array of parser objects
*/
...
...
@@ -173,15 +157,6 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable
return
null
;
}
public
function
isDistinct
(
$distinct
=
null
)
{
if
(
isset
(
$distinct
))
$this
->
isDistinct
=
(
bool
)
$distinct
;
return
$this
->
isDistinct
;
}
/**
* getParser
* parser lazy-loader
...
...
@@ -355,10 +330,6 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable
}
public
function
processPendingSubqueries
()
{
if
(
$this
->
subqueriesProcessed
===
true
)
{
return
false
;
}
foreach
(
$this
->
pendingSubqueries
as
$value
)
{
list
(
$dql
,
$alias
)
=
$value
;
...
...
@@ -371,15 +342,13 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable
$tableAlias
=
$this
->
getTableAlias
(
$componentAlias
);
$sqlAlias
=
$tableAlias
.
'__'
.
count
(
$this
->
aggregateMap
);
$this
->
parts
[
'select'
][]
=
'('
.
$sql
.
') AS '
.
$sqlAlias
;
$this
->
aggregateMap
[
$alias
]
=
$sqlAlias
;
$this
->
subqueryAggregates
[
$componentAlias
][]
=
$alias
;
}
$this
->
subqueriesProcessed
=
true
;
return
true
;
$this
->
pendingSubqueries
=
array
();
}
public
function
processPendingAggregates
(
$componentAlias
)
{
...
...
@@ -530,7 +499,6 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable
if
(
!
empty
(
$this
->
parts
[
'limit'
])
&&
$this
->
needsSubquery
&&
$table
->
getAttribute
(
Doctrine
::
ATTR_QUERY_LIMIT
)
==
Doctrine
::
LIMIT_RECORDS
)
{
$needsSubQuery
=
true
;
$this
->
limitSubqueryUsed
=
true
;
}
// process all pending SELECT part subqueries
...
...
@@ -1050,15 +1018,6 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable
return
(
int
)
$this
->
getConnection
()
->
fetchOne
(
$q
,
$params
);
}
/**
* isLimitSubqueryUsed
* whether or not limit subquery algorithm is used
*
* @return boolean
*/
public
function
isLimitSubqueryUsed
()
{
return
$this
->
limitSubqueryUsed
;
}
/**
* query
...
...
lib/Doctrine/RawSql.php
View file @
15088034
...
...
@@ -61,9 +61,10 @@ class Doctrine_RawSql extends Doctrine_Hydrate
}
/**
* parseQuery
* parses an sql query and adds the parts to internal array
*
* @param string $query
* @return Doctrine_RawSql
* @param string $query
query to be parsed
* @return Doctrine_RawSql
this object
*/
public
function
parseQuery
(
$query
)
{
...
...
@@ -118,9 +119,9 @@ class Doctrine_RawSql extends Doctrine_Hydrate
}
/**
* getQuery
* builds the sql query from the given query parts
*
*
* @return string
* @return string the built sql query
*/
public
function
getQuery
()
{
...
...
@@ -130,7 +131,7 @@ class Doctrine_RawSql extends Doctrine_Hydrate
throw
new
Doctrine_RawSql_Exception
(
'All selected fields in Sql query must be in format tableAlias.fieldName'
);
}
// try to auto-add component
if
(
!
$this
->
aliasHandler
->
getComponent
Alias
(
$e
[
0
]))
{
if
(
!
$this
->
aliasHandler
->
has
Alias
(
$e
[
0
]))
{
try
{
$this
->
addComponent
(
$e
[
0
],
ucwords
(
$e
[
0
]));
}
catch
(
Doctrine_Exception
$exception
)
{
...
...
@@ -139,7 +140,9 @@ class Doctrine_RawSql extends Doctrine_Hydrate
}
if
(
$e
[
1
]
==
'*'
)
{
foreach
(
$this
->
tables
[
$e
[
0
]]
->
getColumnNames
()
as
$name
)
{
$componentAlias
=
$this
->
aliasHandler
->
getComponentAlias
(
$e
[
0
]);
foreach
(
$this
->
_aliasMap
[
$componentAlias
][
'table'
]
->
getColumnNames
()
as
$name
)
{
$field
=
$e
[
0
]
.
'.'
.
$name
;
$this
->
parts
[
'select'
][
$field
]
=
$field
.
' AS '
.
$e
[
0
]
.
'__'
.
$name
;
}
...
...
@@ -151,11 +154,14 @@ class Doctrine_RawSql extends Doctrine_Hydrate
// force-add all primary key fields
foreach
(
$this
->
tableAliases
as
$alias
)
{
foreach
(
$this
->
tables
[
$alias
]
->
getPrimaryKeys
()
as
$key
)
{
$field
=
$alias
.
'.'
.
$key
;
foreach
(
$this
->
aliasHandler
->
getAliases
()
as
$tableAlias
=>
$componentAlias
)
{
$map
=
$this
->
_aliasMap
[
$componentAlias
];
foreach
(
$map
[
'table'
]
->
getPrimaryKeys
()
as
$key
)
{
$field
=
$tableAlias
.
'.'
.
$key
;
if
(
!
isset
(
$this
->
parts
[
'select'
][
$field
]))
{
$this
->
parts
[
'select'
][
$field
]
=
$field
.
' AS '
.
$
a
lias
.
'__'
.
$key
;
$this
->
parts
[
'select'
][
$field
]
=
$field
.
' AS '
.
$
tableA
lias
.
'__'
.
$key
;
}
}
}
...
...
@@ -184,8 +190,9 @@ class Doctrine_RawSql extends Doctrine_Hydrate
}
/**
* getFields
* returns the fields associated with this parser
*
* @return array
* @return array
all the fields associated with this parser
*/
public
function
getFields
()
{
...
...
@@ -209,22 +216,21 @@ class Doctrine_RawSql extends Doctrine_Hydrate
$fullLength
=
strlen
(
$fullPath
);
$table
=
null
;
$currPath
=
''
;
if
(
isset
(
$this
->
_aliasMap
[
$e
[
0
]]))
{
$table
=
$this
->
_aliasMap
[
$e
[
0
]][
'table'
];
$
prev
Path
=
$parent
=
array_shift
(
$e
);
$
curr
Path
=
$parent
=
array_shift
(
$e
);
}
$currPath
=
''
;
foreach
(
$e
as
$k
=>
$component
)
{
// get length of the previous path
$length
=
strlen
(
$currPath
);
// build the current component path
$
prev
Path
=
(
$currPath
)
?
$currPath
.
'.'
.
$component
:
$component
;
$
curr
Path
=
(
$currPath
)
?
$currPath
.
'.'
.
$component
:
$component
;
$delimeter
=
substr
(
$fullPath
,
$length
,
1
);
...
...
@@ -236,22 +242,20 @@ class Doctrine_RawSql extends Doctrine_Hydrate
}
if
(
!
isset
(
$table
))
{
$conn
=
Doctrine_Manager
::
getInstance
()
->
getConnectionForComponent
(
$
name
);
->
getConnectionForComponent
(
$
component
);
$table
=
$conn
->
getTable
(
$component
);
$this
->
_aliasMap
[
$componentAlias
]
=
array
(
'table'
=>
$table
);
}
else
{
$relation
=
$table
->
getRelation
(
$
name
);
$relation
=
$table
->
getRelation
(
$
component
);
$this
->
_aliasMap
[
$componentAlias
]
=
array
(
'table'
=>
$relation
->
getTable
(),
'parent'
=>
$parent
,
'relation'
=>
$relation
);
}
$this
->
aliasHandler
->
addAlias
(
$
componentAlias
,
$table
Alias
);
$this
->
aliasHandler
->
addAlias
(
$
tableAlias
,
$component
Alias
);
$this
->
tableAliases
[
$currPath
]
=
$alias
;
$parent
=
$prevPath
;
$parent
=
$currPath
;
}
return
$this
;
...
...
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