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
4c582bec
Commit
4c582bec
authored
May 19, 2006
by
doctrine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DQL with aliases bug fixed
parent
55f40e6e
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
78 additions
and
26 deletions
+78
-26
Collection.class.php
classes/Collection.class.php
+3
-2
Query.class.php
classes/Query.class.php
+19
-7
Record.class.php
classes/Record.class.php
+13
-4
Table.class.php
classes/Table.class.php
+12
-0
CollectionTestCase.class.php
tests/CollectionTestCase.class.php
+1
-1
QueryTestCase.class.php
tests/QueryTestCase.class.php
+27
-8
classes.php
tests/classes.php
+1
-1
run.php
tests/run.php
+2
-3
No files found.
classes/Collection.class.php
View file @
4c582bec
...
@@ -112,6 +112,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
...
@@ -112,6 +112,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if
(
$relation
instanceof
Doctrine_ForeignKey
||
if
(
$relation
instanceof
Doctrine_ForeignKey
||
$relation
instanceof
Doctrine_LocalKey
)
{
$relation
instanceof
Doctrine_LocalKey
)
{
$this
->
reference_field
=
$relation
->
getForeign
();
$this
->
reference_field
=
$relation
->
getForeign
();
$value
=
$record
->
get
(
$relation
->
getLocal
());
$value
=
$record
->
get
(
$relation
->
getLocal
());
...
@@ -221,7 +222,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
...
@@ -221,7 +222,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if
(
!
isset
(
$offset
))
{
if
(
!
isset
(
$offset
))
{
foreach
(
$coll
as
$record
)
{
foreach
(
$coll
as
$record
)
{
if
(
isset
(
$this
->
reference_field
))
if
(
isset
(
$this
->
reference_field
))
$record
->
s
et
(
$this
->
reference_field
,
$this
->
reference
);
$record
->
rawS
et
(
$this
->
reference_field
,
$this
->
reference
);
$this
->
reference
->
addReference
(
$record
);
$this
->
reference
->
addReference
(
$record
);
}
}
...
...
classes/Query.class.php
View file @
4c582bec
...
@@ -356,6 +356,9 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -356,6 +356,9 @@ class Doctrine_Query extends Doctrine_Access {
* @return Doctrine_Collection the root collection
* @return Doctrine_Collection the root collection
*/
*/
public
function
execute
(
$params
=
array
())
{
public
function
execute
(
$params
=
array
())
{
$this
->
data
=
array
();
$this
->
collections
=
array
();
switch
(
count
(
$this
->
tables
))
:
switch
(
count
(
$this
->
tables
))
:
case
0
:
case
0
:
throw
new
DQLException
();
throw
new
DQLException
();
...
@@ -396,6 +399,7 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -396,6 +399,7 @@ class Doctrine_Query extends Doctrine_Access {
$array
=
$this
->
parseData
(
$stmt
);
$array
=
$this
->
parseData
(
$stmt
);
foreach
(
$array
as
$data
)
:
foreach
(
$array
as
$data
)
:
/**
/**
...
@@ -405,7 +409,6 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -405,7 +409,6 @@ class Doctrine_Query extends Doctrine_Access {
if
(
empty
(
$row
))
if
(
empty
(
$row
))
continue
;
continue
;
$key
=
ucwords
(
$key
);
$name
=
$this
->
tables
[
$key
]
->
getComponentName
();
$name
=
$this
->
tables
[
$key
]
->
getComponentName
();
if
(
!
isset
(
$previd
[
$name
]))
if
(
!
isset
(
$previd
[
$name
]))
...
@@ -417,15 +420,13 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -417,15 +420,13 @@ class Doctrine_Query extends Doctrine_Access {
$record
=
$this
->
tables
[
$name
]
->
getRecord
();
$record
=
$this
->
tables
[
$name
]
->
getRecord
();
if
(
$name
==
$root
)
{
if
(
$name
==
$root
)
{
$this
->
tables
[
$name
]
->
setData
(
$row
);
$record
=
$this
->
tables
[
$name
]
->
getRecord
();
$coll
->
add
(
$record
);
$coll
->
add
(
$record
);
}
else
{
}
else
{
$last
=
$coll
->
getLast
();
$last
=
$coll
->
getLast
();
if
(
!
$last
->
hasReference
(
$name
))
{
if
(
!
$last
->
hasReference
(
$name
))
$last
->
initReference
(
$this
->
getCollection
(
$name
),
$this
->
connectors
[
$name
]);
$last
->
initReference
(
$this
->
getCollection
(
$name
),
$this
->
connectors
[
$name
]);
}
$last
->
addReference
(
$record
);
$last
->
addReference
(
$record
);
}
}
}
}
...
@@ -445,6 +446,11 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -445,6 +446,11 @@ class Doctrine_Query extends Doctrine_Access {
*/
*/
public
function
parseData
(
PDOStatement
$stmt
)
{
public
function
parseData
(
PDOStatement
$stmt
)
{
$array
=
array
();
$array
=
array
();
$keys
=
array
();
foreach
(
array_keys
(
$this
->
tables
)
as
$key
)
{
$k
=
strtolower
(
$key
);
$keys
[
$k
]
=
$key
;
}
while
(
$data
=
$stmt
->
fetch
(
PDO
::
FETCH_ASSOC
))
:
while
(
$data
=
$stmt
->
fetch
(
PDO
::
FETCH_ASSOC
))
:
/**
/**
* parse the data into two-dimensional array
* parse the data into two-dimensional array
...
@@ -453,7 +459,7 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -453,7 +459,7 @@ class Doctrine_Query extends Doctrine_Access {
$e
=
explode
(
"__"
,
$key
);
$e
=
explode
(
"__"
,
$key
);
if
(
count
(
$e
)
>
1
)
{
if
(
count
(
$e
)
>
1
)
{
$data
[
$
e
[
0
]][
$e
[
1
]]
=
$value
;
$data
[
$
keys
[
$e
[
0
]
]][
$e
[
1
]]
=
$value
;
}
else
{
}
else
{
$data
[
0
][
$e
[
0
]]
=
$value
;
$data
[
0
][
$e
[
0
]]
=
$value
;
}
}
...
@@ -810,6 +816,9 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -810,6 +816,9 @@ class Doctrine_Query extends Doctrine_Access {
break
;
break
;
case
Doctrine_Relation
::
MANY_AGGREGATE
:
case
Doctrine_Relation
::
MANY_AGGREGATE
:
case
Doctrine_Relation
::
MANY_COMPOSITE
:
case
Doctrine_Relation
::
MANY_COMPOSITE
:
// subquery needed
$b
=
$fk
->
getTable
()
->
getComponentName
();
$b
=
$fk
->
getTable
()
->
getComponentName
();
$graph
=
new
Doctrine_Query
(
$this
->
session
);
$graph
=
new
Doctrine_Query
(
$this
->
session
);
...
@@ -844,6 +853,8 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -844,6 +853,8 @@ class Doctrine_Query extends Doctrine_Access {
}
}
}
else
{
}
else
{
$fk
=
$objTable
->
getForeignKey
(
$name
);
$fk
=
$objTable
->
getForeignKey
(
$name
);
$name
=
$fk
->
getTable
()
->
getComponentName
();
$tname
=
$objTable
->
getTableName
();
$tname
=
$objTable
->
getTableName
();
$next
=
$fk
->
getTable
();
$next
=
$fk
->
getTable
();
$tname2
=
$next
->
getTableName
();
$tname2
=
$next
->
getTableName
();
...
@@ -886,6 +897,7 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -886,6 +897,7 @@ class Doctrine_Query extends Doctrine_Access {
$objTable
=
$next
;
$objTable
=
$next
;
}
}
if
(
!
isset
(
$this
->
tables
[
$name
]))
{
if
(
!
isset
(
$this
->
tables
[
$name
]))
{
$this
->
tables
[
$name
]
=
$objTable
;
$this
->
tables
[
$name
]
=
$objTable
;
}
}
...
...
classes/Record.class.php
View file @
4c582bec
...
@@ -442,6 +442,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -442,6 +442,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
endswitch
;
endswitch
;
}
}
}
}
if
(
$this
->
state
==
Doctrine_Record
::
STATE_TCLEAN
)
$this
->
state
=
Doctrine_Record
::
STATE_TDIRTY
;
$this
->
data
[
$name
]
=
$value
;
$this
->
data
[
$name
]
=
$value
;
$this
->
modified
[]
=
$name
;
$this
->
modified
[]
=
$name
;
}
}
...
@@ -798,6 +802,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -798,6 +802,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
/**
/**
* hasRefence
* hasRefence
* @param string $name
* @param string $name
* @return boolean
*/
*/
public
function
hasReference
(
$name
)
{
public
function
hasReference
(
$name
)
{
return
isset
(
$this
->
references
[
$name
]);
return
isset
(
$this
->
references
[
$name
]);
...
@@ -807,16 +812,20 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -807,16 +812,20 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @param string $connectorField
* @param string $connectorField
*/
*/
public
function
initReference
(
Doctrine_Collection
$coll
,
Doctrine_Relation
$connector
)
{
public
function
initReference
(
Doctrine_Collection
$coll
,
Doctrine_Relation
$connector
)
{
$name
=
$
coll
->
getTable
()
->
getComponentName
(
);
$name
=
$
this
->
table
->
getAlias
(
$coll
->
getTable
()
->
getComponentName
()
);
$coll
->
setReference
(
$this
,
$connector
);
$coll
->
setReference
(
$this
,
$connector
);
$this
->
references
[
$name
]
=
$coll
;
$this
->
references
[
$name
]
=
$coll
;
$this
->
originals
[
$name
]
=
clone
$coll
;
$this
->
originals
[
$name
]
=
clone
$coll
;
}
}
/**
/**
* addReference
* addReference
* @param Doctrine_Record $record
* @param mixed $key
* @return void
*/
*/
public
function
addReference
(
Doctrine_Record
$record
,
$key
=
null
)
{
public
function
addReference
(
Doctrine_Record
$record
,
$key
=
null
)
{
$name
=
$record
->
getTable
()
->
getComponentName
();
$name
=
$this
->
table
->
getAlias
(
$record
->
getTable
()
->
getComponentName
());
$this
->
references
[
$name
]
->
add
(
$record
,
$key
);
$this
->
references
[
$name
]
->
add
(
$record
,
$key
);
$this
->
originals
[
$name
]
->
add
(
$record
,
$key
);
$this
->
originals
[
$name
]
->
add
(
$record
,
$key
);
}
}
...
@@ -911,7 +920,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -911,7 +920,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$coll
=
$graph
->
query
(
$query
,
array
(
$id
));
$coll
=
$graph
->
query
(
$query
,
array
(
$id
));
$this
->
references
[
$name
]
=
$coll
;
$this
->
references
[
$name
]
=
$coll
;
$this
->
references
[
$name
]
->
setReference
(
$this
,
$fk
);
$this
->
references
[
$name
]
->
setReference
(
$this
,
$fk
);
$this
->
originals
[
$name
]
=
clone
$coll
;
$this
->
originals
[
$name
]
=
clone
$coll
;
...
...
classes/Table.class.php
View file @
4c582bec
...
@@ -400,6 +400,18 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -400,6 +400,18 @@ class Doctrine_Table extends Doctrine_Configurable {
return
$name
;
return
$name
;
}
}
/**
* returns component name for given alias
*
* @param string $alias
* @return string
*/
final
public
function
getAliasName
(
$alias
)
{
if
(
$name
=
array_search
(
$this
->
boundAliases
,
$alias
))
return
$name
;
throw
new
InvalidKeyException
();
}
/**
/**
* unbinds all relations
* unbinds all relations
*
*
...
...
tests/CollectionTestCase.class.php
View file @
4c582bec
...
@@ -35,7 +35,7 @@ class Doctrine_CollectionTestCase extends Doctrine_UnitTestCase {
...
@@ -35,7 +35,7 @@ class Doctrine_CollectionTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
count
(
$coll
),
3
);
$this
->
assertEqual
(
count
(
$coll
),
3
);
//
$this->assertEqual($coll[2]->getState(), Doctrine_Record::STATE_PROXY);
$this
->
assertEqual
(
$coll
[
2
]
->
getState
(),
Doctrine_Record
::
STATE_PROXY
);
$generator
=
new
Doctrine_IndexGenerator
(
$this
->
objTable
->
getIdentifier
());
$generator
=
new
Doctrine_IndexGenerator
(
$this
->
objTable
->
getIdentifier
());
...
...
tests/QueryTestCase.class.php
View file @
4c582bec
...
@@ -7,11 +7,16 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
...
@@ -7,11 +7,16 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this
->
tables
[]
=
"Forum_Thread"
;
$this
->
tables
[]
=
"Forum_Thread"
;
parent
::
prepareTables
();
parent
::
prepareTables
();
}
}
public
function
testQueryWithComplexAliases
()
{
public
function
testQueryWithComplexAliases
()
{
$board
=
new
Forum_Board
();
$board
=
new
Forum_Board
();
$table
=
$board
->
getTable
();
$table
=
$board
->
getTable
();
$this
->
assertTrue
(
$table
->
getForeignKey
(
"Threads"
)
instanceof
Doctrine_ForeignKey
);
$fk
=
$table
->
getForeignKey
(
"Threads"
);
$this
->
assertEqual
(
$table
->
getComponentName
(),
"Forum_Board"
);
$this
->
assertTrue
(
$fk
instanceof
Doctrine_ForeignKey
);
$this
->
assertEqual
(
$fk
->
getTable
()
->
getComponentName
(),
"Forum_Thread"
);
$entry
=
new
Forum_Entry
();
$entry
=
new
Forum_Entry
();
$this
->
assertTrue
(
$entry
->
getTable
()
->
getForeignKey
(
"Thread"
)
instanceof
Doctrine_LocalKey
);
$this
->
assertTrue
(
$entry
->
getTable
()
->
getForeignKey
(
"Thread"
)
instanceof
Doctrine_LocalKey
);
...
@@ -22,22 +27,35 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
...
@@ -22,22 +27,35 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$board
->
name
,
"Doctrine Forum"
);
$this
->
assertEqual
(
$board
->
name
,
"Doctrine Forum"
);
$this
->
assertEqual
(
$board
->
Category
->
name
,
"General discussion"
);
$this
->
assertEqual
(
$board
->
Category
->
name
,
"General discussion"
);
$this
->
assertEqual
(
$board
->
Category
->
getState
(),
Doctrine_Record
::
STATE_TDIRTY
);
$this
->
assertEqual
(
$board
->
Category
->
getState
(),
Doctrine_Record
::
STATE_TDIRTY
);
//
$this->assertEqual($board->Threads[0]->getState(), Doctrine_Record::STATE_TDIRTY);
$this
->
assertEqual
(
$board
->
Threads
[
0
]
->
getState
(),
Doctrine_Record
::
STATE_TDIRTY
);
$this
->
assertTrue
(
$board
->
Threads
[
0
]
instanceof
Forum_Thread
);
$this
->
assertTrue
(
$board
->
Threads
[
0
]
instanceof
Forum_Thread
);
//print_r($this->session->buildFlushTree());
$thread
=
$board
->
Threads
[
0
];
$thread
->
Entries
[
0
]
->
topic
=
"My first topic"
;
$this
->
assertEqual
(
$thread
->
Entries
[
0
]
->
topic
,
"My first topic"
);
$this
->
assertEqual
(
$thread
->
Entries
[
0
]
->
getState
(),
Doctrine_Record
::
STATE_TDIRTY
);
$this
->
assertTrue
(
$thread
->
Entries
[
0
]
instanceof
Forum_Entry
);
$this
->
session
->
flush
();
$this
->
session
->
flush
();
/**
$board
->
getTable
()
->
clear
();
$board
->
getTable
()
->
clear
();
$board
=
$board
->
getTable
()
->
find
(
$board
->
getID
());
$board
=
$board
->
getTable
()
->
find
(
$board
->
getID
());
$this
->
assertEqual
(
$board
->
Threads
->
count
(),
1
);
$this
->
assertEqual
(
$board
->
Threads
->
count
(),
1
);
$this
->
assertEqual
(
$board
->
name
,
"Doctrine Forum"
);
$this
->
assertEqual
(
$board
->
name
,
"Doctrine Forum"
);
$this
->
assertEqual
(
$board
->
Category
->
name
,
"General discussion"
);
$this
->
assertEqual
(
$board
->
Category
->
name
,
"General discussion"
);
$this->assertEqual($board->Category->getState(), Doctrine_Record::STATE_
TDIRTY
);
$this
->
assertEqual
(
$board
->
Category
->
getState
(),
Doctrine_Record
::
STATE_
CLEAN
);
$this
->
assertEqual
(
$board
->
Threads
[
0
]
->
getState
(),
Doctrine_Record
::
STATE_CLEAN
);
$this
->
assertEqual
(
$board
->
Threads
[
0
]
->
getState
(),
Doctrine_Record
::
STATE_CLEAN
);
$this
->
assertTrue
(
$board
->
Threads
[
0
]
instanceof
Forum_Thread
);
$this
->
assertTrue
(
$board
->
Threads
[
0
]
instanceof
Forum_Thread
);
*/
$q
=
new
Doctrine_Query
(
$this
->
session
);
$q
->
from
(
"Forum_Board"
);
$coll
=
$q
->
execute
();
$this
->
assertEqual
(
$coll
->
count
(),
1
);
$q
->
from
(
"Forum_Board, Forum_Board.Threads"
);
$coll
=
$q
->
execute
();
$this
->
assertEqual
(
$coll
->
count
(),
1
);
}
}
public
function
testQueryWithAliases
()
{
public
function
testQueryWithAliases
()
{
...
@@ -306,5 +324,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
...
@@ -306,5 +324,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this
->
assertTrue
(
isset
(
$values
[
'users'
]));
$this
->
assertTrue
(
isset
(
$values
[
'users'
]));
$this
->
assertTrue
(
isset
(
$values
[
'max'
]));
$this
->
assertTrue
(
isset
(
$values
[
'max'
]));
}
}
}
}
?>
?>
tests/classes.php
View file @
4c582bec
...
@@ -207,7 +207,7 @@ class Forum_Thread extends Doctrine_Record {
...
@@ -207,7 +207,7 @@ class Forum_Thread extends Doctrine_Record {
}
}
public
function
setUp
()
{
public
function
setUp
()
{
$this
->
hasOne
(
"Forum_Board as Board"
,
"Forum_Thread.board_id"
);
$this
->
hasOne
(
"Forum_Board as Board"
,
"Forum_Thread.board_id"
);
$this
->
ownsMany
(
"Forum_Entry as Entr
y
"
,
"Forum_Entry.thread_id"
);
$this
->
ownsMany
(
"Forum_Entry as Entr
ies
"
,
"Forum_Entry.thread_id"
);
}
}
}
}
...
...
tests/run.php
View file @
4c582bec
...
@@ -23,7 +23,6 @@ error_reporting(E_ALL);
...
@@ -23,7 +23,6 @@ error_reporting(E_ALL);
$test
=
new
GroupTest
(
"Doctrine Framework Unit Tests"
);
$test
=
new
GroupTest
(
"Doctrine Framework Unit Tests"
);
$test
->
addTestCase
(
new
Doctrine_SessionTestCase
());
$test
->
addTestCase
(
new
Doctrine_SessionTestCase
());
$test
->
addTestCase
(
new
Doctrine_TableTestCase
());
$test
->
addTestCase
(
new
Doctrine_TableTestCase
());
...
@@ -42,12 +41,12 @@ $test->addTestCase(new Doctrine_BatchIteratorTestCase());
...
@@ -42,12 +41,12 @@ $test->addTestCase(new Doctrine_BatchIteratorTestCase());
$test
->
addTestCase
(
new
Doctrine_ConfigurableTestCase
());
$test
->
addTestCase
(
new
Doctrine_ConfigurableTestCase
());
$test
->
addTestCase
(
new
Doctrine_CollectionTestCase
());
$test
->
addTestCase
(
new
Doctrine_Collection_OffsetTestCase
());
$test
->
addTestCase
(
new
Doctrine_Collection_OffsetTestCase
());
$test
->
addTestCase
(
new
Sensei_UnitTestCase
());
$test
->
addTestCase
(
new
Sensei_UnitTestCase
());
$test
->
addTestCase
(
new
Doctrine_CollectionTestCase
());
$test
->
addTestCase
(
new
Doctrine_QueryTestCase
());
$test
->
addTestCase
(
new
Doctrine_QueryTestCase
());
...
...
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