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
20990ed2
Commit
20990ed2
authored
May 29, 2006
by
doctrine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DQL: direct one-to-one relation fetching bug fixed
parent
e15cfd70
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
197 additions
and
87 deletions
+197
-87
Batch.class.php
classes/Collection/Batch.class.php
+8
-3
IndexGenerator.php
classes/IndexGenerator.php
+1
-1
Query.class.php
classes/Query.class.php
+24
-9
Record.class.php
classes/Record.class.php
+38
-7
Sensei.class.php
classes/Sensei/Sensei.class.php
+2
-7
Session.class.php
classes/Session.class.php
+0
-40
Table.class.php
classes/Table.class.php
+7
-1
Nospace.class.php
classes/Validator/Nospace.class.php
+1
-1
QueryTestCase.class.php
tests/QueryTestCase.class.php
+61
-14
SenseiTestCase.class.php
tests/SenseiTestCase.class.php
+5
-2
UnitTestCase.class.php
tests/UnitTestCase.class.php
+1
-0
classes.php
tests/classes.php
+49
-0
run.php
tests/run.php
+0
-2
No files found.
classes/Collection/Batch.class.php
View file @
20990ed2
...
...
@@ -28,6 +28,7 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
/**
* @param integer $batchSize batch size
* @return boolean
*/
public
function
setBatchSize
(
$batchSize
)
{
$batchSize
=
(
int
)
$batchSize
;
...
...
@@ -38,14 +39,18 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
return
true
;
}
/**
* returns the batch size of this collection
*
* @return integer
*/
public
function
getBatchSize
()
{
return
$this
->
batchSize
;
}
/**
* load load a specified element, by loading the batch the element is part of
* @param Doctrine_Record $record data access object
* load
* loads a specified element, by loading the batch the element is part of
*
* @param Doctrine_Record $record record to be loaded
* @return boolean whether or not the load operation was successful
*/
public
function
load
(
Doctrine_Record
$record
)
{
...
...
classes/IndexGenerator.php
View file @
20990ed2
classes/Query.class.php
View file @
20990ed2
...
...
@@ -421,7 +421,6 @@ class Doctrine_Query extends Doctrine_Access {
$colls
=
array
();
foreach
(
$array
as
$data
)
{
/**
* remove duplicated data rows and map data into objects
...
...
@@ -466,6 +465,21 @@ class Doctrine_Query extends Doctrine_Access {
}
else
{
$pointer
=
$this
->
joins
[
$name
];
$fk
=
$this
->
tables
[
$pointer
]
->
getForeignKey
(
$this
->
tables
[
$pointer
]
->
getAlias
(
$name
));
switch
(
$fk
->
getType
())
:
case
Doctrine_Relation
::
ONE_COMPOSITE
:
case
Doctrine_Relation
::
ONE_AGGREGATE
:
$last
=
$prev
[
$pointer
]
->
getLast
();
$last
->
rawSet
(
$this
->
connectors
[
$name
]
->
getLocal
(),
$record
->
getID
());
$last
->
initSingleReference
(
$record
);
$prev
[
$name
]
=
$record
;
break
;
default
:
// one-to-many relation or many-to-many relation
$last
=
$prev
[
$pointer
]
->
getLast
();
if
(
!
$last
->
hasReference
(
$name
))
{
...
...
@@ -473,6 +487,7 @@ class Doctrine_Query extends Doctrine_Access {
$last
->
initReference
(
$prev
[
$name
],
$this
->
connectors
[
$name
]);
}
$last
->
addReference
(
$record
);
endswitch
;
}
}
...
...
classes/Record.class.php
View file @
20990ed2
...
...
@@ -83,6 +83,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @var integer $index this index is used for creating object identifiers
*/
private
static
$index
=
1
;
/**
* @var Doctrine_Null $nullObject a Doctrine_Null object used for SQL null value testing
*/
private
static
$nullObject
;
/**
* @var integer $oid object identifier
*/
...
...
@@ -157,6 +161,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this
->
table
->
getRepository
()
->
add
(
$this
);
}
}
/**
* initNullObject
*/
public
static
function
initNullObject
()
{
self
::
$nullObject
=
new
Doctrine_Null
;
}
/**
* setUp
* implemented by child classes
...
...
@@ -582,11 +592,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this
->
table
->
getSession
()
->
save
(
$this
);
foreach
(
$saveLater
as
$fk
)
{
$table
=
$fk
->
getTable
();
$foreign
=
$fk
->
getForeign
();
$local
=
$fk
->
getLocal
();
$alias
=
$this
->
table
->
getAlias
(
$table
->
getComponentName
());
if
(
isset
(
$this
->
references
[
$alias
]))
{
...
...
@@ -836,6 +842,17 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
final
public
function
getID
()
{
return
$this
->
id
;
}
/**
* getLast
* this method is used internally be Doctrine_Query
* it is needed to provide compatibility between
* records and collections
*
* @return Doctrine_Record
*/
public
function
getLast
()
{
return
$this
;
}
/**
* hasRefence
* @param string $name
...
...
@@ -845,8 +862,22 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
return
isset
(
$this
->
references
[
$name
]);
}
/**
* initalizes a one-to-one relation
*
* @param Doctrine_Record $record
* @param Doctrine_Relation $connector
* @return void
*/
public
function
initSingleReference
(
Doctrine_Record
$record
)
{
$name
=
$this
->
table
->
getAlias
(
$record
->
getTable
()
->
getComponentName
());
$this
->
references
[
$name
]
=
$record
;
}
/**
* initalizes a one-to-many / many-to-many relation
*
* @param Doctrine_Collection $coll
* @param string $connectorField
* @param Doctrine_Relation $connector
* @return void
*/
public
function
initReference
(
Doctrine_Collection
$coll
,
Doctrine_Relation
$connector
)
{
$name
=
$this
->
table
->
getAlias
(
$coll
->
getTable
()
->
getComponentName
());
...
...
classes/Sensei/Sensei.class.php
View file @
20990ed2
<?php
class
Sensei_Group
extends
Doctrine_Record
{
}
//class Sensei_Company extends Sensei_Group { }
class
Sensei_Company
extends
Sensei_Group
{
}
class
Sensei_User
extends
Doctrine_Record
{
}
//class Sensei_Customer extends Sensei_User { }
class
Sensei_Customer
extends
Sensei_User
{
}
class
Sensei_Entity
extends
Doctrine_Record
{
/**
* setTableDefinition
...
...
@@ -65,10 +63,7 @@ class Sensei_Session extends Doctrine_Record {
$this
->
hasColumn
(
"created"
,
"integer"
);
}
}
class
Sensei_Exception
extends
Exception
{
}
class
Sensei
extends
Doctrine_Access
{
const
ATTR_LIFESPAN
=
0
;
/**
...
...
classes/Session.class.php
View file @
20990ed2
...
...
@@ -246,46 +246,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
public
function
create
(
$name
)
{
return
$this
->
getTable
(
$name
)
->
create
();
}
public
function
buildFlushTree2
(
array
$tables
)
{
$tree
=
array
();
foreach
(
$tables
as
$table
)
{
if
(
!
(
$table
instanceof
Doctrine_Table
))
$table
=
$this
->
getTable
(
$table
);
$name
=
$table
->
getComponentName
();
$index
=
array_search
(
$name
,
$tree
);
if
(
$index
===
false
)
$tree
[]
=
$name
;
foreach
(
$table
->
getForeignKeys
()
as
$rel
)
{
$name
=
$rel
->
getTable
()
->
getComponentName
();
$index
=
array_search
(
$name
,
$tree
);
if
(
$rel
instanceof
Doctrine_ForeignKey
)
{
if
(
$index
!==
false
)
unset
(
$tree
[
$index
]);
$tree
[]
=
$name
;
}
elseif
(
$rel
instanceof
Doctrine_LocalKey
)
{
if
(
$index
!==
false
)
unset
(
$tree
[
$index
]);
array_unshift
(
$tree
,
$name
);
}
elseif
(
$rel
instanceof
Doctrine_Association
)
{
$t
=
$rel
->
getAssociationFactory
();
$n
=
$t
->
getComponentName
();
$index
=
array_search
(
$n
,
$tree
);
if
(
$index
!==
false
)
unset
(
$tree
[
$index
]);
$tree
[]
=
$n
;
}
}
}
return
array_values
(
$tree
);
}
/**
* buildFlushTree
...
...
@@ -573,7 +534,6 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
$increment
=
true
;
}
foreach
(
$inserts
as
$k
=>
$record
)
{
$record
->
getTable
()
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onPreSave
(
$record
);
// listen the onPreInsert event
...
...
classes/Table.class.php
View file @
20990ed2
...
...
@@ -81,6 +81,10 @@ class Doctrine_Table extends Doctrine_Configurable {
* @var array $boundAliases bound relation aliases
*/
private
$boundAliases
=
array
();
/**
* @var integer $columnCount cached column count
*/
private
$columnCount
;
/**
...
...
@@ -135,6 +139,8 @@ class Doctrine_Table extends Doctrine_Configurable {
if
(
method_exists
(
$record
,
"setTableDefinition"
))
{
$record
->
setTableDefinition
();
$this
->
columnCount
=
count
(
$this
->
columns
);
if
(
isset
(
$this
->
columns
))
{
$method
=
new
ReflectionMethod
(
$this
->
name
,
"setTableDefinition"
);
$class
=
$method
->
getDeclaringClass
();
...
...
@@ -784,7 +790,7 @@ class Doctrine_Table extends Doctrine_Configurable {
* @return integer
*/
final
public
function
getColumnCount
()
{
return
count
(
$this
->
columns
)
;
return
$this
->
columnCount
;
}
/**
* returns all columns and their definitions
...
...
classes/Validator/Nospace.class.php
View file @
20990ed2
...
...
@@ -8,7 +8,7 @@ class Doctrine_Validator_NoSpace {
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
if
(
preg_match
(
"/[\s
\r\t\n
]/"
,
$value
)
)
if
(
trim
(
$value
)
===
''
)
return
false
;
return
true
;
...
...
tests/QueryTestCase.class.php
View file @
20990ed2
...
...
@@ -7,6 +7,46 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this
->
tables
[]
=
"Forum_Thread"
;
parent
::
prepareTables
();
}
public
function
testOneToOneRelationFetching
()
{
$count
=
$this
->
dbh
->
count
();
$users
=
$this
->
query
->
from
(
"User-l:Email-i"
)
->
execute
();
$this
->
assertEqual
((
$count
+
1
),
$this
->
dbh
->
count
());
$this
->
assertTrue
(
$users
instanceof
Doctrine_Collection_Lazy
);
$count
=
$this
->
dbh
->
count
();
foreach
(
$users
as
$user
)
{
// iterate through users and test that no additional queries are needed
$user
->
Email
->
address
;
$this
->
assertEqual
(
$count
,
$this
->
dbh
->
count
());
}
$users
[
0
]
->
Account
->
amount
=
3000
;
$this
->
assertEqual
(
$users
[
0
]
->
Account
->
amount
,
3000
);
$this
->
assertTrue
(
$users
[
0
]
->
Account
instanceof
Account
);
$this
->
assertEqual
(
$users
[
0
]
->
id
,
$users
[
0
]
->
Account
->
entity_id
);
$users
[
0
]
->
Account
->
save
();
$users
[
0
]
->
refresh
();
$this
->
assertEqual
(
$users
[
0
]
->
Account
->
amount
,
3000
);
$this
->
assertTrue
(
$users
[
0
]
->
Account
instanceof
Account
);
$this
->
assertEqual
(
$users
[
0
]
->
id
,
$users
[
0
]
->
Account
->
entity_id
);
$this
->
assertEqual
(
$users
[
0
]
->
Account
->
getState
(),
Doctrine_Record
::
STATE_CLEAN
);
$users
[
0
]
->
getTable
()
->
clear
();
$users
[
0
]
->
Account
->
getTable
()
->
clear
();
$count
=
$this
->
dbh
->
count
();
$users
=
$this
->
query
->
from
(
"User-l:Account-i"
)
->
execute
();
$this
->
assertEqual
((
$count
+
1
),
$this
->
dbh
->
count
());
$this
->
assertTrue
(
$users
instanceof
Doctrine_Collection_Lazy
);
$this
->
assertEqual
(
$users
->
count
(),
1
);
$this
->
assertEqual
(
$users
[
0
]
->
Account
->
amount
,
3000
);
}
public
function
testNotValidLazyPropertyFetching
()
{
$q
=
new
Doctrine_Query
(
$this
->
session
);
...
...
@@ -49,7 +89,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$count
+
1
,
count
(
$this
->
dbh
));
}
public
function
testQueryWithComplexAliases
()
{
$q
=
new
Doctrine_Query
(
$this
->
session
);
...
...
@@ -209,7 +248,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$query
->
offset
,
3
);
$this
->
assertEqual
(
$coll
->
count
(),
3
);
}
public
function
testPrepared
()
{
public
function
testPrepared
Query
()
{
$coll
=
$this
->
session
->
query
(
"FROM User WHERE User.name = :name"
,
array
(
":name"
=>
"zYne"
));
$this
->
assertEqual
(
$coll
->
count
(),
1
);
}
...
...
@@ -223,6 +262,25 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$users
->
count
(),
8
);
$this
->
assertTrue
(
$users
[
0
]
->
name
==
"Arnold Schwarzenegger"
);
}
public
function
testBatchFetching
()
{
$query
=
new
Doctrine_Query
(
$this
->
session
);
$users
=
$query
->
query
(
"FROM User-b"
);
$this
->
assertEqual
(
trim
(
$query
->
getQuery
()),
"SELECT entity.id AS User__id FROM entity WHERE (entity.type = 0)"
);
$this
->
assertEqual
(
$users
[
0
]
->
name
,
"zYne"
);
$this
->
assertTrue
(
$users
instanceof
Doctrine_Collection_Batch
);
}
public
function
testLazyFetching
()
{
$query
=
new
Doctrine_Query
(
$this
->
session
);
$users
=
$query
->
query
(
"FROM User-l"
);
$this
->
assertEqual
(
trim
(
$query
->
getQuery
()),
"SELECT entity.id AS User__id FROM entity WHERE (entity.type = 0)"
);
$this
->
assertEqual
(
$users
[
0
]
->
name
,
"zYne"
);
$this
->
assertTrue
(
$users
instanceof
Doctrine_Collection_Lazy
);
}
public
function
testQuery
()
{
...
...
@@ -326,21 +384,9 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$count2
=
$this
->
session
->
getDBH
()
->
count
();
$users
=
$query
->
query
(
"FROM User-b"
);
$this
->
assertEqual
(
trim
(
$query
->
getQuery
()),
"SELECT entity.id AS User__id FROM entity WHERE (entity.type = 0)"
);
$this
->
assertEqual
(
$users
[
0
]
->
name
,
"zYne"
);
$this
->
assertTrue
(
$users
instanceof
Doctrine_Collection_Batch
);
$users
=
$query
->
query
(
"FROM User-l"
);
$this
->
assertEqual
(
trim
(
$query
->
getQuery
()),
"SELECT entity.id AS User__id FROM entity WHERE (entity.type = 0)"
);
$this
->
assertEqual
(
$users
[
0
]
->
name
,
"zYne"
);
$this
->
assertTrue
(
$users
instanceof
Doctrine_Collection_Lazy
);
//$this->clearCache();
...
...
@@ -403,5 +449,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
//$this->assertTrue(isset($values['max']));
}
}
?>
tests/SenseiTestCase.class.php
View file @
20990ed2
<?php
require_once
(
"../classes/Doctrine.class.php"
);
Doctrine
::
loadAll
();
class
Sensei_UnitTestCase
extends
UnitTestCase
{
...
...
@@ -13,6 +14,9 @@ class Sensei_UnitTestCase extends UnitTestCase {
private
$init
=
false
;
public
function
init
()
{
if
(
headers_sent
())
throw
new
Exception
(
"'"
.
ob_end_flush
()
.
"'"
);
$this
->
manager
=
Doctrine_Manager
::
getInstance
();
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_CACHE
,
Doctrine
::
CACHE_NONE
);
...
...
@@ -109,6 +113,5 @@ class Sensei_UnitTestCase extends UnitTestCase {
$this
->
assertEqual
(
$this
->
record
->
entity_id
,
0
);
}
}
?>
tests/UnitTestCase.class.php
View file @
20990ed2
...
...
@@ -49,6 +49,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_LISTENER
,
$this
->
listener
);
}
$this
->
query
=
new
Doctrine_Query
(
$this
->
session
);
$this
->
prepareTables
();
$this
->
prepareData
();
}
...
...
tests/classes.php
View file @
20990ed2
...
...
@@ -207,4 +207,53 @@ class Forum_Thread extends Doctrine_Record {
$this
->
ownsMany
(
"Forum_Entry as Entries"
,
"Forum_Entry.thread_id"
);
}
}
class
App
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
32
);
$this
->
hasColumn
(
"user_id"
,
"integer"
,
11
);
$this
->
hasColumn
(
"app_category_id"
,
"integer"
,
11
);
}
public
function
setUp
()
{
$this
->
hasOne
(
"User"
,
"User.id"
);
$this
->
hasMany
(
"App_Category as Category"
,
"App_Category.id"
);
}
}
class
App_User
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"first_name"
,
"string"
,
32
);
$this
->
hasColumn
(
"last_name"
,
"string"
,
32
);
$this
->
hasColumn
(
"email"
,
"string"
,
128
,
"email"
);
$this
->
hasColumn
(
"username"
,
"string"
,
16
,
"unique, nospace"
);
$this
->
hasColumn
(
"password"
,
"string"
,
128
,
"notblank"
);
$this
->
hasColumn
(
"country"
,
"string"
,
2
,
"country"
);
$this
->
hasColumn
(
"zipcode"
,
"string"
,
9
,
"nospace"
);
}
public
function
setUp
()
{
$this
->
hasMany
(
"App"
,
"App.user_id"
);
}
}
class
App_Category
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
32
);
$this
->
hasColumn
(
"parent_id"
,
"integer"
);
}
public
function
setUp
()
{
$this
->
hasMany
(
"App"
,
"App.app_category_id"
);
$this
->
hasMany
(
"App_Category as Parent"
,
"App_Category.parent_id"
);
}
}
/**
$apps = $con->query("FROM App.Category");
if (!empty($apps))
{
foreach ($apps as $app)
{
print '<p>' . $app->Category[0]->name . ' => ' . $app->name . '</p>';
}
}
*/
?>
tests/run.php
View file @
20990ed2
...
...
@@ -52,8 +52,6 @@ $test->addTestCase(new Doctrine_QueryTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
print
"<pre>"
;
$test
->
run
(
new
HtmlReporter
());
$cache
=
Doctrine_Manager
::
getInstance
()
->
getCurrentSession
()
->
getCacheHandler
();
...
...
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