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
Hide 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
...
...
@@ -109,9 +109,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
public
function
setReference
(
Doctrine_Record
$record
,
Doctrine_Relation
$relation
)
{
$this
->
reference
=
$record
;
$this
->
relation
=
$relation
;
if
(
$relation
instanceof
Doctrine_ForeignKey
||
$relation
instanceof
Doctrine_LocalKey
)
{
$this
->
reference_field
=
$relation
->
getForeign
();
$value
=
$record
->
get
(
$relation
->
getLocal
());
...
...
@@ -221,7 +222,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if
(
!
isset
(
$offset
))
{
foreach
(
$coll
as
$record
)
{
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
);
}
...
...
classes/Query.class.php
View file @
4c582bec
...
...
@@ -356,6 +356,9 @@ class Doctrine_Query extends Doctrine_Access {
* @return Doctrine_Collection the root collection
*/
public
function
execute
(
$params
=
array
())
{
$this
->
data
=
array
();
$this
->
collections
=
array
();
switch
(
count
(
$this
->
tables
))
:
case
0
:
throw
new
DQLException
();
...
...
@@ -364,7 +367,7 @@ class Doctrine_Query extends Doctrine_Access {
$query
=
$this
->
getQuery
();
$keys
=
array_keys
(
$this
->
tables
);
$name
=
$this
->
tables
[
$keys
[
0
]]
->
getComponentName
();
$stmt
=
$this
->
session
->
execute
(
$query
,
$params
);
...
...
@@ -396,6 +399,7 @@ class Doctrine_Query extends Doctrine_Access {
$array
=
$this
->
parseData
(
$stmt
);
foreach
(
$array
as
$data
)
:
/**
...
...
@@ -405,7 +409,6 @@ class Doctrine_Query extends Doctrine_Access {
if
(
empty
(
$row
))
continue
;
$key
=
ucwords
(
$key
);
$name
=
$this
->
tables
[
$key
]
->
getComponentName
();
if
(
!
isset
(
$previd
[
$name
]))
...
...
@@ -417,15 +420,13 @@ class Doctrine_Query extends Doctrine_Access {
$record
=
$this
->
tables
[
$name
]
->
getRecord
();
if
(
$name
==
$root
)
{
$this
->
tables
[
$name
]
->
setData
(
$row
);
$record
=
$this
->
tables
[
$name
]
->
getRecord
();
$coll
->
add
(
$record
);
}
else
{
$last
=
$coll
->
getLast
();
if
(
!
$last
->
hasReference
(
$name
))
{
if
(
!
$last
->
hasReference
(
$name
))
$last
->
initReference
(
$this
->
getCollection
(
$name
),
$this
->
connectors
[
$name
]);
}
$last
->
addReference
(
$record
);
}
}
...
...
@@ -445,6 +446,11 @@ class Doctrine_Query extends Doctrine_Access {
*/
public
function
parseData
(
PDOStatement
$stmt
)
{
$array
=
array
();
$keys
=
array
();
foreach
(
array_keys
(
$this
->
tables
)
as
$key
)
{
$k
=
strtolower
(
$key
);
$keys
[
$k
]
=
$key
;
}
while
(
$data
=
$stmt
->
fetch
(
PDO
::
FETCH_ASSOC
))
:
/**
* parse the data into two-dimensional array
...
...
@@ -453,7 +459,7 @@ class Doctrine_Query extends Doctrine_Access {
$e
=
explode
(
"__"
,
$key
);
if
(
count
(
$e
)
>
1
)
{
$data
[
$
e
[
0
]][
$e
[
1
]]
=
$value
;
$data
[
$
keys
[
$e
[
0
]
]][
$e
[
1
]]
=
$value
;
}
else
{
$data
[
0
][
$e
[
0
]]
=
$value
;
}
...
...
@@ -810,6 +816,9 @@ class Doctrine_Query extends Doctrine_Access {
break
;
case
Doctrine_Relation
::
MANY_AGGREGATE
:
case
Doctrine_Relation
::
MANY_COMPOSITE
:
// subquery needed
$b
=
$fk
->
getTable
()
->
getComponentName
();
$graph
=
new
Doctrine_Query
(
$this
->
session
);
...
...
@@ -844,6 +853,8 @@ class Doctrine_Query extends Doctrine_Access {
}
}
else
{
$fk
=
$objTable
->
getForeignKey
(
$name
);
$name
=
$fk
->
getTable
()
->
getComponentName
();
$tname
=
$objTable
->
getTableName
();
$next
=
$fk
->
getTable
();
$tname2
=
$next
->
getTableName
();
...
...
@@ -886,6 +897,7 @@ class Doctrine_Query extends Doctrine_Access {
$objTable
=
$next
;
}
if
(
!
isset
(
$this
->
tables
[
$name
]))
{
$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
endswitch
;
}
}
if
(
$this
->
state
==
Doctrine_Record
::
STATE_TCLEAN
)
$this
->
state
=
Doctrine_Record
::
STATE_TDIRTY
;
$this
->
data
[
$name
]
=
$value
;
$this
->
modified
[]
=
$name
;
}
...
...
@@ -798,6 +802,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
/**
* hasRefence
* @param string $name
* @return boolean
*/
public
function
hasReference
(
$name
)
{
return
isset
(
$this
->
references
[
$name
]);
...
...
@@ -807,16 +812,20 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @param string $connectorField
*/
public
function
initReference
(
Doctrine_Collection
$coll
,
Doctrine_Relation
$connector
)
{
$name
=
$
coll
->
getTable
()
->
getComponentName
(
);
$name
=
$
this
->
table
->
getAlias
(
$coll
->
getTable
()
->
getComponentName
()
);
$coll
->
setReference
(
$this
,
$connector
);
$this
->
references
[
$name
]
=
$coll
;
$this
->
originals
[
$name
]
=
clone
$coll
;
}
/**
* addReference
* @param Doctrine_Record $record
* @param mixed $key
* @return void
*/
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
->
originals
[
$name
]
->
add
(
$record
,
$key
);
}
...
...
@@ -909,9 +918,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$id
=
$this
->
get
(
$local
);
$query
=
"FROM "
.
$table
->
getComponentName
()
.
" WHERE "
.
$table
->
getComponentName
()
.
"."
.
$fk
->
getForeign
()
.
" = ?"
;
$coll
=
$graph
->
query
(
$query
,
array
(
$id
));
$this
->
references
[
$name
]
=
$coll
;
$this
->
references
[
$name
]
->
setReference
(
$this
,
$fk
);
$this
->
references
[
$name
]
->
setReference
(
$this
,
$fk
);
$this
->
originals
[
$name
]
=
clone
$coll
;
...
...
classes/Table.class.php
View file @
4c582bec
...
...
@@ -400,6 +400,18 @@ class Doctrine_Table extends Doctrine_Configurable {
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
*
...
...
tests/CollectionTestCase.class.php
View file @
4c582bec
...
...
@@ -35,7 +35,7 @@ class Doctrine_CollectionTestCase extends Doctrine_UnitTestCase {
$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
());
...
...
tests/QueryTestCase.class.php
View file @
4c582bec
...
...
@@ -7,11 +7,16 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this
->
tables
[]
=
"Forum_Thread"
;
parent
::
prepareTables
();
}
public
function
testQueryWithComplexAliases
()
{
$board
=
new
Forum_Board
();
$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
();
$this
->
assertTrue
(
$entry
->
getTable
()
->
getForeignKey
(
"Thread"
)
instanceof
Doctrine_LocalKey
);
...
...
@@ -22,22 +27,35 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$board
->
name
,
"Doctrine Forum"
);
$this
->
assertEqual
(
$board
->
Category
->
name
,
"General discussion"
);
$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
);
//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
();
/**
$board
->
getTable
()
->
clear
();
$board
=
$board
->
getTable
()
->
find
(
$board
->
getID
());
$this
->
assertEqual
(
$board
->
Threads
->
count
(),
1
);
$this
->
assertEqual
(
$board
->
name
,
"Doctrine Forum"
);
$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
->
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
()
{
...
...
@@ -306,5 +324,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this
->
assertTrue
(
isset
(
$values
[
'users'
]));
$this
->
assertTrue
(
isset
(
$values
[
'max'
]));
}
}
?>
tests/classes.php
View file @
4c582bec
...
...
@@ -207,7 +207,7 @@ class Forum_Thread extends Doctrine_Record {
}
public
function
setUp
()
{
$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);
$test
=
new
GroupTest
(
"Doctrine Framework Unit Tests"
);
$test
->
addTestCase
(
new
Doctrine_SessionTestCase
());
$test
->
addTestCase
(
new
Doctrine_TableTestCase
());
...
...
@@ -42,12 +41,12 @@ $test->addTestCase(new Doctrine_BatchIteratorTestCase());
$test
->
addTestCase
(
new
Doctrine_ConfigurableTestCase
());
$test
->
addTestCase
(
new
Doctrine_CollectionTestCase
());
$test
->
addTestCase
(
new
Doctrine_Collection_OffsetTestCase
());
$test
->
addTestCase
(
new
Sensei_UnitTestCase
());
$test
->
addTestCase
(
new
Doctrine_CollectionTestCase
());
$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