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
fa2da84b
Commit
fa2da84b
authored
May 14, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
86fa70d6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
75 deletions
+95
-75
Hydrate.php
draft/new-core/Hydrate.php
+5
-1
Query.php
draft/new-core/Query.php
+90
-74
No files found.
draft/new-core/Hydrate.php
View file @
fa2da84b
...
...
@@ -151,6 +151,10 @@ class Doctrine_Hydrate2
{
$this
->
tableAliases
=
$aliases
;
}
public
function
getTableAlias
(
$componentAlias
)
{
return
$this
->
aliasHandler
->
getShortAlias
(
$componentAlias
);
}
/**
* copyAliases
*
...
...
draft/new-core/Query.php
View file @
fa2da84b
...
...
@@ -140,12 +140,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable {
public
function
processPendingFields
(
$componentAlias
)
{
$tableAlias
=
$this
->
getTableAlias
(
$componentAlias
);
if
(
!
isset
(
$this
->
tables
[
$tableAlias
]))
{
throw
new
Doctrine_Query_Exception
(
'Unknown component alias '
.
$componentAlias
);
}
$table
=
$this
->
tables
[
$tableAlias
];
$table
=
$this
->
_aliasMap
[
$componentAlias
][
'table'
];
if
(
isset
(
$this
->
pendingFields
[
$componentAlias
]))
{
$fields
=
$this
->
pendingFields
[
$componentAlias
];
...
...
@@ -642,13 +637,14 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable {
*/
public
function
getQuery
(
$params
=
array
())
{
if
(
empty
(
$this
->
parts
[
"select"
])
||
empty
(
$this
->
parts
[
"from"
]))
if
(
empty
(
$this
->
parts
[
'select'
])
||
empty
(
$this
->
parts
[
'from'
]))
{
return
false
;
}
$needsSubQuery
=
false
;
$subquery
=
''
;
$k
=
array_keys
(
$this
->
tables
);
$table
=
$this
->
tables
[
$k
[
0
]
];
$k
=
array_keys
(
$this
->
_aliasMap
);
$table
=
$this
->
_aliasMap
[
$k
[
0
]][
'table'
];
if
(
!
empty
(
$this
->
parts
[
'limit'
])
&&
$this
->
needsSubquery
&&
$table
->
getAttribute
(
Doctrine
::
ATTR_QUERY_LIMIT
)
==
Doctrine
::
LIMIT_RECORDS
)
{
$needsSubQuery
=
true
;
...
...
@@ -661,18 +657,18 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable {
// build the basic query
$str
=
''
;
if
(
$this
->
isDistinct
())
if
(
$this
->
isDistinct
())
{
$str
=
'DISTINCT '
;
}
$q
=
$this
->
getQueryBase
();
$q
.=
array_shift
(
$this
->
parts
[
'from'
]);
print
$q
;
foreach
(
$this
->
parts
[
'from'
]
as
$part
)
{
$q
.=
$this
->
parts
[
'from'
];
foreach
(
$this
->
parts
[
'join'
]
as
$parts
)
{
foreach
(
$parts
as
$part
)
{
// preserve LEFT JOINs only if needed
if
(
substr
(
$part
,
0
,
9
)
===
'LEFT JOIN'
)
{
if
(
substr
(
$part
,
0
,
9
)
===
'LEFT JOIN'
)
{
$e
=
explode
(
' '
,
$part
);
$aliases
=
array_merge
(
$this
->
subqueryAliases
,
...
...
@@ -693,31 +689,31 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable {
// we can always be sure that the first join condition exists
$e2
=
explode
(
' AND '
,
$e
[
1
]);
$part
=
$e
[
0
]
.
' ON '
.
array_shift
(
$e2
);
$part
=
$e
[
0
]
.
' ON '
.
array_shift
(
$e2
);
if
(
!
empty
(
$e2
))
{
if
(
!
empty
(
$e2
))
{
$parser
=
new
Doctrine_Query_JoinCondition
(
$this
);
$part
.=
' AND '
.
$parser
->
parse
(
implode
(
' AND '
,
$e2
));
}
$q
.=
' '
.
$part
;
}
}
if
(
!
empty
(
$this
->
parts
[
'set'
]))
{
if
(
!
empty
(
$this
->
parts
[
'set'
]))
{
$q
.=
' SET '
.
implode
(
', '
,
$this
->
parts
[
'set'
]);
}
$string
=
$this
->
applyInheritance
();
if
(
!
empty
(
$string
))
$this
->
parts
[
'where'
][]
=
'('
.
$string
.
')'
;
if
(
!
empty
(
$string
))
{
$this
->
parts
[
'where'
][]
=
'('
.
$string
.
')'
;
}
$modifyLimit
=
true
;
if
(
!
empty
(
$this
->
parts
[
"limit"
])
||
!
empty
(
$this
->
parts
[
"offset"
]))
{
if
(
!
empty
(
$this
->
parts
[
"limit"
])
||
!
empty
(
$this
->
parts
[
"offset"
]))
{
if
(
$needsSubQuery
)
{
$subquery
=
$this
->
getLimitSubquery
();
...
...
@@ -750,15 +746,17 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable {
$q
.=
(
!
empty
(
$this
->
parts
[
'having'
]))
?
' HAVING '
.
implode
(
' AND '
,
$this
->
parts
[
'having'
])
:
''
;
$q
.=
(
!
empty
(
$this
->
parts
[
'orderby'
]))
?
' ORDER BY '
.
implode
(
', '
,
$this
->
parts
[
'orderby'
])
:
''
;
if
(
$modifyLimit
)
if
(
$modifyLimit
)
{
$q
=
$this
->
conn
->
modifyLimitQuery
(
$q
,
$this
->
parts
[
'limit'
],
$this
->
parts
[
'offset'
]);
}
// return to the previous state
if
(
!
empty
(
$string
))
if
(
!
empty
(
$string
))
{
array_pop
(
$this
->
parts
[
'where'
]);
if
(
$needsSubQuery
)
}
if
(
$needsSubQuery
)
{
array_shift
(
$this
->
parts
[
'where'
]);
}
return
$q
;
}
/**
...
...
@@ -1048,21 +1046,39 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable {
$tmp
=
explode
(
' '
,
$path
);
$componentAlias
=
(
count
(
$tmp
)
>
1
)
?
end
(
$tmp
)
:
false
;
$e
=
preg_split
(
"/[.:]/"
,
$tmp
[
0
],
-
1
);
$fullPath
=
$tmp
[
0
];
$prevPath
=
''
;
if
(
isset
(
$this
->
_aliasMap
[
$e
[
0
]]))
{
$table
=
$this
->
_aliasMap
[
$e
[
0
]][
'table'
];
$parent
=
array_shift
(
$e
);
$p
revPath
=
$p
arent
=
array_shift
(
$e
);
}
foreach
(
$e
as
$key
=>
$name
)
{
// build the current component path
$prevPath
=
(
$prevPath
)
?
$prevPath
.
'.'
.
$name
:
$name
;
// if an alias is not given use the current path as an alias identifier
if
(
$prevPath
!==
$fullPath
||
!
$componentAlias
)
{
$componentAlias
=
$prevPath
;
}
// load fields if necessary
if
(
$loadFields
)
{
$this
->
pendingFields
[
$componentAlias
]
=
array
(
'*'
);
}
if
(
!
isset
(
$table
))
{
// process the root of the path
$table
=
$this
->
loadRoot
(
$name
,
$componentAlias
);
}
else
{
$relation
=
$table
->
getRelation
(
$name
);
$this
->
_aliasMap
[
$componentAlias
]
=
array
(
'parent'
=>
$parent
,
$this
->
_aliasMap
[
$componentAlias
]
=
array
(
'table'
=>
$relation
->
getTable
(),
'parent'
=>
$parent
,
'relation'
=>
$relation
);
if
(
!
$relation
->
isOneToOne
())
{
$this
->
needsSubquery
=
true
;
...
...
@@ -1070,15 +1086,15 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable {
$localAlias
=
$this
->
getShortAlias
(
$parent
,
$table
->
getTableName
());
$foreignAlias
=
$this
->
getShortAlias
(
$componentAlias
,
$relation
->
getTable
()
->
getTableName
());
$aliasString
=
$this
->
conn
->
quoteIdentifier
(
$table
->
getTableName
())
.
' AS '
.
$localAlias
;
$localSql
=
$this
->
conn
->
quoteIdentifier
(
$table
->
getTableName
())
.
' '
.
$localAlias
;
$foreignSql
=
$this
->
conn
->
quoteIdentifier
(
$relation
->
getTable
()
->
getTableName
())
.
' '
.
$foreignAlias
;
$map
=
$relation
->
getTable
()
->
inheritanceMap
;
if
(
!
$loadFields
||
!
empty
(
$map
)
||
$joinCondition
)
{
if
(
!
$loadFields
||
!
empty
(
$map
)
||
$joinCondition
)
{
$this
->
subqueryAliases
[]
=
$foreignAlias
;
}
if
(
$relation
instanceof
Doctrine_Relation_Association
)
{
$asf
=
$relation
->
getAssociationFactory
();
...
...
@@ -1090,13 +1106,9 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable {
$assocPath
=
$prevPath
.
'.'
.
$asf
->
getComponentName
();
if
(
isset
(
$this
->
tableAliases
[
$assocPath
]))
{
$assocAlias
=
$this
->
tableAliases
[
$assocPath
];
}
else
{
$assocAlias
=
$this
->
aliasHandler
->
generateShortAlias
(
$assocTableName
);
}
$assocAlias
=
$this
->
getShortAlias
(
$assocPath
,
$asf
->
getTableName
());
$queryPart
=
'LEFT JOIN '
.
$assocTableName
.
' '
.
$assocAlias
.
' ON '
.
$
foreign
Alias
.
'.'
$queryPart
=
'LEFT JOIN '
.
$assocTableName
.
' '
.
$assocAlias
.
' ON '
.
$
local
Alias
.
'.'
.
$table
->
getIdentifier
()
.
' = '
.
$assocAlias
.
'.'
.
$relation
->
getLocal
();
...
...
@@ -1105,7 +1117,9 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable {
.
$assocAlias
.
'.'
.
$relation
->
getForeign
();
}
$queryPart
=
'LEFT JOIN '
.
$aliasString
.
' ON '
.
$foreignAlias
.
'.'
$this
->
parts
[
'from'
][]
=
$queryPart
;
$queryPart
=
'LEFT JOIN '
.
$foreignSql
.
' ON '
.
$foreignAlias
.
'.'
.
$relation
->
getTable
()
->
getIdentifier
()
.
' = '
.
$assocAlias
.
'.'
.
$relation
->
getForeign
()
.
$joinCondition
;
...
...
@@ -1116,7 +1130,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable {
}
}
else
{
$queryPart
=
'LEFT JOIN '
.
$
aliasString
$queryPart
=
'LEFT JOIN '
.
$
localSql
.
' ON '
.
$localAlias
.
'.'
.
$relation
->
getLocal
()
.
' = '
.
$foreignAlias
.
'.'
.
$relation
->
getForeign
()
.
$joinCondition
;
...
...
@@ -1133,6 +1147,12 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable {
}
}
}
/**
* loadRoot
*
* @param string $name
* @param string $componentAlias
*/
public
function
loadRoot
(
$name
,
$componentAlias
)
{
// get the connection for the component
...
...
@@ -1143,7 +1163,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable {
$tableName
=
$table
->
getTableName
();
// get the short alias for this table
$tableAlias
=
$this
->
aliasHandler
->
getShortAlias
(
$tableName
);
$tableAlias
=
$this
->
aliasHandler
->
getShortAlias
(
$
componentAlias
,
$
tableName
);
// quote table name
$queryPart
=
$this
->
conn
->
quoteIdentifier
(
$tableName
);
...
...
@@ -1171,11 +1191,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable {
*/
public
function
getShortAlias
(
$componentAlias
,
$tableName
)
{
if
(
isset
(
$this
->
tableAliases
[
$componentAlias
]))
{
return
$this
->
tableAliases
[
$componentAlias
];
}
return
$this
->
aliasHandler
->
getShortAlias
(
$tableName
);
return
$this
->
aliasHandler
->
getShortAlias
(
$componentAlias
,
$tableName
);
}
}
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