comparison src/main/java/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java @ 19:7acc09f59b21

Added missing scalar functions sql_max and sql_min to the lists returned by getNumericFunctions(), getStringFunctions() and getTimeDateFunctions().
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 13 Oct 2016 17:22:24 +0200 (2016-10-13)
parents 6e48d0fae766
children e8cced5f7283
comparison
equal deleted inserted replaced
18:8e57d20b5e80 19:7acc09f59b21
474 } 474 }
475 // for debug: System.out.println("SQL query: " + query + "\nResult string: " + sb.toString()); 475 // for debug: System.out.println("SQL query: " + query + "\nResult string: " + sb.toString());
476 return sb.toString(); 476 return sb.toString();
477 } 477 }
478 478
479 // SQL query parts shared in below four getXxxxFunctions() methods 479 // SQL query parts shared by four get<Type>Functions() below
480 private final static String FunctionsSelect = "SELECT DISTINCT \"name\" FROM \"sys\".\"functions\" "; 480 private final static String FunctionsSelect = "SELECT DISTINCT \"name\" FROM \"sys\".\"functions\" ";
481 private final static String FunctionsWhere = "WHERE \"id\" IN (SELECT \"func_id\" FROM \"sys\".\"args\" WHERE \"number\" = 1 AND \"name\" = 'arg_1' AND \"type\" IN "; 481 private final static String FunctionsWhere = "WHERE \"id\" IN (SELECT \"func_id\" FROM \"sys\".\"args\" WHERE \"number\" = 1 AND \"name\" = 'arg_1' AND \"type\" IN ";
482 // Scalar functions sql_max(x, y) and sql_min(x, y) are defined in sys.args only for type 'any'.
483 // Easiest way to include them in the Num, Str and TimeDate lists is to add them explicitly via UNION SQL:
484 private final static String AddFunctionsMaxMin = " UNION SELECT 'sql_max' UNION SELECT 'sql_min'";
485 private final static String FunctionsOrderBy1 = " ORDER BY 1";
482 486
483 @Override 487 @Override
484 public String getNumericFunctions() { 488 public String getNumericFunctions() {
485 String match = 489 String match =
486 "('tinyint', 'smallint', 'int', 'bigint', 'hugeint', 'decimal', 'double', 'real') )" + 490 "('tinyint', 'smallint', 'int', 'bigint', 'hugeint', 'decimal', 'double', 'real') )" +
487 // exclude functions which belong to the 'str' module 491 // exclude functions which belong to the 'str' module
488 " AND \"mod\" <> 'str'"; 492 " AND \"mod\" <> 'str'";
489 return getConcatenatedStringFromQuery(FunctionsSelect + FunctionsWhere + match + " ORDER BY 1"); 493 return getConcatenatedStringFromQuery(FunctionsSelect + FunctionsWhere + match + AddFunctionsMaxMin + FunctionsOrderBy1);
490 } 494 }
491 495
492 @Override 496 @Override
493 public String getStringFunctions() { 497 public String getStringFunctions() {
494 String match = 498 String match =
495 "('char', 'varchar', 'clob', 'json') )" + 499 "('char', 'varchar', 'clob', 'json') )" +
496 // include functions which belong to the 'str' module 500 // include functions which belong to the 'str' module
497 " OR \"mod\" = 'str'"; 501 " OR \"mod\" = 'str'";
498 return getConcatenatedStringFromQuery(FunctionsSelect + FunctionsWhere + match + " ORDER BY 1"); 502 return getConcatenatedStringFromQuery(FunctionsSelect + FunctionsWhere + match + AddFunctionsMaxMin + FunctionsOrderBy1);
499 } 503 }
500 504
501 @Override 505 @Override
502 public String getSystemFunctions() { 506 public String getSystemFunctions() {
503 String wherePart = 507 String wherePart =
510 " UNION SELECT 'coalesce'" + 514 " UNION SELECT 'coalesce'" +
511 " UNION SELECT 'extract'" + 515 " UNION SELECT 'extract'" +
512 " UNION SELECT 'ifthenelse'" + 516 " UNION SELECT 'ifthenelse'" +
513 " UNION SELECT 'isnull'" + 517 " UNION SELECT 'isnull'" +
514 " UNION SELECT 'nullif'"; 518 " UNION SELECT 'nullif'";
515 return getConcatenatedStringFromQuery(FunctionsSelect + wherePart + " ORDER BY 1"); 519 return getConcatenatedStringFromQuery(FunctionsSelect + wherePart + FunctionsOrderBy1);
516 } 520 }
517 521
518 @Override 522 @Override
519 public String getTimeDateFunctions() { 523 public String getTimeDateFunctions() {
520 String match = 524 String match =
521 "('date', 'time', 'timestamp', 'timetz', 'timestamptz', 'sec_interval', 'month_interval') )"; 525 "('date', 'time', 'timestamp', 'timetz', 'timestamptz', 'sec_interval', 'month_interval') )";
522 return getConcatenatedStringFromQuery(FunctionsSelect + FunctionsWhere + match + " ORDER BY 1"); 526 return getConcatenatedStringFromQuery(FunctionsSelect + FunctionsWhere + match + AddFunctionsMaxMin + FunctionsOrderBy1);
523 } 527 }
524 528
525 /** 529 /**
526 * This is the string that can be used to escape '_' and '%' in 530 * This is the string that can be used to escape '_' and '%' in
527 * a search string pattern style catalog search parameters 531 * a search string pattern style catalog search parameters