comparison src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java @ 755:99ff3cd9f4f0

Corrected DatabaseMetaData method getStringFunctions() when connected to a Jun2023 server. It now includes the string functions from the new txtsim module.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 04 May 2023 01:28:52 +0200 (2023-05-03)
parents f317b37bad30
children 7f68120de37c
comparison
equal deleted inserted replaced
754:b6eb51cb5cee 755:99ff3cd9f4f0
406 * Internal utility method getConcatenatedStringFromQuery(String query) 406 * Internal utility method getConcatenatedStringFromQuery(String query)
407 * @param query the SQL SELECT query. Only the output of the first column is fetched and concatenated. 407 * @param query the SQL SELECT query. Only the output of the first column is fetched and concatenated.
408 * @return a String of query result values concatenated into one string, and values separated by comma's 408 * @return a String of query result values concatenated into one string, and values separated by comma's
409 */ 409 */
410 private String getConcatenatedStringFromQuery(final String query) { 410 private String getConcatenatedStringFromQuery(final String query) {
411 final StringBuilder sb = new StringBuilder(1024); 411 final StringBuilder sb = new StringBuilder(1200);
412 Statement st = null; 412 Statement st = null;
413 ResultSet rs = null; 413 ResultSet rs = null;
414 try { 414 try {
415 st = con.createStatement(); 415 st = con.createStatement();
416 rs = st.executeQuery(query); 416 rs = st.executeQuery(query);
430 } catch (SQLException e) { 430 } catch (SQLException e) {
431 /* ignore */ 431 /* ignore */
432 } finally { 432 } finally {
433 MonetConnection.closeResultsetStatement(rs, st); 433 MonetConnection.closeResultsetStatement(rs, st);
434 } 434 }
435 // for debug: System.out.println("SQL (len " + query.length() + "): " + query + "\nResult string: " + sb.toString()); 435 // for debug: System.out.println("SQL (len " + query.length() + "): " + query + "\nResult string(len " + sb.length() + "): " + sb.toString());
436 return sb.toString(); 436 return sb.toString();
437 } 437 }
438 438
439 // SQL query parts shared by four get<Type>Functions() below 439 // SQL query parts shared by four get<Type>Functions() below
440 private static final String FunctionsSelect = "SELECT DISTINCT CASE WHEN f.\"language\" > 0 THEN s.\"name\"||'.'||f.\"name\" ELSE f.\"name\" END" + 440 private static final String FunctionsSelect = "SELECT DISTINCT CASE WHEN f.\"language\" > 0 THEN s.\"name\"||'.'||f.\"name\" ELSE f.\"name\" END" +
462 "('char','varchar','clob','json','url'))" + 462 "('char','varchar','clob','json','url'))" +
463 " AND \"type\" = 1" + // only scalar functions 463 " AND \"type\" = 1" + // only scalar functions
464 // exclude sql functions: get_value_for, next_value_for, restart 464 // exclude sql functions: get_value_for, next_value_for, restart
465 " AND \"mod\" <> 'sql')" + 465 " AND \"mod\" <> 'sql')" +
466 // include specific functions code(int) and space(int) which belong to the 'str' module 466 // include specific functions code(int) and space(int) which belong to the 'str' module
467 " OR \"mod\" = 'str'" + 467 // include functions (difference, editdistance, editdistance2, levenshtein, qgramnormalize, similarity, soundex) which since Jun2023 are in the 'txtsim' module
468 // include 3 specific json functions, md5(), ms_stuff() and udf reverse() which all accept a string arg 468 " OR (\"mod\" IN ('str','txtsim') AND \"type\" = 1)" +
469 // include 3 specific json functions and md5(), ms_stuff() and udf reverse() which all accept a string arg
469 " OR f.\"name\" IN ('isarray','isobject','isvalid','md5','ms_stuff','reverse')"; 470 " OR f.\"name\" IN ('isarray','isobject','isvalid','md5','ms_stuff','reverse')";
470 final String unionPart = 471 final String unionPart =
471 // add functions which are not listed in sys.functions but implemented in the SQL parser (see sql/server/sql_parser.y) 472 // add functions which are not listed in sys.functions but implemented in the SQL parser (see sql/server/sql_parser.y)
472 " UNION SELECT 'position'"; 473 " UNION SELECT 'position'";
473 return getConcatenatedStringFromQuery(FunctionsSelect + FunctionsWhere + match + OrFunctionsMaxMin + unionPart + FunctionsOrderBy1); 474 return getConcatenatedStringFromQuery(FunctionsSelect + FunctionsWhere + match + OrFunctionsMaxMin + unionPart + FunctionsOrderBy1);