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
4e888855
Commit
4e888855
authored
May 19, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
c9d9bf19
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
112 additions
and
54 deletions
+112
-54
Column.php
lib/Doctrine/Column.php
+42
-2
Alias.php
lib/Doctrine/Hydrate/Alias.php
+4
-0
RawSql.php
lib/Doctrine/RawSql.php
+66
-52
No files found.
lib/Doctrine/Column.php
View file @
4e888855
...
...
@@ -36,8 +36,8 @@ class Doctrine_Column extends Doctrine_Access implements IteratorAggregate, Coun
* @var array $definition
*/
protected
$_definition
=
array
(
'type'
=>
null
,
'length'
=>
0
,
'type'
=>
null
,
'length'
=>
0
,
);
/**
* @var array $definition
...
...
@@ -86,6 +86,46 @@ class Doctrine_Column extends Doctrine_Access implements IteratorAggregate, Coun
{
$this
->
_definition
[
$name
]
=
$value
;
}
/**
* @param string $field
* @return array
*/
public
function
getEnumValues
()
{
if
(
isset
(
$this
->
_definition
[
'values'
]))
{
return
$this
->
_definition
[
'values'
];
}
else
{
return
array
();
}
}
/**
* enumValue
*
* @param string $field
* @param integer $index
* @return mixed
*/
public
function
enumValue
(
$index
)
{
if
(
$index
instanceof
Doctrine_Null
)
{
return
$index
;
}
return
isset
(
$this
->
_definition
[
'values'
][
$index
])
?
$this
->
_definition
[
'values'
][
$index
]
:
$index
;
}
/**
* enumIndex
*
* @param string $field
* @param mixed $value
* @return mixed
*/
public
function
enumIndex
(
$field
,
$value
)
{
$values
=
$this
->
getEnumValues
(
$field
);
return
array_search
(
$value
,
$values
);
}
/**
* count
*
...
...
lib/Doctrine/Hydrate/Alias.php
View file @
4e888855
...
...
@@ -99,6 +99,10 @@ class Doctrine_Hydrate_Alias
return
$alias
;
}
public
function
addAlias
(
$tableAlias
,
$componentAlias
)
{
$this
->
shortAliases
[
$tableAlias
]
=
$componentAlias
;
}
/**
* getShortAlias
* some database such as Oracle need the identifier lengths to be < ~30 chars
...
...
lib/Doctrine/RawSql.php
View file @
4e888855
...
...
@@ -35,7 +35,7 @@ class Doctrine_RawSql extends Doctrine_Hydrate
/**
* @var array $fields
*/
private
$fields
;
private
$fields
=
array
()
;
/**
* __call
* method overloader
...
...
@@ -59,16 +59,6 @@ class Doctrine_RawSql extends Doctrine_Hydrate
}
return
$this
;
}
/**
* get
*/
public
function
get
(
$name
)
{
if
(
!
isset
(
$this
->
parts
[
$name
]))
{
throw
new
Doctrine_RawSql_Exception
(
'Unknown query part '
.
$name
);
}
return
$this
->
parts
[
$name
];
}
/**
* parseQuery
*
...
...
@@ -82,35 +72,35 @@ class Doctrine_RawSql extends Doctrine_Hydrate
$this
->
fields
=
$m
[
1
];
$this
->
clear
();
$e
=
Doctrine_
Query
::
sqlExplode
(
$query
,
' '
);
$e
=
Doctrine_
Tokenizer
::
sqlExplode
(
$query
,
' '
);
foreach
(
$e
as
$k
=>
$part
)
{
$low
=
strtolower
(
$part
);
switch
(
strtolower
(
$part
))
{
case
"select"
:
case
"from"
:
case
"where"
:
case
"limit"
:
case
"offset"
:
case
"having"
:
case
'select'
:
case
'from'
:
case
'where'
:
case
'limit'
:
case
'offset'
:
case
'having'
:
$p
=
$low
;
if
(
!
isset
(
$parts
[
$low
]))
{
$parts
[
$low
]
=
array
();
}
break
;
case
"order"
:
case
"group"
:
case
'order'
:
case
'group'
:
$i
=
(
$k
+
1
);
if
(
isset
(
$e
[
$i
])
&&
strtolower
(
$e
[
$i
])
===
"by"
)
{
if
(
isset
(
$e
[
$i
])
&&
strtolower
(
$e
[
$i
])
===
'by'
)
{
$p
=
$low
;
$p
.=
"by"
;
$parts
[
$low
.
"by"
]
=
array
();
$p
.=
'by'
;
$parts
[
$low
.
'by'
]
=
array
();
}
else
{
$parts
[
$p
][]
=
$part
;
}
break
;
case
"by"
:
case
'by'
:
continue
;
default
:
if
(
!
isset
(
$parts
[
$p
][
0
]))
{
...
...
@@ -122,7 +112,7 @@ class Doctrine_RawSql extends Doctrine_Hydrate
};
$this
->
parts
=
$parts
;
$this
->
parts
[
"select"
]
=
array
();
$this
->
parts
[
'select'
]
=
array
();
return
$this
;
}
...
...
@@ -139,7 +129,8 @@ class Doctrine_RawSql extends Doctrine_Hydrate
if
(
!
isset
(
$e
[
1
]))
{
throw
new
Doctrine_RawSql_Exception
(
'All selected fields in Sql query must be in format tableAlias.fieldName'
);
}
if
(
!
isset
(
$this
->
tables
[
$e
[
0
]]))
{
// try to auto-add component
if
(
!
$this
->
aliasHandler
->
getComponentAlias
(
$e
[
0
]))
{
try
{
$this
->
addComponent
(
$e
[
0
],
ucwords
(
$e
[
0
]));
}
catch
(
Doctrine_Exception
$exception
)
{
...
...
@@ -149,12 +140,12 @@ class Doctrine_RawSql extends Doctrine_Hydrate
if
(
$e
[
1
]
==
'*'
)
{
foreach
(
$this
->
tables
[
$e
[
0
]]
->
getColumnNames
()
as
$name
)
{
$field
=
$e
[
0
]
.
'.'
.
$name
;
$this
->
parts
[
'select'
][
$field
]
=
$field
.
' AS '
.
$e
[
0
]
.
'__'
.
$name
;
$field
=
$e
[
0
]
.
'.'
.
$name
;
$this
->
parts
[
'select'
][
$field
]
=
$field
.
' AS '
.
$e
[
0
]
.
'__'
.
$name
;
}
}
else
{
$field
=
$e
[
0
]
.
'.'
.
$e
[
1
];
$this
->
parts
[
'select'
][
$field
]
=
$field
.
' AS '
.
$e
[
0
]
.
'__'
.
$e
[
1
];
$field
=
$e
[
0
]
.
'.'
.
$e
[
1
];
$this
->
parts
[
'select'
][
$field
]
=
$field
.
' AS '
.
$e
[
0
]
.
'__'
.
$e
[
1
];
}
}
...
...
@@ -163,8 +154,8 @@ class Doctrine_RawSql extends Doctrine_Hydrate
foreach
(
$this
->
tableAliases
as
$alias
)
{
foreach
(
$this
->
tables
[
$alias
]
->
getPrimaryKeys
()
as
$key
)
{
$field
=
$alias
.
'.'
.
$key
;
if
(
!
isset
(
$this
->
parts
[
"select"
][
$field
]))
{
$this
->
parts
[
"select"
][
$field
]
=
$field
.
" AS "
.
$alias
.
"__"
.
$key
;
if
(
!
isset
(
$this
->
parts
[
'select'
][
$field
]))
{
$this
->
parts
[
'select'
][
$field
]
=
$field
.
' AS '
.
$alias
.
'__'
.
$key
;
}
}
}
...
...
@@ -207,37 +198,60 @@ class Doctrine_RawSql extends Doctrine_Hydrate
* @param string $componentName
* @return Doctrine_RawSql
*/
public
function
addComponent
(
$tableAlias
,
$
componentName
)
public
function
addComponent
(
$tableAlias
,
$
path
)
{
$e
=
explode
(
'.'
,
$componentName
);
$tmp
=
explode
(
' '
,
$path
);
$originalAlias
=
(
count
(
$tmp
)
>
1
)
?
end
(
$tmp
)
:
null
;
$e
=
explode
(
'.'
,
$tmp
[
0
]);
$fullPath
=
$tmp
[
0
];
$fullLength
=
strlen
(
$fullPath
);
$currPath
=
''
;
$table
=
null
;
if
(
isset
(
$this
->
_aliasMap
[
$e
[
0
]]))
{
$table
=
$this
->
_aliasMap
[
$e
[
0
]][
'table'
];
$prevPath
=
$parent
=
array_shift
(
$e
);
}
$currPath
=
''
;
foreach
(
$e
as
$k
=>
$component
)
{
$currPath
.=
'.'
.
$component
;
if
(
$k
==
0
)
$currPath
=
substr
(
$currPath
,
1
);
// get length of the previous path
$length
=
strlen
(
$currPath
);
// build the current component path
$prevPath
=
(
$currPath
)
?
$currPath
.
'.'
.
$component
:
$component
;
if
(
isset
(
$this
->
tableAliases
[
$currPath
]))
{
$alias
=
$this
->
tableAliases
[
$currPath
];
$delimeter
=
substr
(
$fullPath
,
$length
,
1
);
// if an alias is not given use the current path as an alias identifier
if
(
strlen
(
$currPath
)
===
$fullLength
&&
isset
(
$originalAlias
))
{
$componentAlias
=
$originalAlias
;
}
else
{
$
alias
=
$tableAlias
;
$
componentAlias
=
$currPath
;
}
if
(
!
isset
(
$table
))
{
$conn
=
Doctrine_Manager
::
getInstance
()
->
getConnectionForComponent
(
$name
);
$table
=
$conn
->
getTable
(
$component
);
$this
->
_aliasMap
[
$componentAlias
]
=
array
(
'table'
=>
$table
);
}
else
{
$relation
=
$table
->
getRelation
(
$name
);
if
(
$table
)
{
$tableName
=
$table
->
getAliasName
(
$component
);
$this
->
_aliasMap
[
$componentAlias
]
=
array
(
'table'
=>
$relation
->
getTable
(),
'parent'
=>
$parent
,
'relation'
=>
$relation
);
}
$table
=
$this
->
conn
->
getTable
(
$component
);
$this
->
tables
[
$alias
]
=
$table
;
$this
->
fetchModes
[
$alias
]
=
Doctrine
::
FETCH_IMMEDIATE
;
$this
->
tableAliases
[
$currPath
]
=
$alias
;
$this
->
aliasHandler
->
addAlias
(
$componentAlias
,
$tableAlias
);
if
(
$k
!==
0
)
{
$this
->
joins
[
$alias
]
=
$prevAlias
;
}
$prevAlias
=
$alias
;
$prevPath
=
$currPath
;
$this
->
tableAliases
[
$currPath
]
=
$alias
;
$parent
=
$prevPath
;
}
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