Skip to content

get_foreign_keys only for tables, not aliases#56

Closed
mdobrzanski wants to merge 1 commit intoibmdb:masterfrom
mdobrzanski:reflect-with-aliases
Closed

get_foreign_keys only for tables, not aliases#56
mdobrzanski wants to merge 1 commit intoibmdb:masterfrom
mdobrzanski:reflect-with-aliases

Conversation

@mdobrzanski
Copy link
Copy Markdown

This is in reference to #20

The fix is to return foreign keys only between tables by making a join SQL and filtering tables by type = 'T'.

@asierra01
Copy link
Copy Markdown

asierra01 commented Feb 3, 2019

When I have a chance will do a test with your code....I would image this filter will fix the duplicate fk...that include the (wrong) alias tables. I found out the ibm_db driver also has a function for this purpose ibm_db.foreign_keys....

@CJ-Wright
Copy link
Copy Markdown

This fixed the issue with the DB2 sample DB for me

@amukherjee28
Copy link
Copy Markdown
Member

Changing the query for get_foreign_keys to check where the foreign key table is of type table helps to distinguish alias from table.

Current new query

SELECT "SYSIBM"."SQLFOREIGNKEYS"."FK_NAME", "SYSIBM"."SQLFOREIGNKEYS"."FKTABLE_SCHEM", "SYSIBM"."SQLFOREIGNKEYS"."FKTABLE_NAME", "SYSIBM"."SQLFOREIGNKEYS"."FKCOLUMN_NAME", "SYSIBM"."SQLFOREIGNKEYS"."PK_NAME", "SYSIBM"."SQLFOREIGNKEYS"."PKTABLE_SCHEM", "SYSIBM"."SQLFOREIGNKEYS"."PKTABLE_NAME", "SYSIBM"."SQLFOREIGNKEYS"."PKCOLUMN_NAME" 
FROM "SYSCAT"."TABLES" INNER JOIN "SYSIBM"."SQLFOREIGNKEYS" ON "SYSCAT"."TABLES"."TABNAME" = "SYSIBM"."SQLFOREIGNKEYS"."PKTABLE_NAME" 
WHERE "SYSCAT"."TABLES"."TYPE" = ? AND "SYSCAT"."TABLES"."TABSCHEMA" = ? AND "SYSIBM"."SQLFOREIGNKEYS"."FKTABLE_NAME" = ? ORDER BY "SYSCAT"."TABLES"."TABNAME"

This will help solve the autoload issue for SAMPLE database.

This implementation is only on LUW server for now.

The code change is implemented manually as the PR needs to be rebased.

This is an important change and hence the change was implemented. We thank you for your contribution @mdobrzanski

Thanks

1 similar comment
@amukherjee28
Copy link
Copy Markdown
Member

Changing the query for get_foreign_keys to check where the foreign key table is of type table helps to distinguish alias from table.

Current new query

SELECT "SYSIBM"."SQLFOREIGNKEYS"."FK_NAME", "SYSIBM"."SQLFOREIGNKEYS"."FKTABLE_SCHEM", "SYSIBM"."SQLFOREIGNKEYS"."FKTABLE_NAME", "SYSIBM"."SQLFOREIGNKEYS"."FKCOLUMN_NAME", "SYSIBM"."SQLFOREIGNKEYS"."PK_NAME", "SYSIBM"."SQLFOREIGNKEYS"."PKTABLE_SCHEM", "SYSIBM"."SQLFOREIGNKEYS"."PKTABLE_NAME", "SYSIBM"."SQLFOREIGNKEYS"."PKCOLUMN_NAME" 
FROM "SYSCAT"."TABLES" INNER JOIN "SYSIBM"."SQLFOREIGNKEYS" ON "SYSCAT"."TABLES"."TABNAME" = "SYSIBM"."SQLFOREIGNKEYS"."PKTABLE_NAME" 
WHERE "SYSCAT"."TABLES"."TYPE" = ? AND "SYSCAT"."TABLES"."TABSCHEMA" = ? AND "SYSIBM"."SQLFOREIGNKEYS"."FKTABLE_NAME" = ? ORDER BY "SYSCAT"."TABLES"."TABNAME"

This will help solve the autoload issue for SAMPLE database.

This implementation is only on LUW server for now.

The code change is implemented manually as the PR needs to be rebased.

This is an important change and hence the change was implemented. We thank you for your contribution @mdobrzanski

Thanks

amukherjee28 added a commit to amukherjee28/python-ibmdbsa that referenced this pull request Apr 27, 2022
amukherjee28 added a commit to amukherjee28/python-ibmdbsa that referenced this pull request Apr 27, 2022
Signed-off-by: amukherjee <amukherjee@rocketsoftware.com>
amukherjee28 added a commit that referenced this pull request Apr 27, 2022
* code fix for issue #106

Signed-off-by: amukherjee <amukherjee@rocketsoftware.com>

* Code changes for issue #24

Signed-off-by: amukherjee <amukherjee@rocketsoftware.com>

* PR changes #74

Signed-off-by: amukherjee <amukherjee@rocketsoftware.com>

* Fix for issue #20 and PR #56

Signed-off-by: amukherjee <amukherjee@rocketsoftware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants