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
1dfbc5b0
Commit
1dfbc5b0
authored
Mar 01, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed the handling of aliases within DQL DELETE and UPDATE queries
parent
9b525f34
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
89 additions
and
46 deletions
+89
-46
Hydrate.php
lib/Doctrine/Hydrate.php
+59
-3
Query.php
lib/Doctrine/Query.php
+2
-30
Set.php
lib/Doctrine/Query/Set.php
+2
-2
Where.php
lib/Doctrine/Query/Where.php
+8
-2
DeleteTestCase.php
tests/Query/DeleteTestCase.php
+2
-2
UpdateTestCase.php
tests/Query/UpdateTestCase.php
+11
-4
run.php
tests/run.php
+5
-3
No files found.
lib/Doctrine/Hydrate.php
View file @
1dfbc5b0
...
...
@@ -34,6 +34,30 @@ Doctrine::autoload('Doctrine_Access');
*/
abstract
class
Doctrine_Hydrate
extends
Doctrine_Access
{
/**
* QUERY TYPE CONSTANTS
*/
/**
* constant for SELECT queries
*/
const
SELECT
=
0
;
/**
* constant for DELETE queries
*/
const
DELETE
=
1
;
/**
* constant for UPDATE queries
*/
const
UPDATE
=
2
;
/**
* constant for INSERT queries
*/
const
INSERT
=
3
;
/**
* constant for CREATE queries
*/
const
CREATE
=
4
;
/**
* @var array $fetchmodes an array containing all fetchmodes
*/
...
...
@@ -109,6 +133,12 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
'limit'
=>
false
,
'offset'
=>
false
,
);
/**
* @var integer $type the query type
*
* @see Doctrine_Query::* constants
*/
protected
$type
=
self
::
SELECT
;
/**
* constructor
*
...
...
@@ -605,6 +635,24 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
}
return
false
;
}
/**
* getType
*
* returns the type of this query object
* by default the type is Doctrine_Hydrate::SELECT but if update() or delete()
* are being called the type is Doctrine_Hydrate::UPDATE and Doctrine_Hydrate::DELETE,
* respectively
*
* @see Doctrine_Hydrate::SELECT
* @see Doctrine_Hydrate::UPDATE
* @see Doctrine_Hydrate::DELETE
*
* @return integer return the query type
*/
public
function
getType
()
{
return
$this
->
type
;
}
/**
* applyInheritance
* applies column aggregation inheritance to DQL / SQL query
...
...
@@ -627,14 +675,22 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
$index
=
0
;
foreach
(
$array
as
$tableAlias
=>
$maps
)
{
$a
=
array
();
// don't use table aliases if the query isn't a select query
if
(
$this
->
type
!==
Doctrine_Query
::
SELECT
)
{
$tableAlias
=
''
;
}
else
{
$tableAlias
.=
'.'
;
}
foreach
(
$maps
as
$map
)
{
$b
=
array
();
foreach
(
$map
as
$field
=>
$value
)
{
if
(
$index
>
0
)
{
$b
[]
=
'('
.
$tableAlias
.
'.'
.
$field
.
' = '
.
$value
.
' OR '
.
$tableAlias
.
'.'
.
$field
.
' IS NULL)'
;
$b
[]
=
'('
.
$tableAlias
.
$field
.
' = '
.
$value
.
' OR '
.
$tableAlias
.
$field
.
' IS NULL)'
;
}
else
{
$b
[]
=
$tableAlias
.
'.'
.
$field
.
' = '
.
$value
;
$b
[]
=
$tableAlias
.
$field
.
' = '
.
$value
;
}
}
...
...
lib/Doctrine/Query.php
View file @
1dfbc5b0
...
...
@@ -31,30 +31,6 @@ Doctrine::autoload('Doctrine_Hydrate');
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class
Doctrine_Query
extends
Doctrine_Hydrate
implements
Countable
{
/**
* QUERY TYPE CONSTANTS
*/
/**
* constant for SELECT queries
*/
const
SELECT
=
0
;
/**
* constant for DELETE queries
*/
const
DELETE
=
1
;
/**
* constant for UPDATE queries
*/
const
UPDATE
=
2
;
/**
* constant for INSERT queries
*/
const
INSERT
=
3
;
/**
* constant for CREATE queries
*/
const
CREATE
=
4
;
/**
* @param array $subqueryAliases the table aliases needed in some LIMIT subqueries
*/
...
...
@@ -87,12 +63,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
*/
private
$pendingFields
=
array
();
/**
* @var integer $type the query type
*
* @see Doctrine_Query::* constants
*/
protected
$type
=
self
::
SELECT
;
/**
* create
...
...
@@ -126,6 +97,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
$this
->
isSubquery
=
(
bool
)
$bool
;
return
$this
;
}
/**
* getAggregateAlias
*
...
...
lib/Doctrine/Query/Set.php
View file @
1dfbc5b0
...
...
@@ -46,9 +46,9 @@ class Doctrine_Query_Set extends Doctrine_Query_Part
$reference
=
implode
(
'.'
,
$e
);
$alias
=
$this
->
query
->
getTableAlias
(
$reference
);
$table
=
$this
->
query
->
getTable
(
$alias
);
$fieldname
=
$alias
?
$alias
.
'.'
.
$field
:
$field
;
$result
[]
=
$fieldname
.
' = '
.
$set
[
1
];
$result
[]
=
$table
->
getColumnName
(
$field
)
.
' = '
.
$set
[
1
];
}
return
implode
(
', '
,
$result
);
...
...
lib/Doctrine/Query/Where.php
View file @
1dfbc5b0
...
...
@@ -132,7 +132,7 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
$trimmed
=
Doctrine_Query
::
bracketTrim
(
$value
);
if
(
substr
(
$trimmed
,
0
,
4
)
==
'FROM'
||
substr
(
$trimmed
,
0
,
6
)
==
'SELECT'
)
{
// subquery found
$q
=
new
Doctrine_Query
();
$value
=
'('
.
$q
->
isSubquery
(
true
)
->
parseQuery
(
$trimmed
)
->
getQuery
()
.
')'
;
...
...
@@ -171,7 +171,13 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
$value
=
$enumIndex
;
}
default
:
$fieldname
=
$alias
?
$alias
.
'.'
.
$field
:
$field
;
if
(
$this
->
query
->
getType
()
===
Doctrine_Query
::
SELECT
)
{
$fieldname
=
$alias
?
$alias
.
'.'
.
$field
:
$field
;
}
else
{
$fieldname
=
$field
;
}
$where
=
$fieldname
.
' '
.
$operator
.
' '
.
$value
;
}
...
...
tests/Query/DeleteTestCase.php
View file @
1dfbc5b0
...
...
@@ -5,13 +5,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase {
$q
->
parseQuery
(
'DELETE FROM User'
);
$this
->
assertEqual
(
$q
->
getQuery
(),
'DELETE FROM entity WHERE (
e.
type = 0)'
);
$this
->
assertEqual
(
$q
->
getQuery
(),
'DELETE FROM entity WHERE (type = 0)'
);
$q
=
new
Doctrine_Query
();
$q
->
delete
()
->
from
(
'User'
);
$this
->
assertEqual
(
$q
->
getQuery
(),
'DELETE FROM entity WHERE (
e.
type = 0)'
);
$this
->
assertEqual
(
$q
->
getQuery
(),
'DELETE FROM entity WHERE (type = 0)'
);
}
public
function
testDeleteAll
()
{
$q
=
new
Doctrine_Query
();
...
...
tests/Query/UpdateTestCase.php
View file @
1dfbc5b0
...
...
@@ -5,26 +5,33 @@ class Doctrine_Query_Update_TestCase extends Doctrine_UnitTestCase {
$q
->
parseQuery
(
"UPDATE User u SET u.name = 'someone'"
);
$this
->
assertEqual
(
$q
->
getQuery
(),
"UPDATE entity
e SET e.name = 'someone' WHERE (e.
type = 0)"
);
$this
->
assertEqual
(
$q
->
getQuery
(),
"UPDATE entity
SET name = 'someone' WHERE (
type = 0)"
);
$q
=
new
Doctrine_Query
();
$q
->
update
(
'User u'
)
->
set
(
'u.name'
,
"'someone'"
);
$this
->
assertEqual
(
$q
->
getQuery
(),
"UPDATE entity
e SET e.name = 'someone' WHERE (e.
type = 0)"
);
$this
->
assertEqual
(
$q
->
getQuery
(),
"UPDATE entity
SET name = 'someone' WHERE (
type = 0)"
);
}
public
function
testUpdateWorksWithMultipleColumns
()
{
$q
=
new
Doctrine_Query
();
$q
->
parseQuery
(
"UPDATE User u SET u.name = 'someone', u.email_id = 5"
);
$this
->
assertEqual
(
$q
->
getQuery
(),
"UPDATE entity
e SET e.name = 'someone', e.email_id = 5 WHERE (e.
type = 0)"
);
$this
->
assertEqual
(
$q
->
getQuery
(),
"UPDATE entity
SET name = 'someone', email_id = 5 WHERE (
type = 0)"
);
$q
=
new
Doctrine_Query
();
$q
->
update
(
'User u'
)
->
set
(
'u.name'
,
"'someone'"
)
->
set
(
'u.email_id'
,
5
);
$this
->
assertEqual
(
$q
->
getQuery
(),
"UPDATE entity e SET e.name = 'someone', e.email_id = 5 WHERE (e.type = 0)"
);
$this
->
assertEqual
(
$q
->
getQuery
(),
"UPDATE entity SET name = 'someone', email_id = 5 WHERE (type = 0)"
);
}
public
function
testUpdateSupportsConditions
()
{
$q
=
new
Doctrine_Query
();
$q
->
parseQuery
(
"UPDATE User u SET u.name = 'someone' WHERE u.id = 5"
);
$this
->
assertEqual
(
$q
->
getQuery
(),
"UPDATE entity SET name = 'someone' WHERE id = 5 AND (type = 0)"
);
}
}
?>
tests/run.php
View file @
1dfbc5b0
...
...
@@ -62,7 +62,7 @@ $test = new GroupTest('Doctrine Framework Unit Tests');
// DATABASE ABSTRACTION tests
/**
// Connection drivers (not yet fully tested)
$test->addTestCase(new Doctrine_Connection_Pgsql_TestCase());
$test->addTestCase(new Doctrine_Connection_Oracle_TestCase());
...
...
@@ -196,7 +196,7 @@ $test->addTestCase(new Doctrine_CustomResultSetOrderTestCase());
//$test->addTestCase(new Doctrine_Collection_Offset_TestCase());
// Query tests
// Query tests
*/
$test
->
addTestCase
(
new
Doctrine_Query_MultiJoin_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_ReferenceModel_TestCase
());
...
...
@@ -205,7 +205,7 @@ $test->addTestCase(new Doctrine_Query_ComponentAlias_TestCase());
$test
->
addTestCase
(
new
Doctrine_Query_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_ShortAliases_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_Delete_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_Where_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_Limit_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_IdentifierQuoting_TestCase
());
...
...
@@ -229,6 +229,8 @@ $test->addTestCase(new Doctrine_Cache_Apc_TestCase());
$test
->
addTestCase
(
new
Doctrine_Cache_Memcache_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Cache_Sqlite_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_Delete_TestCase
());
// Cache tests
//$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
...
...
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