Skip to content

Commit

Permalink
[SQLLINE-183] Add wrapper around DatabaseMetaData, to make SQLLine le…
Browse files Browse the repository at this point in the history
…ss susceptible to errors in underlying JDBC driver

Wrapper uses reflection, and handles method-not-supported exceptions.
In future it could perhaps handle other exceptions, and do caching.

Add a test emulating hive behaviour with method not supported.

Add "strictJdbc" property to mark whether we should use default values
when hitting not-supported/not-implemented methods of DatabaseMetaData.
  • Loading branch information
snuyanzin authored and julianhyde committed Nov 19, 2018
1 parent 68bf5df commit e2c67fe
Show file tree
Hide file tree
Showing 14 changed files with 1,140 additions and 20 deletions.
10 changes: 10 additions & 0 deletions src/docbkx/manual.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3026,6 +3026,16 @@ java.sql.SQLException: ORA-00942: table or view does not exist
<literal>true</literal>.
</para>
</sect1>
<sect1 id="setting_silent">
<title>silent</title>
<para>
If <literal>false</literal>, then use default values
defined by <literal>java.sql.DatabaseMetaData</literal>
in case an implementation of this interface fails with
e.g. "Method not supported", otherwise it also fails.
Defaults to <literal>false</literal>.
</para>
</sect1>
<sect1 id="setting_silent">
<title>silent</title>
<para>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/sqlline/BuiltInProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public enum BuiltInProperty implements SqlLineProperty {
SHOW_HEADER("showHeader", Type.BOOLEAN, true),
SHOW_NESTED_ERRS("showNestedErrs", Type.BOOLEAN, false),
SHOW_WARNINGS("showWarnings", Type.BOOLEAN, true),
STRICT_JDBC("strictJdbc", Type.BOOLEAN, false),
TIME_FORMAT("timeFormat", Type.STRING, DEFAULT),
TIMEOUT("timeout", Type.INTEGER, -1),
TIMESTAMP_FORMAT("timestampFormat", Type.STRING, DEFAULT),
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/sqlline/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,12 @@ public void metadata(
return;
}

Object res = sqlLine.getReflector().invoke(sqlLine.getDatabaseMetaData(),
DatabaseMetaData.class, cmd, argList);
final Object res = sqlLine.getReflector()
.invoke(sqlLine.getDatabaseMetaData(), DatabaseMetaDataWrapper.class,
cmd, argList);
if (res instanceof ResultSet) {
ResultSet rs = (ResultSet) res;
try {
try (ResultSet rs = (ResultSet) res) {
sqlLine.print(rs, callback);
} finally {
rs.close();
}
} else if (res != null) {
sqlLine.output(res.toString());
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/sqlline/DatabaseConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class DatabaseConnection {
private final SqlLine sqlLine;
Connection connection;
DatabaseMetaData meta;
DatabaseMetaDataWrapper meta;
private final String driver;
private final String url;
private final Properties info;
Expand Down Expand Up @@ -128,7 +128,7 @@ boolean connect() throws SQLException {
// Instead, we use the driver instance to make the connection

connection = theDriver.connect(url, info);
meta = connection.getMetaData();
meta = new DatabaseMetaDataWrapper(sqlLine, connection.getMetaData());

try {
sqlLine.debug(
Expand Down Expand Up @@ -219,7 +219,7 @@ Schema getSchema() {
return schema;
}

DatabaseMetaData getDatabaseMetaData() {
DatabaseMetaDataWrapper getDatabaseMetaData() {
return meta;
}

Expand Down
Loading

0 comments on commit e2c67fe

Please sign in to comment.