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
b4bcc51c
Commit
b4bcc51c
authored
May 24, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
b6dcef0e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
32 deletions
+72
-32
Hydrate.php
lib/Doctrine/Hydrate.php
+70
-30
Query.php
lib/Doctrine/Query.php
+2
-2
No files found.
lib/Doctrine/Hydrate.php
View file @
b4bcc51c
...
...
@@ -118,9 +118,13 @@ class Doctrine_Hydrate
*/
protected
$type
=
self
::
SELECT
;
protected
$shortAliases
=
array
();
protected
$shortAliasIndexes
=
array
();
protected
$_tableAliases
=
array
();
/**
* @var array $_tableAliasSeeds A simple array keys representing table aliases and values
* as table alias seeds. The seeds are used for generating short table
* aliases.
*/
protected
$_tableAliasSeeds
=
array
();
/**
* constructor
*
...
...
@@ -133,18 +137,25 @@ class Doctrine_Hydrate
}
$this
->
_conn
=
$connection
;
}
public
function
generateNewAlias
(
$alias
)
/**
* generateNewTableAlias
* generates a new alias from given table alias
*
* @param string $tableAlias table alias from which to generate the new alias from
* @return string the created table alias
*/
public
function
generateNewTableAlias
(
$tableAlias
)
{
if
(
isset
(
$this
->
shortAliases
[
$a
lias
]))
{
if
(
isset
(
$this
->
_tableAliases
[
$tableA
lias
]))
{
// generate a new alias
$name
=
substr
(
$
a
lias
,
0
,
1
);
$i
=
((
int
)
substr
(
$
a
lias
,
1
));
$name
=
substr
(
$
tableA
lias
,
0
,
1
);
$i
=
((
int
)
substr
(
$
tableA
lias
,
1
));
if
(
$i
==
0
)
{
$i
=
1
;
}
$newIndex
=
(
$this
->
shortAliasIndexe
s
[
$name
]
+
$i
);
$newIndex
=
(
$this
->
_tableAliasSeed
s
[
$name
]
+
$i
);
return
$name
.
$newIndex
;
}
...
...
@@ -154,38 +165,53 @@ class Doctrine_Hydrate
public
function
hasAlias
(
$tableName
)
{
return
(
isset
(
$this
->
short
Aliases
[
$tableName
]));
return
(
isset
(
$this
->
_table
Aliases
[
$tableName
]));
}
public
function
getComponentAlias
(
$tableAlias
)
{
if
(
!
isset
(
$this
->
short
Aliases
[
$tableAlias
]))
{
if
(
!
isset
(
$this
->
_table
Aliases
[
$tableAlias
]))
{
throw
new
Doctrine_Hydrate_Exception
(
'Unknown table alias '
.
$tableAlias
);
}
return
$this
->
short
Aliases
[
$tableAlias
];
return
$this
->
_table
Aliases
[
$tableAlias
];
}
public
function
getShortAliasIndex
(
$alias
)
/**
* getTableAliasSeed
* returns the alias seed for given table alias
*
* @param string $tableAlias table alias that identifies the alias seed
* @return integer table alias seed
*/
public
function
getTableAliasSeed
(
$tableAlias
)
{
if
(
!
isset
(
$this
->
shortAliasIndexes
[
$a
lias
]))
{
if
(
!
isset
(
$this
->
_tableAliasSeeds
[
$tableA
lias
]))
{
return
0
;
}
return
$this
->
shortAliasIndexes
[
$a
lias
];
return
$this
->
_tableAliasSeeds
[
$tableA
lias
];
}
public
function
generateShortAlias
(
$componentAlias
,
$tableName
)
/**
* generateTableAlias
* generates a table alias from given table name and associates
* it with given component alias
*
* @param string $componentAlias the component alias to be associated with generated table alias
* @param string $tableName the table name from which to generate the table alias
* @return string the generated table alias
*/
public
function
generateTableAlias
(
$componentAlias
,
$tableName
)
{
$char
=
strtolower
(
substr
(
$tableName
,
0
,
1
));
$alias
=
$char
;
if
(
!
isset
(
$this
->
shortAliasIndexe
s
[
$alias
]))
{
$this
->
shortAliasIndexe
s
[
$alias
]
=
1
;
if
(
!
isset
(
$this
->
_tableAliasSeed
s
[
$alias
]))
{
$this
->
_tableAliasSeed
s
[
$alias
]
=
1
;
}
while
(
isset
(
$this
->
short
Aliases
[
$alias
]))
{
$alias
=
$char
.
++
$this
->
shortAliasIndexe
s
[
$alias
];
while
(
isset
(
$this
->
_table
Aliases
[
$alias
]))
{
$alias
=
$char
.
++
$this
->
_tableAliasSeed
s
[
$alias
];
}
$this
->
short
Aliases
[
$alias
]
=
$componentAlias
;
$this
->
_table
Aliases
[
$alias
]
=
$componentAlias
;
return
$alias
;
}
...
...
@@ -197,7 +223,7 @@ class Doctrine_Hydrate
*/
public
function
getAliases
()
{
return
$this
->
short
Aliases
;
return
$this
->
_table
Aliases
;
}
/**
* addTableAlias
...
...
@@ -209,7 +235,7 @@ class Doctrine_Hydrate
*/
public
function
addTableAlias
(
$tableAlias
,
$componentAlias
)
{
$this
->
short
Aliases
[
$tableAlias
]
=
$componentAlias
;
$this
->
_table
Aliases
[
$tableAlias
]
=
$componentAlias
;
return
$this
;
}
...
...
@@ -227,7 +253,7 @@ class Doctrine_Hydrate
*/
public
function
getTableAlias
(
$componentAlias
,
$tableName
=
null
)
{
$alias
=
array_search
(
$componentAlias
,
$this
->
short
Aliases
);
$alias
=
array_search
(
$componentAlias
,
$this
->
_table
Aliases
);
if
(
$alias
!==
false
)
{
return
$alias
;
...
...
@@ -237,7 +263,7 @@ class Doctrine_Hydrate
throw
new
Doctrine_Hydrate_Exception
(
"Couldn't get short alias for "
.
$componentAlias
);
}
return
$this
->
generate
Short
Alias
(
$componentAlias
,
$tableName
);
return
$this
->
generate
Table
Alias
(
$componentAlias
,
$tableName
);
}
/**
* addQueryPart
...
...
@@ -301,7 +327,7 @@ class Doctrine_Hydrate
*/
public
function
copyAliases
(
Doctrine_Hydrate
$query
)
{
$this
->
shortAliases
=
$query
->
short
Aliases
;
$this
->
_tableAliases
=
$query
->
_table
Aliases
;
return
$this
;
}
...
...
@@ -333,6 +359,15 @@ class Doctrine_Hydrate
{
return
false
;
}
/**
* setQueryPart
* sets a query part in the query part array
*
* @param string $name the name of the query part to be set
* @param string $part query part string
* @throws Doctrine_Hydrate_Exception if trying to set unknown query part
* @return Doctrine_Hydrate this object
*/
public
function
getQueryPart
(
$part
)
{
if
(
!
isset
(
$this
->
parts
[
$part
]))
{
...
...
@@ -342,18 +377,23 @@ class Doctrine_Hydrate
return
$this
->
parts
[
$part
];
}
/**
* remove
* removeQueryPart
* removes a query part from the query part array
*
* @param $name
* @param string $name the name of the query part to be removed
* @throws Doctrine_Hydrate_Exception if trying to remove unknown query part
* @return Doctrine_Hydrate this object
*/
public
function
remove
(
$name
)
public
function
remove
QueryPart
(
$name
)
{
if
(
isset
(
$this
->
parts
[
$name
]))
{
if
(
$name
==
"limit"
||
$name
==
"offset"
)
{
if
(
$name
==
'limit'
||
$name
==
'offset'
)
{
$this
->
parts
[
$name
]
=
false
;
}
else
{
$this
->
parts
[
$name
]
=
array
();
}
}
else
{
throw
new
Doctrine_Hydrate_Exception
(
'Unknown query part '
.
$part
);
}
return
$this
;
}
...
...
lib/Doctrine/Query.php
View file @
b4bcc51c
...
...
@@ -756,7 +756,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
}
if
(
$this
->
hasAlias
(
$part
))
{
$parts
[
$k
]
=
$this
->
generateNewAlias
(
$part
);
$parts
[
$k
]
=
$this
->
generateNew
Table
Alias
(
$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
->
generateNewAlias
(
$trimmed
);
$e
[
0
]
=
substr
(
$e
[
0
],
0
,
$pos
)
.
$this
->
generateNew
Table
Alias
(
$trimmed
);
$parts
[
$k
]
=
implode
(
'.'
,
$e
);
}
}
...
...
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