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
df773520
Commit
df773520
authored
May 24, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
7e953aa2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
169 deletions
+109
-169
Hydrate.php
lib/Doctrine/Hydrate.php
+97
-5
Alias.php
lib/Doctrine/Hydrate/Alias.php
+0
-136
Query.php
lib/Doctrine/Query.php
+8
-24
RawSql.php
lib/Doctrine/RawSql.php
+4
-4
No files found.
lib/Doctrine/Hydrate.php
View file @
df773520
...
...
@@ -122,6 +122,10 @@ class Doctrine_Hydrate
* @see Doctrine_Query::* constants
*/
protected
$type
=
self
::
SELECT
;
protected
$shortAliases
=
array
();
protected
$shortAliasIndexes
=
array
();
/**
* constructor
*
...
...
@@ -133,12 +137,101 @@ class Doctrine_Hydrate
$connection
=
Doctrine_Manager
::
getInstance
()
->
getCurrentConnection
();
}
$this
->
conn
=
$connection
;
$this
->
aliasHandler
=
new
Doctrine_Hydrate_Alias
();
}
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
hasAlias
(
$tableName
)
{
return
(
isset
(
$this
->
shortAliases
[
$tableName
]));
}
public
function
getComponentAlias
(
$tableAlias
)
{
if
(
!
isset
(
$this
->
shortAliases
[
$tableAlias
]))
{
throw
new
Doctrine_Hydrate_Exception
(
'Unknown table alias '
.
$tableAlias
);
}
return
$this
->
shortAliases
[
$tableAlias
];
}
public
function
getShortAliasIndex
(
$alias
)
{
if
(
!
isset
(
$this
->
shortAliasIndexes
[
$alias
]))
{
return
0
;
}
return
$this
->
shortAliasIndexes
[
$alias
];
}
public
function
generateShortAlias
(
$componentAlias
,
$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
]
=
$componentAlias
;
return
$alias
;
}
public
function
getAliases
()
{
return
$this
->
shortAliases
;
}
public
function
addAlias
(
$tableAlias
,
$componentAlias
)
{
$this
->
shortAliases
[
$tableAlias
]
=
$componentAlias
;
}
/**
* getShortAlias
* some database such as Oracle need the identifier lengths to be < ~30 chars
* hence Doctrine creates as short identifier aliases as possible
*
* this method is used for the creation of short table aliases, its also
* smart enough to check if an alias already exists for given component (componentAlias)
*
* @param string $componentAlias the alias for the query component to search table alias for
* @param string $tableName the table name from which the table alias is being created
* @return string the generated / fetched short alias
*/
public
function
getShortAlias
(
$componentAlias
,
$tableName
=
null
)
{
$alias
=
array_search
(
$componentAlias
,
$this
->
shortAliases
);
if
(
$alias
!==
false
)
{
return
$alias
;
}
if
(
$tableName
===
null
)
{
throw
new
Doctrine_Hydrate_Exception
(
"Couldn't get short alias for "
.
$componentAlias
);
}
return
$this
->
generateShortAlias
(
$componentAlias
,
$tableName
);
}
public
function
getTableAlias
(
$componentAlias
)
{
return
$this
->
aliasHandler
->
getShortAlias
(
$componentAlias
);
return
$this
->
getShortAlias
(
$componentAlias
);
}
public
function
addQueryPart
(
$name
,
$part
)
{
...
...
@@ -174,7 +267,7 @@ class Doctrine_Hydrate
*/
public
function
copyAliases
(
$query
)
{
$this
->
aliasHandler
=
$query
->
aliasHandler
;
$this
->
shortAliases
=
$query
->
shortAliases
;
return
$this
;
}
...
...
@@ -252,7 +345,6 @@ class Doctrine_Hydrate
'offset'
=>
false
,
);
$this
->
inheritanceApplied
=
false
;
$this
->
aliasHandler
->
clear
();
}
/**
* getConnection
...
...
@@ -399,7 +491,7 @@ class Doctrine_Hydrate
if
(
empty
(
$row
))
{
continue
;
}
$alias
=
$this
->
aliasHandler
->
getComponentAlias
(
$tableAlias
);
$alias
=
$this
->
getComponentAlias
(
$tableAlias
);
$map
=
$this
->
_aliasMap
[
$alias
];
// initialize previous row array if not set
...
...
lib/Doctrine/Hydrate/Alias.php
deleted
100644 → 0
View file @
7e953aa2
<?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
hasAlias
(
$tableName
)
{
return
(
isset
(
$this
->
shortAliases
[
$tableName
]));
}
public
function
getComponentAlias
(
$tableAlias
)
{
if
(
!
isset
(
$this
->
shortAliases
[
$tableAlias
]))
{
throw
new
Doctrine_Hydrate_Exception
(
'Unknown table alias '
.
$tableAlias
);
}
return
$this
->
shortAliases
[
$tableAlias
];
}
public
function
getShortAliasIndex
(
$alias
)
{
if
(
!
isset
(
$this
->
shortAliasIndexes
[
$alias
]))
{
return
0
;
}
return
$this
->
shortAliasIndexes
[
$alias
];
}
public
function
generateShortAlias
(
$componentAlias
,
$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
]
=
$componentAlias
;
return
$alias
;
}
public
function
getAliases
()
{
return
$this
->
shortAliases
;
}
public
function
addAlias
(
$tableAlias
,
$componentAlias
)
{
$this
->
shortAliases
[
$tableAlias
]
=
$componentAlias
;
}
/**
* getShortAlias
* some database such as Oracle need the identifier lengths to be < ~30 chars
* hence Doctrine creates as short identifier aliases as possible
*
* this method is used for the creation of short table aliases, its also
* smart enough to check if an alias already exists for given component (componentAlias)
*
* @param string $componentAlias the alias for the query component to search table alias for
* @param string $tableName the table name from which the table alias is being created
* @return string the generated / fetched short alias
*/
public
function
getShortAlias
(
$componentAlias
,
$tableName
=
null
)
{
$alias
=
array_search
(
$componentAlias
,
$this
->
shortAliases
);
if
(
$alias
!==
false
)
{
return
$alias
;
}
if
(
$tableName
===
null
)
{
throw
new
Doctrine_Hydrate_Exception
(
"Couldn't get short alias for "
.
$componentAlias
);
}
return
$this
->
generateShortAlias
(
$componentAlias
,
$tableName
);
}
}
lib/Doctrine/Query.php
View file @
df773520
...
...
@@ -653,7 +653,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
break
;
}
$field
=
$this
->
aliasHandler
->
getShortAlias
(
$rootAlias
)
.
'.'
.
$table
->
getIdentifier
();
$field
=
$this
->
getShortAlias
(
$rootAlias
)
.
'.'
.
$table
->
getIdentifier
();
// only append the subquery if it actually contains something
if
(
$subquery
!==
''
)
{
...
...
@@ -704,7 +704,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$componentAlias
=
key
(
$this
->
_aliasMap
);
// get short alias
$alias
=
$this
->
aliasHandler
->
getShortAlias
(
$componentAlias
);
$alias
=
$this
->
getShortAlias
(
$componentAlias
);
$primaryKey
=
$alias
.
'.'
.
$table
->
getIdentifier
();
// initialize the base of the subquery
...
...
@@ -727,7 +727,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
foreach
(
$this
->
parts
[
'from'
]
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
);
if
(
!
in_array
(
$e
[
3
],
$this
->
subqueryAliases
)
&&
...
...
@@ -755,8 +755,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
continue
;
}
if
(
$this
->
aliasHandler
->
hasAlias
(
$part
))
{
$parts
[
$k
]
=
$this
->
aliasHandler
->
generateNewAlias
(
$part
);
if
(
$this
->
hasAlias
(
$part
))
{
$parts
[
$k
]
=
$this
->
generateNewAlias
(
$part
);
}
if
(
strpos
(
$part
,
'.'
)
!==
false
)
{
...
...
@@ -765,7 +765,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$trimmed
=
ltrim
(
$e
[
0
],
'( '
);
$pos
=
strpos
(
$e
[
0
],
$trimmed
);
$e
[
0
]
=
substr
(
$e
[
0
],
0
,
$pos
)
.
$this
->
aliasHandler
->
generateNewAlias
(
$trimmed
);
$e
[
0
]
=
substr
(
$e
[
0
],
0
,
$pos
)
.
$this
->
generateNewAlias
(
$trimmed
);
$parts
[
$k
]
=
implode
(
'.'
,
$e
);
}
}
...
...
@@ -1070,7 +1070,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$tableName
=
$table
->
getTableName
();
// get the short alias for this table
$tableAlias
=
$this
->
aliasHandler
->
getShortAlias
(
$componentAlias
,
$tableName
);
$tableAlias
=
$this
->
getShortAlias
(
$componentAlias
,
$tableName
);
// quote table name
$queryPart
=
$this
->
conn
->
quoteIdentifier
(
$tableName
);
...
...
@@ -1115,7 +1115,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$table
=
$map
[
'table'
];
// build the query base
$q
=
'SELECT COUNT(DISTINCT '
.
$this
->
aliasHandler
->
getShortAlias
(
$table
->
getTableName
())
$q
=
'SELECT COUNT(DISTINCT '
.
$this
->
getShortAlias
(
$table
->
getTableName
())
.
'.'
.
$table
->
getIdentifier
()
.
') FROM '
.
$this
->
buildFromPart
();
...
...
@@ -1153,20 +1153,4 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
return
$this
->
execute
(
$params
);
}
/**
* getShortAlias
* some database such as Oracle need the identifier lengths to be < ~30 chars
* hence Doctrine creates as short identifier aliases as possible
*
* this method is used for the creation of short table aliases, its also
* smart enough to check if an alias already exists for given component (componentAlias)
*
* @param string $componentAlias the alias for the query component to search table alias for
* @param string $tableName the table name from which the table alias is being created
* @return string the generated / fetched short alias
*/
public
function
getShortAlias
(
$componentAlias
,
$tableName
)
{
return
$this
->
aliasHandler
->
getShortAlias
(
$componentAlias
,
$tableName
);
}
}
lib/Doctrine/RawSql.php
View file @
df773520
...
...
@@ -135,7 +135,7 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract
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
->
hasAlias
(
$e
[
0
]))
{
if
(
!
$this
->
hasAlias
(
$e
[
0
]))
{
try
{
$this
->
addComponent
(
$e
[
0
],
ucwords
(
$e
[
0
]));
}
catch
(
Doctrine_Exception
$exception
)
{
...
...
@@ -144,7 +144,7 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract
}
if
(
$e
[
1
]
==
'*'
)
{
$componentAlias
=
$this
->
aliasHandler
->
getComponentAlias
(
$e
[
0
]);
$componentAlias
=
$this
->
getComponentAlias
(
$e
[
0
]);
foreach
(
$this
->
_aliasMap
[
$componentAlias
][
'table'
]
->
getColumnNames
()
as
$name
)
{
$field
=
$e
[
0
]
.
'.'
.
$name
;
...
...
@@ -158,7 +158,7 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract
// force-add all primary key fields
foreach
(
$this
->
aliasHandler
->
getAliases
()
as
$tableAlias
=>
$componentAlias
)
{
foreach
(
$this
->
getAliases
()
as
$tableAlias
=>
$componentAlias
)
{
$map
=
$this
->
_aliasMap
[
$componentAlias
];
foreach
(
$map
[
'table'
]
->
getPrimaryKeys
()
as
$key
)
{
...
...
@@ -257,7 +257,7 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract
'parent'
=>
$parent
,
'relation'
=>
$relation
);
}
$this
->
a
liasHandler
->
a
ddAlias
(
$tableAlias
,
$componentAlias
);
$this
->
addAlias
(
$tableAlias
,
$componentAlias
);
$parent
=
$currPath
;
}
...
...
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