Mercurial > hg > monetdb-java
comparison src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java @ 734:e0caafa2d814
Extend getSystemFunctions() to also report system functions database() and ifnull() if they exist in sys.functions and can be called without odbc escape sequences.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 16 Feb 2023 15:32:48 +0100 (2023-02-16) |
parents | c6bea28cbce3 |
children | f317b37bad30 |
comparison
equal
deleted
inserted
replaced
733:c6bea28cbce3 | 734:e0caafa2d814 |
---|---|
431 // for debug: System.out.println("SQL (len " + query.length() + "): " + query + "\nResult string: " + sb.toString()); | 431 // for debug: System.out.println("SQL (len " + query.length() + "): " + query + "\nResult string: " + sb.toString()); |
432 return sb.toString(); | 432 return sb.toString(); |
433 } | 433 } |
434 | 434 |
435 // SQL query parts shared by four get<Type>Functions() below | 435 // SQL query parts shared by four get<Type>Functions() below |
436 private static final String FunctionsSelect = "SELECT DISTINCT CASE WHEN \"language\" > 0 THEN s.\"name\"||'.'||f.\"name\" ELSE f.\"name\" END FROM \"sys\".\"functions\" f JOIN \"sys\".\"schemas\" s ON f.\"schema_id\" = s.\"id\" WHERE "; | 436 private static final String FunctionsSelect = "SELECT DISTINCT CASE WHEN f.\"language\" > 0 THEN s.\"name\"||'.'||f.\"name\" ELSE f.\"name\" END" + |
437 " FROM \"sys\".\"functions\" f JOIN \"sys\".\"schemas\" s ON f.\"schema_id\" = s.\"id\" WHERE "; | |
437 private static final String FunctionsWhere = "(f.\"id\" IN (SELECT \"func_id\" FROM \"sys\".\"args\" WHERE \"number\" = 1 AND \"name\" = 'arg_1' AND \"type\" IN "; | 438 private static final String FunctionsWhere = "(f.\"id\" IN (SELECT \"func_id\" FROM \"sys\".\"args\" WHERE \"number\" = 1 AND \"name\" = 'arg_1' AND \"type\" IN "; |
438 // Scalar functions sql_max(x,y), sql_min(x,y), greatest(x,y) and least(x,y) are defined in sys.args for type 'any' and usable as num, str and timedate functions. | 439 // Scalar functions sql_max(x,y), sql_min(x,y), greatest(x,y) and least(x,y) are defined in sys.args for type 'any' and usable as num, str and timedate functions. |
439 private static final String OrFunctionsMaxMin = " OR f.\"name\" IN ('sql_max','sql_min','least','greatest')"; | 440 private static final String OrFunctionsMaxMin = " OR f.\"name\" IN ('sql_max','sql_min','least','greatest')"; |
440 private static final String FunctionsOrderBy1 = " ORDER BY 1"; | 441 private static final String FunctionsOrderBy1 = " ORDER BY 1"; |
441 | 442 |
469 } | 470 } |
470 | 471 |
471 @Override | 472 @Override |
472 public String getSystemFunctions() { | 473 public String getSystemFunctions() { |
473 final String wherePart = | 474 final String wherePart = |
474 "f.\"name\" IN ('columnsize','debug','get_value_for','hash','hashsize','heapsize'" + | 475 "f.\"name\" IN ('columnsize','database','debug','get_value_for','hash','hashsize','heapsize'" + |
475 ",'ifthenelse','imprintsize','isaurl','isauuid','isnull','masterclock','mastertick'" + | 476 ",'ifnull','ifthenelse','imprintsize','isaurl','isauuid','isnull','masterclock','mastertick'" + |
476 ",'newurl','next_value_for','password_hash','replicaclock','replicatick','uuid')" + | 477 ",'newurl','next_value_for','password_hash','replicaclock','replicatick','uuid')" + |
477 // add functions which are not listed in sys.functions but implemented in the SQL parser (see sql/server/sql_parser.y) | 478 // add functions which are not listed in sys.functions but implemented in the SQL parser (see sql/server/sql_parser.y) |
478 " UNION ALL SELECT * FROM (VALUES('cast'),('coalesce'),('convert'),('nullif')) as sf"; | 479 " UNION ALL SELECT * FROM (VALUES('cast'),('coalesce'),('convert'),('nullif')) as sf"; |
480 // ToDo: from release 11.47.1 we also support function: ifnull, but only with odbc escape notation, so {fn ifnull(null, 2)}. Related issue: 6933. | |
479 return getConcatenatedStringFromQuery(FunctionsSelect + wherePart + FunctionsOrderBy1); | 481 return getConcatenatedStringFromQuery(FunctionsSelect + wherePart + FunctionsOrderBy1); |
480 } | 482 } |
481 | 483 |
482 @Override | 484 @Override |
483 public String getTimeDateFunctions() { | 485 public String getTimeDateFunctions() { |
487 " OR f.\"name\" IN ('localtime','localtimestamp','date_trunc')"; | 489 " OR f.\"name\" IN ('localtime','localtimestamp','date_trunc')"; |
488 final String unionPart = | 490 final String unionPart = |
489 // add time date functions which are not listed in sys.functions but implemented in the SQL parser (see sql/server/sql_parser.y) | 491 // add time date functions which are not listed in sys.functions but implemented in the SQL parser (see sql/server/sql_parser.y) |
490 " UNION SELECT 'extract'" + | 492 " UNION SELECT 'extract'" + |
491 " UNION SELECT 'now'"; | 493 " UNION SELECT 'now'"; |
494 // ToDo: from release 11.47.1 we also support functions: dayname and monthname, but only with odbc escape notation, so {fn dayname(current_date)}. Related issue: 7300. | |
492 return getConcatenatedStringFromQuery(FunctionsSelect + wherePart + OrFunctionsMaxMin + unionPart + FunctionsOrderBy1); | 495 return getConcatenatedStringFromQuery(FunctionsSelect + wherePart + OrFunctionsMaxMin + unionPart + FunctionsOrderBy1); |
493 } | 496 } |
494 | 497 |
495 /** | 498 /** |
496 * This is the string that can be used to escape '_' and '%' in | 499 * This is the string that can be used to escape '_' and '%' in |