Mercurial > hg > monetdb-java
diff src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java @ 215:71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
when connected to a MonetDB server which has table sys.comments.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 19 Apr 2018 16:13:01 +0200 (2018-04-19) |
parents | b8c007e86694 |
children | 4572f0694fde |
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java @@ -147,6 +147,11 @@ public class MonetConnection /** Whether or not CLOB is mapped to Types.VARCHAR instead of Types.CLOB within this connection */ private boolean treatClobAsVarChar = false; + // Internal cache for determining if system table sys.comments (new as of Mar2018 release) exists on server + private boolean queriedCommentsTable = false; + private boolean hasCommentsTable = false; + + /** * Constructor of a Connection for MonetDB. At this moment the * current implementation limits itself to storing the given host, @@ -1671,6 +1676,46 @@ public class MonetConnection } /** + * Internal utility method to query the server to find out if it has + * the system table sys.comments (which is new as of Mar2018 release). + * The result is cached and reused, so that we only test the query once per connection. + * This method is used by methods from MonetDatabaseMetaData. + */ + boolean commentsTableExists() { + if (queriedCommentsTable) + return hasCommentsTable; + + queriedCommentsTable = true; // set flag, so the querying part below is done only once, at first invocation. + Statement stmt = null; + ResultSet rs = null; + try { + stmt = createStatement(); + if (stmt != null) { + rs = stmt.executeQuery( "SELECT \"id\", \"remark\" FROM \"sys\".\"comments\" LIMIT 1"); + if (rs != null) { + rs.next(); + hasCommentsTable = true; + } + } + } catch (SQLException se) { + /* ignore */ + } finally { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { /* ignore */ } + } + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException e) { /* ignore */ } + } + } +// for debug: System.out.println("commentsTableExists returns: " + hasCommentsTable); + return hasCommentsTable; + } + + /** * Sends the given string to MonetDB as special transaction command. * All possible returned information is discarded. * Encountered errors are reported.