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
68088c16
Commit
68088c16
authored
May 17, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enum support for placeholders!
parent
b6b91ac0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
110 additions
and
15 deletions
+110
-15
Hydrate.php
lib/Doctrine/Hydrate.php
+13
-4
Query.php
lib/Doctrine/Query.php
+57
-10
Where.php
lib/Doctrine/Query/Where.php
+7
-0
Table.php
lib/Doctrine/Table.php
+0
-1
WhereTestCase.php
tests/Query/WhereTestCase.php
+33
-0
No files found.
lib/Doctrine/Hydrate.php
View file @
68088c16
...
...
@@ -109,6 +109,8 @@ class Doctrine_Hydrate
*/
protected
$parts
=
array
(
'select'
=>
array
(),
'distinct'
=>
false
,
'forUpdate'
=>
false
,
'from'
=>
array
(),
'set'
=>
array
(),
'join'
=>
array
(),
...
...
@@ -255,6 +257,8 @@ class Doctrine_Hydrate
$this
->
tables
=
array
();
$this
->
parts
=
array
(
'select'
=>
array
(),
'distinct'
=>
false
,
'forUpdate'
=>
false
,
'from'
=>
array
(),
'set'
=>
array
(),
'join'
=>
array
(),
...
...
@@ -327,6 +331,7 @@ class Doctrine_Hydrate
public
function
_fetch
(
$params
=
array
(),
$fetchMode
=
Doctrine
::
FETCH_RECORD
)
{
$params
=
$this
->
conn
->
convertBooleans
(
array_merge
(
$this
->
params
,
$params
));
$params
=
$this
->
convertEnums
(
$params
);
if
(
!
$this
->
view
)
{
$query
=
$this
->
getQuery
(
$params
);
...
...
@@ -336,19 +341,23 @@ class Doctrine_Hydrate
if
(
$this
->
isLimitSubqueryUsed
()
&&
$this
->
conn
->
getDBH
()
->
getAttribute
(
Doctrine
::
ATTR_DRIVER_NAME
)
!==
'mysql'
)
{
$params
=
array_merge
(
$params
,
$params
);
}
$stmt
=
$this
->
conn
->
execute
(
$query
,
$params
);
return
$this
->
parseData
(
$stmt
);
}
public
function
convertEnums
(
$params
)
{
return
$params
;
}
public
function
setAliasMap
(
$map
)
{
$this
->
_aliasMap
=
$map
;
}
public
function
getAliasMap
()
public
function
getAliasMap
()
{
return
$this
->
_aliasMap
;
}
...
...
@@ -403,7 +412,7 @@ class Doctrine_Hydrate
// we keep track of all the collections
$colls
=
array
();
$colls
[]
=
$coll
;
$colls
[]
=
$coll
;
$prevRow
=
array
();
/**
* iterate over the fetched data
...
...
lib/Doctrine/Query.php
View file @
68088c16
...
...
@@ -35,15 +35,15 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable
/**
* @param array $subqueryAliases the table aliases needed in some LIMIT subqueries
*/
pr
ivate
$subqueryAliases
=
array
();
pr
otected
$subqueryAliases
=
array
();
/**
* @param boolean $needsSubquery
*/
pr
ivate
$needsSubquery
=
false
;
pr
otected
$needsSubquery
=
false
;
/**
* @param boolean $limitSubqueryUsed
*/
pr
ivate
$limitSubqueryUsed
=
false
;
pr
otected
$limitSubqueryUsed
=
false
;
protected
$_status
=
array
(
'needsSubquery'
=>
true
);
...
...
@@ -51,20 +51,20 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable
* @param boolean $isSubquery whether or not this query object is a subquery of another
* query object
*/
pr
ivate
$isSubquery
;
pr
otected
$isSubquery
;
pr
ivate
$isDistinct
=
false
;
pr
otected
$isDistinct
=
false
;
pr
ivate
$neededTables
=
array
();
pr
otected
$neededTables
=
array
();
/**
* @var array $pendingFields
*/
pr
ivate
$pendingFields
=
array
();
pr
otected
$pendingFields
=
array
();
/**
* @var array $pendingSubqueries SELECT part subqueries, these are called pending subqueries since
* they cannot be parsed directly (some queries might be correlated)
*/
pr
ivate
$pendingSubqueries
=
array
();
pr
otected
$pendingSubqueries
=
array
();
/**
* @var boolean $subqueriesProcessed Whether or not pending subqueries have already been processed.
* Consequent calls to getQuery would result badly constructed queries
...
...
@@ -73,12 +73,15 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable
* Since subqueries can be correlated, they can only be processed when
* the main query is fully constructed
*/
pr
ivate
$subqueriesProcessed
=
false
;
pr
otected
$subqueriesProcessed
=
false
;
/**
* @var array $_parsers an array of parser objects
*/
protected
$_parsers
=
array
();
/**
* @var array $_enumParams an array containing the keys of the parameters that should be enumerated
*/
protected
$_enumParams
=
array
();
/**
* create
...
...
@@ -90,6 +93,50 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable
{
return
new
Doctrine_Query
();
}
/**
* addEnumParam
* sets input parameter as an enumerated parameter
*
* @param string $key the key of the input parameter
* @return Doctrine_Query
*/
public
function
addEnumParam
(
$key
,
$table
=
null
,
$column
=
null
)
{
$array
=
(
isset
(
$table
)
||
isset
(
$column
))
?
array
(
$table
,
$column
)
:
array
();
if
(
$key
===
'?'
)
{
$this
->
_enumParams
[]
=
$array
;
}
else
{
$this
->
_enumParams
[
$key
]
=
$array
;
}
}
/**
* getEnumParams
* get all enumerated parameters
*
* @return array all enumerated parameters
*/
public
function
getEnumParams
()
{
return
$this
->
_enumParams
;
}
/**
* convertEnums
* convert enum parameters to their integer equivalents
*
* @return array converted parameter array
*/
public
function
convertEnums
(
$params
)
{
foreach
(
$this
->
_enumParams
as
$key
=>
$values
)
{
if
(
isset
(
$params
[
$key
]))
{
if
(
!
empty
(
$values
))
{
$params
[
$key
]
=
$values
[
0
]
->
enumIndex
(
$values
[
1
],
$params
[
$key
]);
}
}
}
return
$params
;
}
/**
* isSubquery
* if $bool parameter is set this method sets the value of
...
...
lib/Doctrine/Query/Where.php
View file @
68088c16
...
...
@@ -163,6 +163,13 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
}
$value
=
'('
.
implode
(
', '
,
$value
)
.
')'
;
}
}
elseif
(
substr
(
$value
,
0
,
1
)
==
':'
||
$value
===
'?'
)
{
// placeholder found
if
(
$table
->
getTypeOf
(
$field
)
==
'enum'
)
{
$this
->
query
->
addEnumParam
(
$value
,
$table
,
$field
);
}
else
{
$this
->
query
->
addEnumParam
(
$value
,
null
,
null
);
}
}
else
{
if
(
$enumIndex
!==
false
)
{
$value
=
$enumIndex
;
...
...
lib/Doctrine/Table.php
View file @
68088c16
...
...
@@ -1387,7 +1387,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
{
return
array_keys
(
$this
->
columns
);
}
/**
* getDefinitionOf
*
...
...
tests/Query/WhereTestCase.php
View file @
68088c16
...
...
@@ -211,6 +211,39 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
$this
->
assertEqual
(
$q
->
getQuery
(),
"SELECT e.id AS e__id FROM entity e WHERE e.name = 'foo.bar' AND (e.type = 0)"
);
}
public
function
testEnumValuesWorkInPlaceholders
()
{
$e
=
new
EnumTest
;
$e
->
status
=
'verified'
;
$e
->
save
();
$q
=
new
Doctrine_Query
();
$q
->
select
(
'e.*'
)
->
from
(
'EnumTest e'
)
->
where
(
'e.status = ?'
);
$this
->
assertEqual
(
count
(
$q
->
getEnumParams
()),
1
);
$q
->
execute
(
array
(
'verified'
));
}
public
function
testEnumValuesWorkWithMultiplePlaceholders
()
{
$q
=
new
Doctrine_Query
();
$q
->
select
(
'e.*'
)
->
from
(
'EnumTest e'
)
->
where
(
'e.id = ? AND e.status = ?'
);
$p
=
$q
->
getEnumParams
();
$this
->
assertEqual
(
array_keys
(
$p
),
array
(
0
,
1
));
$this
->
assertTrue
(
empty
(
$p
[
0
]));
$q
->
execute
(
array
(
1
,
'verified'
));
}
public
function
testEnumValuesWorkWithMultipleNamedPlaceholders
()
{
$q
=
new
Doctrine_Query
();
$q
->
select
(
'e.*'
)
->
from
(
'EnumTest e'
)
->
where
(
'e.id = :id AND e.status = :status'
);
$p
=
$q
->
getEnumParams
();
$this
->
assertEqual
(
array_keys
(
$p
),
array
(
':id'
,
':status'
));
$this
->
assertTrue
(
empty
(
$p
[
':id'
]));
$q
->
execute
(
array
(
1
,
'verified'
));
}
}
?>
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