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
161b9125
Commit
161b9125
authored
Nov 27, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added missing class Doctrine_Hydrate_Alias, refactored query and hydrate classes
parent
be7931ed
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
45 deletions
+106
-45
Hydrate.php
lib/Doctrine/Hydrate.php
+4
-16
Alias.php
lib/Doctrine/Hydrate/Alias.php
+94
-0
Query.php
lib/Doctrine/Query.php
+8
-29
No files found.
lib/Doctrine/Hydrate.php
View file @
161b9125
...
...
@@ -50,10 +50,6 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @var array $joins an array containing all table joins
*/
protected
$joins
=
array
();
/**
* @var array $data fetched data
*/
protected
$data
=
array
();
/**
* @var array $params query input parameters
*/
...
...
@@ -92,7 +88,9 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
protected
$pendingAggregates
=
array
();
protected
$aggregateMap
=
array
();
/**
* @var Doctrine_Hydrate_Alias $aliasHandler
*/
protected
$aliasHandler
;
/**
* @var array $parts SQL query string parts
...
...
@@ -229,7 +227,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
);
$this
->
inheritanceApplied
=
false
;
$this
->
aggregate
=
false
;
$this
->
data
=
array
();
$this
->
collections
=
array
();
$this
->
joins
=
array
();
$this
->
tableIndexes
=
array
();
...
...
@@ -541,16 +539,6 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
}
return
false
;
}
public
function
getShortAliasIndex
(
$alias
)
{
return
$this
->
aliasHandler
->
getShortAliasIndex
(
$alias
);
}
public
function
generateShortAlias
(
$tableName
)
{
return
$this
->
aliasHandler
->
generateShortAlias
(
$tableName
);
}
public
function
getShortAlias
(
$tableName
)
{
return
$this
->
aliasHandler
->
getShortAlias
(
$tableName
);
}
/**
* applyInheritance
* applies column aggregation inheritance to DQL / SQL query
...
...
lib/Doctrine/Hydrate/Alias.php
0 → 100644
View file @
161b9125
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Hydrate_Alias
* This class handles the creation of aliases for components in DQL query
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class
Doctrine_Hydrate_Alias
{
protected
$shortAliases
=
array
();
protected
$shortAliasIndexes
=
array
();
public
function
clear
()
{
$this
->
shortAliases
=
array
();
$this
->
shortAliasIndexes
=
array
();
}
public
function
generateNewAlias
(
$alias
)
{
if
(
isset
(
$this
->
shortAliases
[
$alias
]))
{
// generate a new alias
$name
=
substr
(
$alias
,
0
,
1
);
$i
=
((
int
)
substr
(
$alias
,
1
));
if
(
$i
==
0
)
$i
=
1
;
$newIndex
=
(
$this
->
shortAliasIndexes
[
$name
]
+
$i
);
return
$name
.
$newIndex
;
}
return
$alias
;
}
public
function
hasAliasFor
(
$tableName
)
{
return
(
isset
(
$this
->
shortAliases
[
$tableName
]));
}
public
function
getShortAliasIndex
(
$alias
)
{
if
(
!
isset
(
$this
->
shortAliasIndexes
[
$alias
]))
return
0
;
return
$this
->
shortAliasIndexes
[
$alias
];
}
public
function
generateShortAlias
(
$tableName
)
{
$char
=
strtolower
(
substr
(
$tableName
,
0
,
1
));
$alias
=
$char
;
if
(
!
isset
(
$this
->
shortAliasIndexes
[
$alias
]))
$this
->
shortAliasIndexes
[
$alias
]
=
1
;
while
(
isset
(
$this
->
shortAliases
[
$alias
]))
{
$alias
=
$char
.
++
$this
->
shortAliasIndexes
[
$alias
];
}
$this
->
shortAliases
[
$alias
]
=
$tableName
;
return
$alias
;
}
public
function
getShortAlias
(
$tableName
)
{
$alias
=
array_search
(
$tableName
,
$this
->
shortAliases
);
if
(
$alias
!==
false
)
return
$alias
;
return
$this
->
generateShortAlias
(
$tableName
);
}
}
lib/Doctrine/Query.php
View file @
161b9125
...
...
@@ -200,9 +200,9 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
$having
=
$this
->
having
;
$table
=
reset
(
$this
->
tables
);
$q
=
'SELECT COUNT(DISTINCT '
.
$this
->
getShortAlias
(
$table
->
getTableName
())
.
'.'
.
$table
->
getIdentifier
()
.
') FROM '
.
$table
->
getTableName
()
.
' '
.
$this
->
getShortAlias
(
$table
->
getTableName
());
$q
=
'SELECT COUNT(DISTINCT '
.
$this
->
aliasHandler
->
getShortAlias
(
$table
->
getTableName
())
.
'.'
.
$table
->
getIdentifier
()
.
') FROM '
.
$table
->
getTableName
()
.
' '
.
$this
->
aliasHandler
->
getShortAlias
(
$table
->
getTableName
());
foreach
(
$join
as
$j
)
{
$q
.=
' '
.
implode
(
' '
,
$j
);
...
...
@@ -528,7 +528,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
break
;
}
$field
=
$this
->
getShortAlias
(
$table
->
getTableName
())
.
'.'
.
$table
->
getIdentifier
();
$field
=
$this
->
aliasHandler
->
getShortAlias
(
$table
->
getTableName
())
.
'.'
.
$table
->
getIdentifier
();
// only append the subquery if it actually contains something
if
(
$subquery
!==
''
)
...
...
@@ -569,7 +569,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
$k
=
array_keys
(
$this
->
tables
);
$table
=
$this
->
tables
[
$k
[
0
]];
$alias
=
$this
->
getShortAlias
(
$table
->
getTableName
());
$alias
=
$this
->
aliasHandler
->
getShortAlias
(
$table
->
getTableName
());
$primaryKey
=
$alias
.
'.'
.
$table
->
getIdentifier
();
// initialize the base of the subquery
...
...
@@ -638,27 +638,6 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
return
$subquery
;
}
/**
public function generateNewAlias($alias) {
if(isset($this->shortAliases[$alias])) {
// generate a new alias
$name = substr($alias, 0, 1);
$i = ((int) substr($alias, 1));
if($i == 0)
$i = 1;
$newIndex = ($this->shortAliasIndexes[$name] + $i);
return $name . $newIndex;
}
return $alias;
}
*/
/**
* query the database with DQL (Doctrine Query Language)
*
...
...
@@ -1072,7 +1051,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
$table
=
$this
->
connection
->
getTable
(
$name
);
$tname
=
$this
->
getShortAlias
(
$table
->
getTableName
());
$tname
=
$this
->
aliasHandler
->
getShortAlias
(
$table
->
getTableName
());
if
(
!
isset
(
$this
->
tableAliases
[
$currPath
]))
$this
->
tableIndexes
[
$tname
]
=
1
;
...
...
@@ -1093,7 +1072,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
if
(
isset
(
$this
->
tableAliases
[
$prevPath
]))
{
$tname
=
$this
->
tableAliases
[
$prevPath
];
}
else
$tname
=
$this
->
getShortAlias
(
$table
->
getTableName
());
$tname
=
$this
->
aliasHandler
->
getShortAlias
(
$table
->
getTableName
());
$fk
=
$table
->
getRelation
(
$name
);
...
...
@@ -1105,7 +1084,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
if
(
isset
(
$this
->
tableAliases
[
$currPath
]))
{
$tname2
=
$this
->
tableAliases
[
$currPath
];
}
else
$tname2
=
$this
->
generateShortAlias
(
$original
);
$tname2
=
$this
->
aliasHandler
->
generateShortAlias
(
$original
);
$aliasString
=
$original
.
' '
.
$tname2
;
...
...
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