Skip to content

Commit

Permalink
Merge pull request #261 from EHDEN/scan-views
Browse files Browse the repository at this point in the history
Scan views for mssql, oracle, msaccess and teradata
  • Loading branch information
Maxim Moinat authored Aug 10, 2020
2 parents 309cbba + f205822 commit dca5419
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions rabbit-core/src/main/java/org/ohdsi/databases/RichConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,22 @@ public List<String> getTableNames(String database) {
if (dbType == DbType.MYSQL) {
query = "SHOW TABLES IN " + database;
} else if (dbType == DbType.MSSQL || dbType == DbType.PDW || dbType == DbType.AZURE) {
query = "SELECT CONCAT(schemas.name, '.', tables.name) FROM " + database + ".sys.tables INNER JOIN " + database + ".sys.schemas ON tables.schema_id = schemas.schema_id ORDER BY schemas.name, tables.name";
query = "SELECT CONCAT(schemas.name, '.', tables_views.name) FROM " +
"(SELECT schema_id, name FROM %1$s.sys.tables UNION ALL SELECT schema_id, name FROM %1$s.sys.views) tables_views " +
"INNER JOIN %1$s.sys.schemas ON tables_views.schema_id = schemas.schema_id " +
"ORDER BY schemas.name, tables_views.name";
query = String.format(query, database);
System.out.println(query);
} else if (dbType == DbType.ORACLE) {
query = "SELECT table_name FROM all_tables WHERE owner='" + database.toUpperCase() + "'";
query = "SELECT table_name FROM " +
"(SELECT table_name, owner FROM all_tables UNION ALL SELECT view_name, owner FROM all_views) tables_views " +
"WHERE owner='" + database.toUpperCase() + "'";
} else if (dbType == DbType.POSTGRESQL || dbType == DbType.REDSHIFT) {
query = "SELECT table_name FROM information_schema.tables WHERE table_schema = '" + database.toLowerCase() + "' ORDER BY table_name";
} else if (dbType == DbType.MSACCESS) {
query = "SELECT Name FROM sys.MSysObjects WHERE Type=1 AND Flags=0;";
query = "SELECT Name FROM sys.MSysObjects WHERE (Type=1 OR Type=5) AND Flags=0;";
} else if (dbType == DbType.TERADATA) {
query = "SELECT TableName from dbc.tables WHERE tablekind = 'T' and databasename='" + database + "'";
query = "SELECT TableName from dbc.tables WHERE tablekind IN ('T','V') and databasename='" + database + "'";
} else if (dbType == DbType.BIGQUERY) {
query = "SELECT table_name from " + database + ".INFORMATION_SCHEMA.TABLES ORDER BY table_name;";
}
Expand Down

0 comments on commit dca5419

Please sign in to comment.