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
cba61cb3
Commit
cba61cb3
authored
Oct 08, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #155
parent
966450d4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
14 deletions
+63
-14
Query.php
lib/Doctrine/Query.php
+7
-2
Where.php
lib/Doctrine/Query/Where.php
+8
-4
QueryWhereTestCase.php
tests/QueryWhereTestCase.php
+48
-8
No files found.
lib/Doctrine/Query.php
View file @
cba61cb3
<?php
<?php
/*
/*
* $Id$
* $Id$
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
...
@@ -601,7 +601,12 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
...
@@ -601,7 +601,12 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
* @return array
* @return array
*/
*/
public
static
function
sqlExplode
(
$str
,
$d
=
" "
,
$e1
=
'('
,
$e2
=
')'
)
{
public
static
function
sqlExplode
(
$str
,
$d
=
" "
,
$e1
=
'('
,
$e2
=
')'
)
{
$str
=
explode
(
"
$d
"
,
$str
);
if
(
is_array
(
$d
))
{
$str
=
preg_split
(
'/('
.
implode
(
'|'
,
$d
)
.
')/'
,
$str
);
$d
=
stripslashes
(
$d
[
0
]);
}
else
$str
=
explode
(
"
$d
"
,
$str
);
$i
=
0
;
$i
=
0
;
$term
=
array
();
$term
=
array
();
foreach
(
$str
as
$key
=>
$val
)
{
foreach
(
$str
as
$key
=>
$val
)
{
...
...
lib/Doctrine/Query/Where.php
View file @
cba61cb3
...
@@ -12,17 +12,20 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
...
@@ -12,17 +12,20 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
public
function
load
(
$where
)
{
public
function
load
(
$where
)
{
$e
=
Doctrine_Query
::
sqlExplode
(
$where
);
$e
=
Doctrine_Query
::
sqlExplode
(
$where
);
if
(
count
(
$e
)
<
3
)
{
$e
=
Doctrine_Query
::
sqlExplode
(
$where
,
array
(
'='
,
'<'
,
'>'
,
'!='
));
}
$r
=
array_shift
(
$e
);
$r
=
array_shift
(
$e
);
$a
=
explode
(
"."
,
$r
);
$a
=
explode
(
"."
,
$r
);
if
(
count
(
$a
)
>
1
)
{
if
(
count
(
$a
)
>
1
)
{
$field
=
array_pop
(
$a
);
$field
=
array_pop
(
$a
);
$count
=
count
(
$e
);
$count
=
count
(
$e
);
$slice
=
array_slice
(
$e
,
0
,
(
$count
-
1
));
$operator
=
implode
(
' '
,
$slice
);
$slice
=
array_slice
(
$e
,
-
1
,
1
);
$slice
=
array_slice
(
$e
,
-
1
,
1
);
$value
=
implode
(
''
,
$slice
);
$value
=
implode
(
''
,
$slice
);
$operator
=
trim
(
substr
(
$where
,
strlen
(
$r
),
-
strlen
(
$value
)));
$reference
=
implode
(
"."
,
$a
);
$reference
=
implode
(
"."
,
$a
);
$count
=
count
(
$a
);
$count
=
count
(
$a
);
...
@@ -99,7 +102,8 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
...
@@ -99,7 +102,8 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
$where
=
$this
->
query
->
getTableAlias
(
$reference
)
.
'.'
.
$field
.
' '
.
$operator
.
' '
.
$value
;
$where
=
$this
->
query
->
getTableAlias
(
$reference
)
.
'.'
.
$field
.
' '
.
$operator
.
' '
.
$value
;
}
}
}
}
}
}
return
$where
;
return
$where
;
}
}
...
...
tests/QueryWhereTestCase.php
View file @
cba61cb3
...
@@ -5,7 +5,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase {
...
@@ -5,7 +5,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase {
$this
->
tables
=
array
(
'entity'
);
$this
->
tables
=
array
(
'entity'
);
parent
::
prepareTables
();
parent
::
prepareTables
();
}
}
public
function
test
QueryWith
DirectParameterSetting
()
{
public
function
testDirectParameterSetting
()
{
$this
->
connection
->
clear
();
$this
->
connection
->
clear
();
$user
=
new
User
();
$user
=
new
User
();
...
@@ -13,28 +13,68 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase {
...
@@ -13,28 +13,68 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase {
$user
->
save
();
$user
->
save
();
$q
=
new
Doctrine_Query
();
$q
=
new
Doctrine_Query
();
$q
->
from
(
'User(id)'
)
->
addWhere
(
'User.id = ?'
,
1
);
$q
->
from
(
'User(id)'
)
->
addWhere
(
'User.id = ?'
,
1
);
$users
=
$q
->
execute
();
$users
=
$q
->
execute
();
$this
->
assertEqual
(
$users
->
count
(),
1
);
$this
->
assertEqual
(
$users
->
count
(),
1
);
$this
->
assertEqual
(
$users
[
0
]
->
name
,
'someone'
);
$this
->
assertEqual
(
$users
[
0
]
->
name
,
'someone'
);
}
}
public
function
test
QueryWith
DirectMultipleParameterSetting
()
{
public
function
testDirectMultipleParameterSetting
()
{
$user
=
new
User
();
$user
=
new
User
();
$user
->
name
=
'someone
2'
;
$user
->
name
=
'someone
.
2'
;
$user
->
save
();
$user
->
save
();
$q
=
new
Doctrine_Query
();
$q
=
new
Doctrine_Query
();
$q
->
from
(
'User(id)'
)
->
addWhere
(
'User.id IN (?, ?)'
,
array
(
1
,
2
));
$q
->
from
(
'User(id)'
)
->
addWhere
(
'User.id IN (?, ?)'
,
array
(
1
,
2
));
$users
=
$q
->
execute
();
$users
=
$q
->
execute
();
$this
->
assertEqual
(
$users
->
count
(),
2
);
$this
->
assertEqual
(
$users
->
count
(),
2
);
$this
->
assertEqual
(
$users
[
0
]
->
name
,
'someone'
);
$this
->
assertEqual
(
$users
[
0
]
->
name
,
'someone'
);
$this
->
assertEqual
(
$users
[
1
]
->
name
,
'someone 2'
);
$this
->
assertEqual
(
$users
[
1
]
->
name
,
'someone.2'
);
}
public
function
testOperatorWithNoTrailingSpaces
()
{
$q
=
new
Doctrine_Query
();
$q
->
from
(
'User(id)'
)
->
where
(
"User.name='someone'"
);
$users
=
$q
->
execute
();
$this
->
assertEqual
(
$users
->
count
(),
1
);
$this
->
assertEqual
(
$q
->
getQuery
(),
"SELECT entity.id AS entity__id FROM entity WHERE entity.name = 'someone' AND (entity.type = 0)"
);
}
public
function
testOperatorWithNoTrailingSpaces2
()
{
$q
=
new
Doctrine_Query
();
$q
->
from
(
'User(id)'
)
->
where
(
"User.name='foo.bar'"
);
$users
=
$q
->
execute
();
$this
->
assertEqual
(
$users
->
count
(),
0
);
$this
->
assertEqual
(
$q
->
getQuery
(),
"SELECT entity.id AS entity__id FROM entity WHERE entity.name = 'foo.bar' AND (entity.type = 0)"
);
}
public
function
testOperatorWithSingleTrailingSpace
()
{
$q
=
new
Doctrine_Query
();
$q
->
from
(
'User(id)'
)
->
where
(
"User.name= 'foo.bar'"
);
$users
=
$q
->
execute
();
$this
->
assertEqual
(
$users
->
count
(),
0
);
$this
->
assertEqual
(
$q
->
getQuery
(),
"SELECT entity.id AS entity__id FROM entity WHERE entity.name = 'foo.bar' AND (entity.type = 0)"
);
}
public
function
testOperatorWithSingleTrailingSpace2
()
{
$q
=
new
Doctrine_Query
();
$q
->
from
(
'User(id)'
)
->
where
(
"User.name ='foo.bar'"
);
$users
=
$q
->
execute
();
$this
->
assertEqual
(
$users
->
count
(),
0
);
$this
->
assertEqual
(
$q
->
getQuery
(),
"SELECT entity.id AS entity__id FROM entity WHERE entity.name = 'foo.bar' AND (entity.type = 0)"
);
}
}
}
}
?>
?>
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