add switchCatalogs() from the current implementation
@@ -822,7 +822,7 @@ public final class SQLServerDatabaseMetaData implements java.sql.DatabaseMetaDat
+ (null == schema || schema.trim().length() != 0 ? ", @pktable_owner=" + schema : "")
+ (null == cat || cat.trim().length() != 0 ? ", @pktable_qualifier=" + cat : "");
- return getResultSetForForeignKeyInformation(sp_fkeys_Query);
+ return getResultSetForForeignKeyInformation(sp_fkeys_Query, cat);
}
/* L0 */ public String getExtraNameCharacters() throws SQLServerException {
@@ -858,7 +858,7 @@ public final class SQLServerDatabaseMetaData implements java.sql.DatabaseMetaDat
+ (null == schema || schema.trim().length() != 0 ? ", @fktable_owner=" + schema : "")
+ (null == cat || cat.trim().length() != 0 ? ", @fktable_qualifier=" + cat : "");
- return getResultSetForForeignKeyInformation(sp_fkeys_Query);
+ return getResultSetForForeignKeyInformation(sp_fkeys_Query, cat);
}
String fkeys_results_column_definition = "PKTABLE_QUALIFIER sysname, PKTABLE_OWNER sysname, PKTABLE_NAME sysname, PKCOLUMN_NAME sysname, FKTABLE_QUALIFIER sysname, FKTABLE_OWNER sysname, FKTABLE_NAME sysname, FKCOLUMN_NAME sysname, KEY_SEQ smallint, UPDATE_RULE smallint, DELETE_RULE smallint, FK_NAME sysname, PK_NAME sysname, DEFERRABILITY smallint";
@@ -873,14 +873,15 @@ public final class SQLServerDatabaseMetaData implements java.sql.DatabaseMetaDat
* @return
* @throws SQLServerException
*/
- private ResultSet getResultSetForForeignKeyInformation(String sp_fkeys_Query) throws SQLServerException {
+ private ResultSet getResultSetForForeignKeyInformation(String sp_fkeys_Query, String cat) throws SQLServerException {
String fkeys_results_tableName = "#fkeys_results";
String foreign_keys_combined_tableName = "#foreign_keys_combined_results";
String sys_foreign_keys = "sys.foreign_keys";
- SQLServerStatement stmt = null; //cannot close this statement, otherwise the returned resultset would be closed too.
-
- stmt = (SQLServerStatement) connection.createStatement();
+ String orgCat = switchCatalogs(cat);
+ try {
+ // cannot close this statement, otherwise the returned resultset would be closed too.
+ SQLServerStatement stmt = (SQLServerStatement) connection.createStatement();
/**
* create a temp table that has the same definition as the result of sp_fkeys:
@@ -963,6 +964,12 @@ public final class SQLServerDatabaseMetaData implements java.sql.DatabaseMetaDat
"select PKTABLE_QUALIFIER,PKTABLE_OWNER,PKTABLE_NAME,PKCOLUMN_NAME,FKTABLE_QUALIFIER,FKTABLE_OWNER,FKTABLE_NAME,FKCOLUMN_NAME,KEY_SEQ,UPDATE_RULE,DELETE_RULE,FK_NAME,PK_NAME,DEFERRABILITY from "
+ foreign_keys_combined_tableName + " order by FKTABLE_QUALIFIER, FKTABLE_OWNER, FKTABLE_NAME, KEY_SEQ");
}
+ finally {
+ if (null != orgCat) {
+ connection.setCatalog(orgCat);
+ }
+ }
+ }
private final static String[] getIndexInfoColumnNames = {/* 1 */ TABLE_CAT, /* 2 */ TABLE_SCHEM, /* 3 */ TABLE_NAME, /* 4 */ NON_UNIQUE,
/* 5 */ INDEX_QUALIFIER, /* 6 */ INDEX_NAME, /* 7 */ TYPE, /* 8 */ ORDINAL_POSITION, /* 9 */ COLUMN_NAME, /* 10 */ ASC_OR_DESC,
