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
6e6c4353
Commit
6e6c4353
authored
Dec 16, 2013
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix table foreign key constraints introspection in DB2
parent
06147703
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
15 deletions
+60
-15
DB2Platform.php
lib/Doctrine/DBAL/Platforms/DB2Platform.php
+25
-2
DB2SchemaManager.php
lib/Doctrine/DBAL/Schema/DB2SchemaManager.php
+35
-13
No files found.
lib/Doctrine/DBAL/Platforms/DB2Platform.php
View file @
6e6c4353
...
@@ -254,8 +254,31 @@ class DB2Platform extends AbstractPlatform
...
@@ -254,8 +254,31 @@ class DB2Platform extends AbstractPlatform
*/
*/
public
function
getListTableForeignKeysSQL
(
$table
)
public
function
getListTableForeignKeysSQL
(
$table
)
{
{
return
"SELECT TBNAME, RELNAME, REFTBNAME, DELETERULE, UPDATERULE, FKCOLNAMES, PKCOLNAMES "
.
return
"SELECT fkcol.COLNAME AS local_column,
"FROM SYSIBM.SYSRELS WHERE TBNAME = UPPER('"
.
$table
.
"')"
;
fk.REFTABNAME AS foreign_table,
pkcol.COLNAME AS foreign_column,
fk.CONSTNAME AS index_name,
CASE
WHEN fk.UPDATERULE = 'R' THEN 'RESTRICT'
ELSE NULL
END AS on_update,
CASE
WHEN fk.DELETERULE = 'C' THEN 'CASCADE'
WHEN fk.DELETERULE = 'N' THEN 'SET NULL'
WHEN fk.DELETERULE = 'R' THEN 'RESTRICT'
ELSE NULL
END AS on_delete
FROM SYSCAT.REFERENCES AS fk
JOIN SYSCAT.KEYCOLUSE AS fkcol
ON fk.CONSTNAME = fkcol.CONSTNAME
AND fk.TABSCHEMA = fkcol.TABSCHEMA
AND fk.TABNAME = fkcol.TABNAME
JOIN SYSCAT.KEYCOLUSE AS pkcol
ON fk.REFKEYNAME = pkcol.CONSTNAME
AND fk.REFTABSCHEMA = pkcol.TABSCHEMA
AND fk.REFTABNAME = pkcol.TABNAME
WHERE fk.TABNAME = UPPER('"
.
$table
.
"')
ORDER BY fkcol.COLSEQ ASC"
;
}
}
/**
/**
...
...
lib/Doctrine/DBAL/Schema/DB2SchemaManager.php
View file @
6e6c4353
...
@@ -133,21 +133,43 @@ class DB2SchemaManager extends AbstractSchemaManager
...
@@ -133,21 +133,43 @@ class DB2SchemaManager extends AbstractSchemaManager
*/
*/
protected
function
_getPortableTableForeignKeyDefinition
(
$tableForeignKey
)
protected
function
_getPortableTableForeignKeyDefinition
(
$tableForeignKey
)
{
{
$tableForeignKey
=
array_change_key_case
(
$tableForeignKey
,
CASE_LOWER
);
$tableForeignKey
[
'deleterule'
]
=
$this
->
_getPortableForeignKeyRuleDef
(
$tableForeignKey
[
'deleterule'
]);
$tableForeignKey
[
'updaterule'
]
=
$this
->
_getPortableForeignKeyRuleDef
(
$tableForeignKey
[
'updaterule'
]);
return
new
ForeignKeyConstraint
(
return
new
ForeignKeyConstraint
(
array_map
(
'trim'
,
(
array
)
$tableForeignKey
[
'fkcolnames'
]),
$tableForeignKey
[
'local_columns'
],
$tableForeignKey
[
'reftbname'
],
$tableForeignKey
[
'foreign_table'
],
array_map
(
'trim'
,
(
array
)
$tableForeignKey
[
'pkcolnames'
]),
$tableForeignKey
[
'foreign_columns'
],
$tableForeignKey
[
'relname'
],
$tableForeignKey
[
'name'
],
array
(
$tableForeignKey
[
'options'
]
'onUpdate'
=>
$tableForeignKey
[
'updaterule'
],
);
'onDelete'
=>
$tableForeignKey
[
'deleterule'
],
}
/**
* {@inheritdoc}
*/
protected
function
_getPortableTableForeignKeysList
(
$tableForeignKeys
)
{
$foreignKeys
=
array
();
foreach
(
$tableForeignKeys
as
$tableForeignKey
)
{
$tableForeignKey
=
array_change_key_case
(
$tableForeignKey
,
\CASE_LOWER
);
if
(
!
isset
(
$foreignKeys
[
$tableForeignKey
[
'index_name'
]]))
{
$foreignKeys
[
$tableForeignKey
[
'index_name'
]]
=
array
(
'local_columns'
=>
array
(
$tableForeignKey
[
'local_column'
]),
'foreign_table'
=>
$tableForeignKey
[
'foreign_table'
],
'foreign_columns'
=>
array
(
$tableForeignKey
[
'foreign_column'
]),
'name'
=>
$tableForeignKey
[
'index_name'
],
'options'
=>
array
(
'onUpdate'
=>
$tableForeignKey
[
'on_update'
],
'onDelete'
=>
$tableForeignKey
[
'on_delete'
],
)
)
);
);
}
else
{
$foreignKeys
[
$tableForeignKey
[
'index_name'
]][
'local_columns'
][]
=
$tableForeignKey
[
'local_column'
];
$foreignKeys
[
$tableForeignKey
[
'index_name'
]][
'foreign_columns'
][]
=
$tableForeignKey
[
'foreign_column'
];
}
}
return
parent
::
_getPortableTableForeignKeysList
(
$foreignKeys
);
}
}
/**
/**
...
...
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