Subject: | DB2: unique constraint detection fails |
In DBIx::Class::Schema::Loader::DBI::DB2::_table_uniq_info(), we see:
q{SELECT kcu.COLNAME, kcu.CONSTNAME, kcu.COLSEQ
FROM SYSCAT.TABCONST as tc
JOIN SYSCAT.KEYCOLUSE as kcu ON tc.CONSTNAME = kcu.CONSTNAME
WHERE tc.TABSCHEMA = ? and tc.TABNAME = ? and tc.TYPE = 'U'}
However, tc and kcu should be joined using both the table and schema
names, along the lines of
q{SELECT kcu.COLNAME, kcu.CONSTNAME, kcu.COLSEQ
FROM SYSCAT.TABCONST as tc
JOIN SYSCAT.KEYCOLUSE as kcu
ON tc.CONSTNAME = kcu.CONSTNAME and tc.SCHEMANAME = kcu.SCHEMANAME
WHERE tc.TABSCHEMA = ? and tc.TABNAME = ? and tc.TYPE = 'U'}
Without that, the query will return constraints for the wrong tables if
there happens to be a table of the same name in multiple schemas.
(marked as critical as this tends to break functionality with DB2)