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
4cd29eaf
Commit
4cd29eaf
authored
Oct 26, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DQL enum handling fixed, fixes #202
parent
79034ea7
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
96 additions
and
58 deletions
+96
-58
Where.php
lib/Doctrine/Query/Where.php
+57
-25
Association.php
lib/Doctrine/Relation/Association.php
+5
-4
Table.php
lib/Doctrine/Table.php
+13
-21
EnumTestCase.php
tests/EnumTestCase.php
+15
-6
run.php
tests/run.php
+6
-2
No files found.
lib/Doctrine/Query/Where.php
View file @
4cd29eaf
...
...
@@ -28,7 +28,7 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
}
$r
=
array_shift
(
$e
);
$a
=
explode
(
"."
,
$r
);
$a
=
explode
(
'.'
,
$r
);
if
(
count
(
$a
)
>
1
)
{
$field
=
array_pop
(
$a
);
...
...
@@ -84,36 +84,43 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
}
}
else
{
$table
=
$this
->
query
->
load
(
$reference
,
false
);
$enumIndex
=
$table
->
enumIndex
(
$field
,
trim
(
$value
,
"'"
));
$alias
=
$this
->
query
->
getTableAlias
(
$reference
);
$table
=
$this
->
query
->
getTable
(
$alias
);
// check if value is enumerated value
$enumIndex
=
$table
->
enumIndex
(
$field
,
trim
(
$value
,
"'"
));
if
(
substr
(
$value
,
0
,
1
)
==
'('
)
{
// trim brackets
$trimmed
=
Doctrine_Query
::
bracketTrim
(
$value
);
if
(
$value
==
'true'
)
$value
=
1
;
elseif
(
$value
==
'false'
)
$value
=
0
;
elseif
(
substr
(
$value
,
0
,
5
)
==
'(FROM'
)
{
// subquery
$sub
=
Doctrine_Query
::
bracketTrim
(
$value
);
if
(
substr
(
$trimmed
,
0
,
4
)
==
'FROM'
||
substr
(
$trimmed
,
0
,
6
)
==
'SELECT'
)
{
// subquery found
$q
=
new
Doctrine_Query
();
$value
=
'('
.
$q
->
parseQuery
(
$sub
)
->
getQuery
()
.
')'
;
$value
=
'('
.
$q
->
parseQuery
(
$trimmed
)
->
getQuery
()
.
')'
;
}
elseif
(
substr
(
$trimmed
,
0
,
4
)
==
'SQL:'
)
{
$value
=
'('
.
substr
(
$trimmed
,
4
)
.
')'
;
}
else
{
// check that value isn't a string
if
(
strpos
(
$value
,
'\''
)
===
false
)
{
$a
=
explode
(
'.'
,
$value
);
if
(
count
(
$a
)
>
1
)
{
// either a float or a component..
// simple in expression found
$e
=
Doctrine_Query
::
sqlExplode
(
$trimmed
,
','
);
if
(
!
is_numeric
(
$a
[
0
]))
{
// a component found
$value
=
$this
->
query
->
getTableAlias
(
$a
[
0
])
.
'.'
.
$a
[
1
];
}
$value
=
array
();
foreach
(
$e
as
$part
)
{
$index
=
$table
->
enumIndex
(
$field
,
trim
(
$part
,
"'"
));
if
(
$index
!==
false
)
$value
[]
=
$index
;
else
$value
[]
=
$this
->
parseLiteralValue
(
$part
);
}
$value
=
'('
.
implode
(
', '
,
$value
)
.
')'
;
}
}
else
{
if
(
$enumIndex
!==
false
)
$value
=
$enumIndex
;
else
$value
=
$this
->
parseLiteralValue
(
$value
);
}
switch
(
$operator
)
{
case
'<'
:
case
'>'
:
...
...
@@ -128,7 +135,32 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
}
return
$where
;
}
public
function
parseLiteralValue
(
$value
)
{
// check that value isn't a string
if
(
strpos
(
$value
,
'\''
)
===
false
)
{
// parse booleans
if
(
$value
==
'true'
)
$value
=
1
;
elseif
(
$value
==
'false'
)
$value
=
0
;
$a
=
explode
(
'.'
,
$value
);
if
(
count
(
$a
)
>
1
)
{
// either a float or a component..
if
(
!
is_numeric
(
$a
[
0
]))
{
// a component found
$value
=
$this
->
query
->
getTableAlias
(
$a
[
0
])
.
'.'
.
$a
[
1
];
}
}
}
else
{
// string literal found
}
return
$value
;
}
public
function
parseExists
(
$where
,
$negation
)
{
$operator
=
(
$negation
)
?
'EXISTS'
:
'NOT EXISTS'
;
...
...
lib/Doctrine/Relation/Association.php
View file @
4cd29eaf
...
...
@@ -61,10 +61,11 @@ class Doctrine_Relation_Association extends Doctrine_Relation {
public
function
getRelationDql
(
$count
,
$context
=
'record'
)
{
switch
(
$context
)
:
case
"record"
:
$sub
=
"SELECT "
.
$this
->
foreign
.
" FROM "
.
$this
->
associationTable
->
getTableName
()
.
" WHERE "
.
$this
->
local
.
" IN ("
.
substr
(
str_repeat
(
"?, "
,
$count
),
0
,
-
2
)
.
")"
;
$sub
=
'SQL:SELECT '
.
$this
->
foreign
.
' FROM '
.
$this
->
associationTable
->
getTableName
()
.
' WHERE '
.
$this
->
local
.
' IN ('
.
substr
(
str_repeat
(
"?, "
,
$count
),
0
,
-
2
)
.
')'
;
$dql
=
"FROM "
.
$this
->
table
->
getComponentName
();
$dql
.=
"."
.
$this
->
associationTable
->
getComponentName
();
...
...
lib/Doctrine/Table.php
View file @
4cd29eaf
...
...
@@ -88,7 +88,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
*
* so the full columns array might look something like the following:
* array(
* 'name' => array('string',
20, array('notnull' => true, 'default' => 'someone')
* 'name' => array('string',
20, array('notnull' => true, 'default' => 'someone')),
* 'age' => array('integer', 11, array('notnull' => true))
* )
*/
...
...
@@ -873,7 +873,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
/**
* @param $id database row id
* @throws Doctrine_Find_Exception
* @return DAOProxy a proxy for given identifier
*/
final
public
function
getProxy
(
$id
=
null
)
{
if
(
$id
!==
null
)
{
...
...
@@ -889,13 +888,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
}
return
$this
->
getRecord
();
}
/**
* getTableDescription
* @return array
*/
final
public
function
getTableDescription
()
{
return
$this
->
columns
;
}
/**
* count
*
...
...
tests/EnumTestCase.php
View file @
4cd29eaf
...
...
@@ -22,7 +22,7 @@ class Doctrine_EnumTestCase extends Doctrine_UnitTestCase {
try
{
$query
=
new
Doctrine_Query
(
$this
->
connection
);
$ret
=
$query
->
query
(
'FROM EnumTest WHERE EnumTest.status = open'
);
$ret
=
$query
->
query
(
"FROM EnumTest WHERE EnumTest.status = 'open'"
);
$this
->
assertEqual
(
count
(
$ret
),
1
);
}
catch
(
Exception
$e
)
{
$this
->
fail
();
...
...
@@ -32,7 +32,7 @@ class Doctrine_EnumTestCase extends Doctrine_UnitTestCase {
public
function
testInAndNotIn
()
{
try
{
$query
=
new
Doctrine_Query
(
$this
->
connection
);
$ret
=
$query
->
query
(
'FROM EnumTest WHERE EnumTest.status IN (open)'
);
$ret
=
$query
->
query
(
"FROM EnumTest WHERE EnumTest.status IN ('open')"
);
$this
->
assertEqual
(
count
(
$ret
),
1
);
}
catch
(
Exception
$e
)
{
$this
->
fail
();
...
...
@@ -40,18 +40,26 @@ class Doctrine_EnumTestCase extends Doctrine_UnitTestCase {
try
{
$query
=
new
Doctrine_Query
(
$this
->
connection
);
$ret
=
$query
->
query
(
'FROM EnumTest WHERE EnumTest.status NOT IN (verified, closed)'
);
$ret
=
$query
->
query
(
"FROM EnumTest WHERE EnumTest.status NOT IN ('verified', 'closed')"
);
$this
->
assertEqual
(
count
(
$ret
),
1
);
}
catch
(
Exception
$e
)
{
$this
->
fail
();
}
}
public
function
testNotEqual
()
{
public
function
testExpressionComposition
()
{
try
{
$query
=
new
Doctrine_Query
(
$this
->
connection
);
$ret
=
$query
->
query
(
'FROM EnumTest WHERE EnumTest.status != closed'
);
$ret
=
$query
->
query
(
"FROM EnumTest e WHERE e.id > 0 AND (e.status != 'closed' OR e.status = 'verified')"
);
$this
->
assertEqual
(
count
(
$ret
),
1
);
}
catch
(
Exception
$e
)
{
$this
->
fail
();
}
}
public
function
testNotEqual
()
{
try
{
$query
=
new
Doctrine_Query
(
$this
->
connection
);
$ret
=
$query
->
query
(
"FROM EnumTest WHERE EnumTest.status != 'closed'"
);
$this
->
assertEqual
(
count
(
$ret
),
1
);
}
catch
(
Exception
$e
)
{
$this
->
fail
();
...
...
@@ -119,5 +127,6 @@ class Doctrine_EnumTestCase extends Doctrine_UnitTestCase {
}
$this
->
assertTrue
(
$f
);
}
}
?>
tests/run.php
View file @
4cd29eaf
...
...
@@ -54,6 +54,9 @@ require_once('BooleanTestCase.php');
require_once
(
'EnumTestCase.php'
);
require_once
(
'DataDictSqliteTestCase.php'
);
require_once
(
'DataDict/PgsqlTestCase.php'
);
require_once
(
'CustomResultSetOrderTestCase.php'
);
error_reporting
(
E_ALL
);
...
...
@@ -61,6 +64,7 @@ print '<pre>';
$test
=
new
GroupTest
(
'Doctrine Framework Unit Tests'
);
$test
->
addTestCase
(
new
Doctrine_DataDict_Pgsql_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Relation_TestCase
());
...
...
@@ -124,8 +128,6 @@ $test->addTestCase(new Doctrine_CustomResultSetOrderTestCase());
$test
->
addTestCase
(
new
Doctrine_BooleanTestCase
());
$test
->
addTestCase
(
new
Doctrine_EnumTestCase
());
$test
->
addTestCase
(
new
Doctrine_Record_Filter_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_Limit_TestCase
());
...
...
@@ -149,6 +151,8 @@ $test->addTestCase(new Doctrine_Query_Delete_TestCase());
$test
->
addTestCase
(
new
Doctrine_Query_Update_TestCase
());
$test
->
addTestCase
(
new
Doctrine_EnumTestCase
());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
...
...
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