// Intermediate holders
Iterator tables;
Table table;
Constraint[] constraints;
int constraintCount;
Constraint constraint;
String cat;
String schem;
Object[] row;
// column number mappings
final int constraint_catalog = 0;
final int constraint_schema = 1;
final int constraint_name = 2;
final int constraint_type = 3;
final int table_catalog = 4;
final int table_schema = 5;
final int table_name = 6;
final int is_deferable = 7;
final int initially_deferred = 8;
// initialization
tables =
database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
table = null; // else compiler complains
// do it
while (tables.hasNext()) {
table = (Table) tables.next();
/** @todo - requires table level INSERT or UPDATE or DELETE or REFERENCES (not SELECT) right */
if (table.isView() || !isAccessibleTable(table)) {
continue;
}
constraints = table.getConstraints();
constraintCount = constraints.length;
for (int i = 0; i < constraintCount; i++) {
constraint = constraints[i];
row = t.getEmptyRowData();
switch (constraint.getConstraintType()) {
case Constraint.CHECK : {
row[constraint_type] = "CHECK";
break;
}
case Constraint.UNIQUE : {
row[constraint_type] = "UNIQUE";
break;
}
case Constraint.FOREIGN_KEY : {
row[constraint_type] = "FOREIGN KEY";
table = constraint.getRef();
break;
}
case Constraint.PRIMARY_KEY : {
row[constraint_type] = "PRIMARY KEY";
break;
}
case Constraint.MAIN :
default : {
continue;
}
}
cat = database.getCatalogName().name;
schem = table.getSchemaName().name;
row[constraint_catalog] = cat;
row[constraint_schema] = schem;
row[constraint_name] = constraint.getName().name;
row[table_catalog] = cat;
row[table_schema] = schem;
row[table_name] = table.getName().name;
row[is_deferable] = Tokens.T_NO;
row[initially_deferred] = Tokens.T_NO;