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
f7a7472c
Commit
f7a7472c
authored
Mar 21, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Foreign key exporting added
parent
1fbb8b6c
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
138 additions
and
33 deletions
+138
-33
Doctrine.php
lib/Doctrine.php
+4
-4
Configurable.php
lib/Doctrine/Configurable.php
+3
-1
Connection.php
lib/Doctrine/Connection.php
+4
-0
Pessimistic.php
lib/Doctrine/Locking/Manager/Pessimistic.php
+1
-1
Manager.php
lib/Doctrine/Manager.php
+1
-0
Relation.php
lib/Doctrine/Relation.php
+14
-0
Table.php
lib/Doctrine/Table.php
+21
-10
MysqlTestCase.php
tests/Export/MysqlTestCase.php
+73
-5
ManyToManyTestCase.php
tests/Relation/ManyToManyTestCase.php
+4
-4
UnitOfWorkTestCase.php
tests/UnitOfWorkTestCase.php
+2
-1
UnitTestCase.php
tests/UnitTestCase.php
+2
-1
run.php
tests/run.php
+9
-6
No files found.
lib/Doctrine.php
View file @
f7a7472c
...
...
@@ -345,13 +345,13 @@ final class Doctrine
*/
const
EXPORT_NONE
=
0
;
/**
* export
constraint
s
* export
table
s
*/
const
EXPORT_
CONSTRAINTS
=
1
;
const
EXPORT_
TABLES
=
1
;
/**
* export
table
s
* export
constraint
s
*/
const
EXPORT_
TABLES
=
2
;
const
EXPORT_
CONSTRAINTS
=
2
;
/**
* export all
*/
...
...
lib/Doctrine/Configurable.php
View file @
f7a7472c
...
...
@@ -94,7 +94,8 @@ abstract class Doctrine_Configurable
}
break
;
case
Doctrine
::
ATTR_CREATE_TABLES
:
$value
=
(
bool
)
$value
;
$attribute
=
Doctrine
::
ATTR_EXPORT
;
$value
=
Doctrine
::
EXPORT_ALL
;
break
;
case
Doctrine
::
ATTR_ACCESSORS
:
$accessors
=
array
(
'none'
,
'get'
,
'set'
,
'both'
);
...
...
@@ -128,6 +129,7 @@ abstract class Doctrine_Configurable
case
Doctrine
::
ATTR_ACCESSOR_PREFIX_SET
:
case
Doctrine
::
ATTR_EMULATE_DATABASE
:
case
Doctrine
::
ATTR_DEFAULT_SEQUENCE
:
case
Doctrine
::
ATTR_EXPORT
:
break
;
case
Doctrine
::
ATTR_SEQCOL_NAME
:
...
...
lib/Doctrine/Connection.php
View file @
f7a7472c
...
...
@@ -758,6 +758,10 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$this
->
tables
[
$name
]
=
$table
;
if
(
$table
->
getAttribute
(
Doctrine
::
ATTR_EXPORT
)
&
Doctrine
::
EXPORT_TABLES
)
{
$table
->
export
();
}
return
$table
;
}
/**
...
...
lib/Doctrine/Locking/Manager/Pessimistic.php
View file @
f7a7472c
...
...
@@ -58,7 +58,7 @@ class Doctrine_Locking_Manager_Pessimistic
{
$this
->
conn
=
$conn
;
if
(
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_
CREATE_TABLES
)
===
true
)
{
if
(
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_
EXPORT
)
&
Doctrine
::
EXPORT_TABLES
)
{
$columns
=
array
();
$columns
[
'object_type'
]
=
array
(
'type'
=>
'string'
,
'length'
=>
50
,
...
...
lib/Doctrine/Manager.php
View file @
f7a7472c
...
...
@@ -114,6 +114,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
Doctrine
::
ATTR_QUOTE_IDENTIFIER
=>
false
,
Doctrine
::
ATTR_SEQCOL_NAME
=>
'id'
,
Doctrine
::
ATTR_PORTABILITY
=>
Doctrine
::
PORTABILITY_ALL
,
Doctrine
::
ATTR_EXPORT
=>
Doctrine
::
EXPORT_NONE
,
);
foreach
(
$attributes
as
$attribute
=>
$value
)
{
$old
=
$this
->
getAttribute
(
$attribute
);
...
...
lib/Doctrine/Relation.php
View file @
f7a7472c
...
...
@@ -66,6 +66,7 @@ abstract class Doctrine_Relation
'onDelete'
=>
false
,
'onUpdate'
=>
false
,
'deferred'
=>
false
,
'constraint'
=>
false
,
);
/**
* constructor
...
...
@@ -91,6 +92,8 @@ abstract class Doctrine_Relation
*
* type the relation type, either Doctrine_Relation::ONE or Doctrine_Relation::MANY
*
* constraint boolean value, true if the relation needs referential integrity constraint
*
* The onDelete and onUpdate keys accept the following values:
*
* CASCADE: Delete or update the row from the parent table and automatically delete or
...
...
@@ -119,6 +122,8 @@ abstract class Doctrine_Relation
}
if
(
isset
(
$definition
[
$key
]))
{
$def
[
$key
]
=
$definition
[
$key
];
}
else
{
$def
[
$key
]
=
null
;
}
}
...
...
@@ -133,6 +138,15 @@ abstract class Doctrine_Relation
{
return
$this
->
definition
;
}
/**
* hasConstraint
*
* @return boolean
*/
public
function
hasConstraint
()
{
return
$this
->
definition
[
'constraint'
];
}
/**
* getAlias
* returns the relation alias
...
...
lib/Doctrine/Table.php
View file @
f7a7472c
...
...
@@ -295,9 +295,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
}
*/
if
(
$this
->
getAttribute
(
Doctrine
::
ATTR_CREATE_TABLES
))
{
$this
->
export
();
}
}
}
else
{
...
...
@@ -362,13 +360,21 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$primary
[]
=
$name
;
}
}
/**
foreach ($this->getRelations() as $name => $relation) {
$fk = $relation->toArray();
$fk['foreignTable'] = $relation->getTable()->getTableName();
$options['foreignKeys'][] = $fk;
} */
if
(
$this
->
getAttribute
(
Doctrine
::
ATTR_EXPORT
)
&
Doctrine
::
EXPORT_CONSTRAINTS
)
{
foreach
(
$this
->
getRelations
()
as
$name
=>
$relation
)
{
$fk
=
$relation
->
toArray
();
$fk
[
'foreignTable'
]
=
$relation
->
getTable
()
->
getTableName
();
if
(
$relation
->
hasConstraint
())
{
$options
[
'foreignKeys'
][]
=
$fk
;
}
elseif
(
$relation
instanceof
Doctrine_Relation_LocalKey
)
{
$options
[
'foreignKeys'
][]
=
$fk
;
}
}
}
$options
[
'primary'
]
=
$primary
;
...
...
@@ -847,6 +853,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
unset
(
$definition
[
'field'
]);
$definition
[
'table'
]
=
$this
->
conn
->
getTable
(
$definition
[
'class'
],
false
);
$definition
[
'constraint'
]
=
false
;
if
(
$component
==
$this
->
options
[
'name'
]
||
in_array
(
$component
,
$this
->
options
[
'parents'
]))
{
...
...
@@ -872,6 +879,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
}
//$definition['foreign'] = $tmp;
$definition
[
'constraint'
]
=
true
;
$relation
=
new
Doctrine_Relation_ForeignKey
(
$definition
);
}
...
...
@@ -882,6 +890,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
if
(
!
isset
(
$defintion
[
'local'
]))
{
$definition
[
'local'
]
=
$this
->
identifier
;
}
$definition
[
'constraint'
]
=
true
;
// ONE-TO-MANY or ONE-TO-ONE
$relation
=
new
Doctrine_Relation_ForeignKey
(
$definition
);
...
...
@@ -914,7 +925,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
if
(
$e2
[
0
]
!=
$component
)
{
throw
new
Doctrine_Table_Exception
(
$e2
[
0
]
.
' doesn\'t match '
.
$component
);
}
$associationTable
=
$this
->
conn
->
getTable
(
$e2
[
0
]
,
false
);
$associationTable
=
$this
->
conn
->
getTable
(
$e2
[
0
]);
if
(
count
(
$fields
)
>
1
)
{
// SELF-REFERENCING THROUGH JOIN TABLE
...
...
tests/Export/MysqlTestCase.php
View file @
f7a7472c
...
...
@@ -32,6 +32,11 @@
*/
class
Doctrine_Export_Mysql_TestCase
extends
Doctrine_UnitTestCase
{
public
function
prepareTables
()
{
}
public
function
prepareData
()
{
}
public
function
testAlterTableThrowsExceptionWithoutValidTableName
()
{
try
{
...
...
@@ -248,7 +253,8 @@ class Doctrine_Export_Mysql_TestCase extends Doctrine_UnitTestCase
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'CREATE TABLE sometable (id INT UNSIGNED AUTO_INCREMENT, content VARCHAR(4), FULLTEXT INDEX myindex (content DESC), PRIMARY KEY(id)) ENGINE = MYISAM'
);
}
public
function
testExportSupportsIndexes
()
public
function
testExportSupportsIndexes
()
{
$r
=
new
MysqlIndexTestRecord
;
...
...
@@ -259,19 +265,45 @@ class Doctrine_Export_Mysql_TestCase extends Doctrine_UnitTestCase
{
$r
=
new
MysqlForeignKeyTest
;
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'CREATE TABLE mysql_foreign_key_test (id BIGINT AUTO_INCREMENT, name TEXT, code INT, content TEXT, parent_id BIGINT, FOREIGN KEY id REFERENCES mysql_foreign_key_test(parent_id) ON UPDATE RESTRICT ON DELETE CASCADE, PRIMARY KEY(id)) ENGINE = INNODB'
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'CREATE TABLE mysql_foreign_key_test (id BIGINT AUTO_INCREMENT, name TEXT, code INT, content TEXT, parent_id BIGINT, FOREIGN KEY
parent_id REFERENCES mysql_foreign_key_test(id), FOREIGN KEY
id REFERENCES mysql_foreign_key_test(parent_id) ON UPDATE RESTRICT ON DELETE CASCADE, PRIMARY KEY(id)) ENGINE = INNODB'
);
}
public
function
testExportSupportsForeignKeysWithoutAttributes
()
{
$r
=
new
MysqlForeignKeyTest2
;
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'CREATE TABLE mysql_foreign_key_test2 (id BIGINT AUTO_INCREMENT, name TEXT, foreignkey BIGINT, FOREIGN KEY foreignkey REFERENCES mysql_foreign_key_test(id), PRIMARY KEY(id)) ENGINE = INNODB'
);
}
public
function
testExportSupportsForeignKeysForManyToManyRelations
()
{
$r
=
new
MysqlUser
;
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'CREATE TABLE mysql_user (id BIGINT AUTO_INCREMENT, name TEXT, PRIMARY KEY(id)) ENGINE = INNODB'
);
$r
->
MysqlGroup
[
0
];
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'CREATE TABLE mysql_group (id BIGINT AUTO_INCREMENT, name TEXT, PRIMARY KEY(id)) ENGINE = INNODB'
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'CREATE TABLE mysql_group_member (group_id BIGINT, user_id BIGINT, PRIMARY KEY(group_id, user_id)) ENGINE = INNODB'
);
}
}
class
MysqlForeignKeyTest
extends
Doctrine_Record
{
public
function
setTableDefinition
()
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
'name'
,
'string'
,
null
);
$this
->
hasColumn
(
'code'
,
'integer'
,
4
);
$this
->
hasColumn
(
'content'
,
'string'
,
4000
);
$this
->
hasColumn
(
'parent_id'
,
'integer'
);
$this
->
hasMany
(
'MysqlForeignKeyTest as Children'
,
$this
->
hasOne
(
'MysqlForeignKeyTest as Parent'
,
'MysqlForeignKeyTest.parent_id'
);
$this
->
hasMany
(
'MysqlForeignKeyTest as Children'
,
'MysqlForeignKeyTest.parent_id'
,
array
(
'onDelete'
=>
'CASCADE'
,
'onUpdate'
=>
'RESTRICT'
)
...
...
@@ -281,7 +313,43 @@ class MysqlForeignKeyTest extends Doctrine_Record
}
}
class
MysqlIndexTestRecord
extends
Doctrine_Record
class
MysqlGroupMember
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
'group_id'
,
'integer'
,
null
,
'primary'
);
$this
->
hasColumn
(
'user_id'
,
'integer'
,
null
,
'primary'
);
}
}
class
MysqlUser
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
'name'
,
'string'
,
null
);
$this
->
hasMany
(
'MysqlGroup'
,
'MysqlGroupMember.group_id'
);
}
}
class
MysqlGroup
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
'name'
,
'string'
,
null
);
$this
->
hasMany
(
'MysqlUser'
,
'MysqlGroupMember.user_id'
);
}
}
class
MysqlForeignKeyTest2
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
'name'
,
'string'
,
null
);
$this
->
hasColumn
(
'foreignkey'
,
'integer'
);
$this
->
hasOne
(
'MysqlForeignKeyTest'
,
'MysqlForeignKeyTest2.foreignkey'
);
}
}
class
MysqlIndexTestRecord
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
...
...
tests/Relation/ManyToManyTestCase.php
View file @
f7a7472c
...
...
@@ -5,7 +5,7 @@ class M2MTest extends Doctrine_Record {
$this
->
hasColumn
(
'child_id'
,
'integer'
);
}
public
function
setUp
()
{
$this
->
ownsMany
(
'OwnsOneToManyWithAlias as AliasO2M'
,
'AliasO2M.component_id'
);
$this
->
hasMany
(
'RTC1 as RTC1'
,
'JC1.c1_id'
);
$this
->
hasMany
(
'RTC2 as RTC2'
,
'JC1.c1_id'
);
$this
->
hasMany
(
'RTC3 as RTC3'
,
'JC2.c1_id'
);
...
...
@@ -155,9 +155,10 @@ class Doctrine_Relation_ManyToMany_TestCase extends Doctrine_UnitTestCase {
}
public
function
testUnknownManyToManyRelation
()
{
$component
=
new
RelationErrorTest
();
try
{
$component
=
new
RelationErrorTest
();
$rel
=
$component
->
getTable
()
->
getRelation
(
'RTCUnknown'
);
$this
->
fail
();
}
catch
(
Doctrine_Table_Exception
$e
)
{
...
...
@@ -211,7 +212,6 @@ class Doctrine_Relation_ManyToMany_TestCase extends Doctrine_UnitTestCase {
public
function
testManyToManyHasRelationWithAliases
()
{
$component
=
new
M2MTest
();
$component
->
AliasO2M
;
try
{
$rel
=
$component
->
getTable
()
->
getRelation
(
'RTC1'
);
...
...
tests/UnitOfWorkTestCase.php
View file @
f7a7472c
...
...
@@ -22,7 +22,8 @@ class Doctrine_UnitOfWork_TestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$tree
,
$this
->
correct
);
$tree
=
$this
->
unitOfWork
->
buildFlushTree
(
array
(
"Assignment"
,
"Task"
,
"Resource"
));
$this
->
assertEqual
(
$tree
,
$this
->
correct2
);
$this
->
assertEqual
(
$tree
,
$this
->
correct
);
}
public
function
testbuildFlushTree2
()
{
$this
->
correct
=
array
(
"Forum_Category"
,
"Forum_Board"
,
"Forum_Thread"
);
...
...
tests/UnitTestCase.php
View file @
f7a7472c
...
...
@@ -29,7 +29,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
$this
->
manager
=
Doctrine_Manager
::
getInstance
();
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_FETCHMODE
,
Doctrine
::
FETCH_IMMEDIATE
);
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_EXPORT
,
Doctrine
::
EXPORT_ALL
);
$this
->
tables
=
array_merge
(
$this
->
tables
,
array
(
"entity"
,
...
...
@@ -92,6 +92,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
$this
->
listener
=
$this
->
manager
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
);
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_LISTENER
,
$this
->
listener
);
}
catch
(
Doctrine_Manager_Exception
$e
)
{
if
(
$this
->
driverName
==
'main'
)
{
$this
->
dbh
=
Doctrine_Db
::
getConnection
(
'sqlite::memory:'
);
...
...
tests/run.php
View file @
f7a7472c
...
...
@@ -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
());
...
...
@@ -108,12 +108,13 @@ $test->addTestCase(new Doctrine_Export_TestCase());
//$test->addTestCase(new Doctrine_Export_Reporter_TestCase());
$test
->
addTestCase
(
new
Doctrine_Export_Firebird_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Export_Informix_TestCase
());
$test->addTestCase(new Doctrine_Export_Mysql_TestCase());
$test
->
addTestCase
(
new
Doctrine_Export_Mssql_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Export_Pgsql_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Export_Oracle_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Export_Sqlite_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Export_Mysql_TestCase
());
// Import module (not yet fully tested)
//$test->addTestCase(new Doctrine_Import_TestCase());
...
...
@@ -153,6 +154,7 @@ $test->addTestCase(new Doctrine_Collection_TestCase());
$test
->
addTestCase
(
new
Doctrine_TreeStructure_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Relation_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Relation_Access_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Relation_ManyToMany_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Relation_OneToOne_TestCase
());
...
...
@@ -163,13 +165,15 @@ $test->addTestCase(new Doctrine_Boolean_TestCase());
// Utility components
$test->addTestCase(new Doctrine_Hook_TestCase());
$test
->
addTestCase
(
new
Doctrine_PessimisticLocking_TestCase
());
$test
->
addTestCase
(
new
Doctrine_RawSql_TestCase
());
$test
->
addTestCase
(
new
Doctrine_View_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Validator_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Hook_TestCase
());
// Db component
$test
->
addTestCase
(
new
Doctrine_Db_TestCase
());
...
...
@@ -196,7 +200,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 +209,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,7 +233,6 @@ $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());
...
...
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