Skip to content

Commit 2f4ad07

Browse files
committed
- Added foreign tables to the list of tables returned by getTables() and getTableNames() for PostgreSQL databases
git-svn-id: svn://192.168.0.80/JavaXT/javaxt-core@1599 2c7b0aa6-e0b2-3c4e-bb4a-8b65b6c465ff
1 parent 4fb4234 commit 2f4ad07

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/javaxt/sql/Database.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ public static Table[] getTables(Connection conn){
787787
java.util.ArrayList<Table> tables = new java.util.ArrayList<>();
788788
try{
789789
DatabaseMetaData dbmd = conn.getConnection().getMetaData();
790-
try(ResultSet rs = dbmd.getTables(null,null,null,new String[]{"TABLE"})){
790+
try(ResultSet rs = dbmd.getTables(null,null,null,getTableFilter(database))){
791791
while (rs.next()) {
792792
tables.add(new Table(rs, dbmd));
793793
}
@@ -827,7 +827,7 @@ public String[] getTableNames() throws SQLException {
827827
try (Connection conn = getConnection()){
828828

829829
DatabaseMetaData dbmd = conn.getConnection().getMetaData();
830-
try (ResultSet rs = dbmd.getTables(null,null,null,new String[]{"TABLE"})){
830+
try (ResultSet rs = dbmd.getTables(null,null,null,getTableFilter(this))){
831831
while (rs.next()) {
832832
javaxt.utils.Record record = new javaxt.utils.Record();
833833
record.set("schema", rs.getString("TABLE_SCHEM"));
@@ -853,6 +853,22 @@ public String[] getTableNames() throws SQLException {
853853
}
854854

855855

856+
//**************************************************************************
857+
//** getTableFilter
858+
//**************************************************************************
859+
/** Returns a filter used to generate a list of tables via DatabaseMetaData
860+
*/
861+
private static String[] getTableFilter(Database database){
862+
if (database!=null){
863+
Driver driver = database.getDriver();
864+
if (driver!=null && driver.equals("PostgreSQL")){
865+
return new String[]{"TABLE", "FOREIGN TABLE"};
866+
}
867+
}
868+
return new String[]{"TABLE"};
869+
}
870+
871+
856872
//**************************************************************************
857873
//** getCatalogs
858874
//**************************************************************************

0 commit comments

Comments
 (0)