comparison src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java @ 921:41d0cce6d2df

Use new con.checkMinimumDBVersion() method. Also used it in the implementation of getClientInfoProperties() as it queries new system table sys.clientinfo_properties. Optimised the used query in getClientInfoProperties() and added a default query returning no rows for older servers.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 25 Jul 2024 20:22:29 +0200 (8 months ago)
parents a8ca336e7f1a
children d416e9b6b3d0
comparison
equal deleted inserted replaced
920:ff7dbded88c8 921:41d0cce6d2df
467 ",'replicaclock','replicatick'" + // wlc/wlr functions 467 ",'replicaclock','replicatick'" + // wlc/wlr functions
468 ",'sql_max','sql_min','uuid')"; 468 ",'sql_max','sql_min','uuid')";
469 String unionPart = 469 String unionPart =
470 // add functions which are not listed in sys.functions but implemented in the SQL parser (see sql/server/sql_parser.y) 470 // add functions which are not listed in sys.functions but implemented in the SQL parser (see sql/server/sql_parser.y)
471 " UNION SELECT * FROM (VALUES('cast'),('coalesce'),('convert'),('ifnull'),('nullif')) as sf"; 471 " UNION SELECT * FROM (VALUES('cast'),('coalesce'),('convert'),('ifnull'),('nullif')) as sf";
472 try { 472 // from release 11.47.1 we support function: ifnull, but only with odbc escape notation, so {fn ifnull(null, 2)}. See issue: 6933.
473 // from release 11.47.1 we support function: ifnull, but only with odbc escape notation, so {fn ifnull(null, 2)}. See issue: 6933. 473 // from release 11.49.1 we support function: ifnull also without odbc escape notation.
474 // from release 11.49.1 we support function: ifnull also without odbc escape notation. 474 if (! con.checkMinimumDBVersion(11, 47))
475 if ((con.getDatabaseMajorVersion() == 11) && (con.getDatabaseMinorVersion() <= 45)) 475 // release 11.45 (Sep2022) or older did not support function: ifnull. remove it.
476 // release 11.45 (Sep2022) or older did not support function: ifnull. 476 unionPart = unionPart.replace(",('ifnull')", "");
477 unionPart = unionPart.replace(",('ifnull')", "");
478 } catch (SQLException e) { /* ignore */ }
479 return getConcatenatedStringFromQuery(FunctionsSelect + wherePart + unionPart + FunctionsOrderBy1); 477 return getConcatenatedStringFromQuery(FunctionsSelect + wherePart + unionPart + FunctionsOrderBy1);
480 } 478 }
481 479
482 @Override 480 @Override
483 public String getTimeDateFunctions() { 481 public String getTimeDateFunctions() {
941 * @return true if so 939 * @return true if so
942 */ 940 */
943 @Override 941 @Override
944 public boolean supportsIntegrityEnhancementFacility() { 942 public boolean supportsIntegrityEnhancementFacility() {
945 // Starting with release Aug2024 (11.51.1) MonetDB now also supports CHECK constraints (ref issue 3335, 3568). 943 // Starting with release Aug2024 (11.51.1) MonetDB now also supports CHECK constraints (ref issue 3335, 3568).
946 try { 944 return con.checkMinimumDBVersion(11, 51);
947 if ((con.getDatabaseMajorVersion() == 11) && (con.getDatabaseMinorVersion() >= 51))
948 return true;
949 } catch (SQLException e) { /* ignore */ }
950 return false; // for older servers
951 } 945 }
952 946
953 /** 947 /**
954 * Is some form of outer join supported? 948 * Is some form of outer join supported?
955 * 949 *
3920 * @return A ResultSet object; each row is a supported client info property 3914 * @return A ResultSet object; each row is a supported client info property
3921 * @throws SQLException if a database access error occurs 3915 * @throws SQLException if a database access error occurs
3922 */ 3916 */
3923 @Override 3917 @Override
3924 public ResultSet getClientInfoProperties() throws SQLException { 3918 public ResultSet getClientInfoProperties() throws SQLException {
3925 // This query combines the properties we know about with any additional properties that 3919 String query = "SELECT cast('' as varchar(40)) AS \"NAME\", cast(0 as int) AS \"MAX_LEN\", cast('' as varchar(128)) AS \"DEFAULT_VALUE\", cast('' as varchar(256)) AS \"DESCRIPTION\" WHERE 1=0";
3926 // may have been added to sys.clientinfo_properties in the mean time. 3920 // only MonetDB Server 11.51 (Aug2024) or higher supports table sys.clientinfo_properties
3927 final String query = 3921 if (con.checkMinimumDBVersion(11, 51)) {
3928 "WITH jdbc_info AS (\n" + 3922 // The query combines the 5 properties (added in Aug2024) we know about with
3929 " SELECT 'ApplicationName' AS \"NAME\", NULL AS \"MAX_LEN\", " + stringEscape(ClientInfo.defaultApplicationName) + " AS \"DEFAULT_VALUE\", 'Name of the application' AS \"DESCRIPTION\", 0 AS i\n" + 3923 // any additional properties that may have been added later to sys.clientinfo_properties table
3930 " UNION ALL\n" + 3924 query = "SELECT prop AS \"NAME\", cast(maxlen as int) AS \"MAX_LEN\", defval AS \"DEFAULT_VALUE\", descr AS \"DESCRIPTION\"" +
3931 " SELECT 'ClientHostname' AS \"NAME\", NULL AS \"MAX_LEN\", " + stringEscape(ClientInfo.defaultHostname) + " AS \"DEFAULT_VALUE\", 'Host the application is running on' AS \"DESCRIPTION\", 1 AS i\n" + 3925 " FROM sys.clientinfo_properties" +
3932 " UNION ALL\n" + 3926 " LEFT OUTER JOIN (VALUES " +
3933 " SELECT 'ClientRemark' AS \"NAME\", 256 AS \"MAX_LEN\", R'' AS \"DEFAULT_VALUE\", 'Additional information' AS \"DESCRIPTION\", 2 AS i\n" + 3927 "('ApplicationName',128," + stringEscape(ClientInfo.defaultApplicationName) + ",'Name of the application')," +
3934 " UNION ALL\n" + 3928 "('ClientHostname',128," + stringEscape(ClientInfo.defaultHostname) + ",'Host the application is running on')," +
3935 " SELECT 'ClientLibrary' AS \"NAME\", NULL AS \"MAX_LEN\", " + stringEscape(ClientInfo.defaultClientLibrary) + " AS \"DEFAULT_VALUE\", 'Name and version of the driver' AS \"DESCRIPTION\", 3 AS i\n" + 3929 "('ClientLibrary',128," + stringEscape(ClientInfo.defaultClientLibrary) + ",'Name and version of the driver')," +
3936 " UNION ALL\n" + 3930 "('ClientPid',19," + stringEscape(ClientInfo.defaultPid) + ",'Process id of the application')," +
3937 " SELECT 'ClientPid' AS \"NAME\", 10 AS \"MAX_LEN\", " + stringEscape(ClientInfo.defaultPid) + " AS \"DEFAULT_VALUE\", 'Process id of the application' AS \"DESCRIPTION\", 4 AS i\n" + 3931 "('ClientRemark',256,NULL,'Additional information')" +
3938 ")\n" + 3932 ") AS t(nm, maxlen, defval, descr) ON prop = nm" +
3939 "SELECT\n" + 3933 " ORDER BY 1";
3940 " prop AS \"NAME\",\n" + 3934 }
3941 " COALESCE(\"MAX_LEN\", 24) AS \"MAX_LEN\",\n" +
3942 " \"DEFAULT_VALUE\",\n" +
3943 " \"DESCRIPTION\"\n" +
3944 "FROM sys.clientinfo_properties AS sys_info LEFT OUTER JOIN jdbc_info ON prop = \"NAME\"\n" +
3945 "ORDER BY COALESCE(i, 1000), \"NAME\"\n"
3946 ;
3947
3948 return executeMetaDataQuery(query); 3935 return executeMetaDataQuery(query);
3949 } 3936 }
3950 3937
3951 private static String stringEscape(String s) { 3938 private static String stringEscape(String s) {
3952 return "R'" + s.replaceAll("'", "''") + "'"; 3939 return "R'" + s.replaceAll("'", "''") + "'";