schemacrawler / SchemaCrawler

Free database schema discovery and comprehension tool
http://www.schemacrawler.com/
Other
1.62k stars 199 forks source link

Support for falling back to ResultSetMetaData #9

Closed n3integration closed 9 years ago

n3integration commented 9 years ago

We have seen cases where the underlying database will fail to fetch the database schema information (i.e. schemacrawler.schema.Table.getColumns()). In the case of failures, it would be nice to fall back to the ResultSetMetaData using a simple query. For example, something along the lines of SELECT * FROM 'table' WHERE 1 = 0 would suffice.

n3integration commented 9 years ago

Here is a sample stack trace:

schemacrawler.schemacrawler.SchemaCrawlerException: Could not retrieve columns for table bigdata.table: [Teradata Database] [TeraJDBC 15.00.00.20] [Error 5315] [SQLState HY000] The user does not have SELECT access to DBC.UDTInfo.TypeKind.
    at schemacrawler.crawl.SchemaCrawler.crawlTables(SchemaCrawler.java:499)
    at schemacrawler.crawl.SchemaCrawler.crawl(SchemaCrawler.java:553)
    at schemacrawler.utility.SchemaCrawlerUtility.getCatalog(SchemaCrawlerUtility.java:46)
        ...
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLException: [Teradata Database] [TeraJDBC 15.00.00.20] [Error 5315] [SQLState HY000] The user does not have SELECT access to DBC.UDTInfo.TypeKind.
    at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDatabaseSQLException(ErrorFactory.java:308)
    at com.teradata.jdbc.jdbc_4.statemachine.ReceiveInitSubState.action(ReceiveInitSubState.java:109)
    at com.teradata.jdbc.jdbc_4.statemachine.StatementReceiveState.subStateMachine(StatementReceiveState.java:307)
    at com.teradata.jdbc.jdbc_4.statemachine.StatementReceiveState.action(StatementReceiveState.java:196)
    at com.teradata.jdbc.jdbc_4.statemachine.StatementController.runBody(StatementController.java:123)
    at com.teradata.jdbc.jdbc_4.statemachine.StatementController.run(StatementController.java:114)
    at com.teradata.jdbc.jdbc_4.TDStatement.executeStatement(TDStatement.java:385)
    at com.teradata.jdbc.jdbc_4.TDStatement.executeStatement(TDStatement.java:327)
    at com.teradata.jdbc.jdbc_4.TDStatement.doNonPrepExecuteQuery(TDStatement.java:315)
    at com.teradata.jdbc.jdbc_4.TDStatement.executeQuery(TDStatement.java:1101)
    at com.teradata.jdbc.TeraDatabaseMetaData.getColumns(TeraDatabaseMetaData.java:3240)
    at schemacrawler.crawl.TableRetriever.retrieveColumns(TableRetriever.java:79)
    at schemacrawler.crawl.SchemaCrawler.crawlTables(SchemaCrawler.java:417)
    ... 12 more
schemacrawler commented 9 years ago

This is a database configuration issue, and can be fixed by giving the database user the appropriate permissions. For details, please see Unable to access application tables.

n3integration commented 9 years ago

We are currently working around the issue by falling back to the ResultSetMetaData and are happy to contribute back to SchemaCrawler for the benefit of the community. If you would prefer a PR rather than closing out the issue, let me know. Either way, thanks for all of your effort toward SchemaCrawler!