comparison src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java @ 759:846a456f0f0c

Remove append() calls for static int values in construction of Strings. They are not needed as javac can inline those static values.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 29 Jun 2023 15:54:08 +0200 (22 months ago)
parents 7f68120de37c
children e1389c0ffb7c
comparison
equal deleted inserted replaced
758:37eae5a78c1b 759:846a456f0f0c
1697 "cast(null as char(1)) AS \"Field4\", " + 1697 "cast(null as char(1)) AS \"Field4\", " +
1698 "cast(null as char(1)) AS \"Field5\", " + 1698 "cast(null as char(1)) AS \"Field5\", " +
1699 "cast(null as char(1)) AS \"Field6\", ") 1699 "cast(null as char(1)) AS \"Field6\", ")
1700 .append(useCommentsTable ? "COALESCE(cm.\"remark\", cast(f.\"func\" as varchar(9999)))" : "cast(f.\"func\" as varchar(9999))").append(" AS \"REMARKS\", " + 1700 .append(useCommentsTable ? "COALESCE(cm.\"remark\", cast(f.\"func\" as varchar(9999)))" : "cast(f.\"func\" as varchar(9999))").append(" AS \"REMARKS\", " +
1701 // in MonetDB procedures have no return value by design. 1701 // in MonetDB procedures have no return value by design.
1702 "cast(").append(DatabaseMetaData.procedureNoResult).append(" AS smallint) AS \"PROCEDURE_TYPE\", " + 1702 "cast(" + DatabaseMetaData.procedureNoResult + " AS smallint) AS \"PROCEDURE_TYPE\", " +
1703 // only the id value uniquely identifies a procedure. Include it to be able to differentiate between multiple overloaded procedures with the same name 1703 // only the id value uniquely identifies a procedure. Include it to be able to differentiate between multiple overloaded procedures with the same name
1704 "cast(f.\"id\" as varchar(10)) AS \"SPECIFIC_NAME\" " + 1704 "cast(f.\"id\" as varchar(10)) AS \"SPECIFIC_NAME\" " +
1705 "FROM \"sys\".\"functions\" f JOIN \"sys\".\"schemas\" s ON f.\"schema_id\" = s.\"id\" "); 1705 "FROM \"sys\".\"functions\" f " +
1706 "JOIN \"sys\".\"schemas\" s ON f.\"schema_id\" = s.\"id\" ");
1706 if (useCommentsTable) { 1707 if (useCommentsTable) {
1707 query.append("LEFT OUTER JOIN \"sys\".\"comments\" cm ON f.\"id\" = cm.\"id\" "); 1708 query.append("LEFT OUTER JOIN \"sys\".\"comments\" cm ON f.\"id\" = cm.\"id\" ");
1708 } 1709 }
1709 // include procedures only (type = 2). Others will be returned via getFunctions() 1710 // include procedures only (type = 2). Others will be returned via getFunctions()
1710 query.append("WHERE f.\"type\" = 2"); 1711 query.append("WHERE f.\"type\" = 2");
1806 query.append("SELECT cast(null as char(1)) AS \"PROCEDURE_CAT\", " + 1807 query.append("SELECT cast(null as char(1)) AS \"PROCEDURE_CAT\", " +
1807 "s.\"name\" AS \"PROCEDURE_SCHEM\", " + 1808 "s.\"name\" AS \"PROCEDURE_SCHEM\", " +
1808 "f.\"name\" AS \"PROCEDURE_NAME\", " + 1809 "f.\"name\" AS \"PROCEDURE_NAME\", " +
1809 "a.\"name\" AS \"COLUMN_NAME\", " + 1810 "a.\"name\" AS \"COLUMN_NAME\", " +
1810 "cast(CASE a.\"inout\"" + 1811 "cast(CASE a.\"inout\"" +
1811 " WHEN 0 THEN (CASE a.\"number\" WHEN 0 THEN ").append(DatabaseMetaData.procedureColumnReturn).append(" ELSE ").append(DatabaseMetaData.procedureColumnOut).append(" END)" + 1812 " WHEN 0 THEN (CASE a.\"number\" WHEN 0 THEN " + DatabaseMetaData.procedureColumnReturn + " ELSE " + DatabaseMetaData.procedureColumnOut + " END)" +
1812 " WHEN 1 THEN ").append(DatabaseMetaData.procedureColumnIn) 1813 " WHEN 1 THEN " + DatabaseMetaData.procedureColumnIn +
1813 .append(" ELSE ").append(DatabaseMetaData.procedureColumnUnknown).append(" END AS smallint) AS \"COLUMN_TYPE\", " + 1814 " ELSE " + DatabaseMetaData.procedureColumnUnknown + " END AS smallint) AS \"COLUMN_TYPE\", " +
1814 "cast(").append(MonetDriver.getSQLTypeMap("a.\"type\"")).append(" AS int) AS \"DATA_TYPE\", " + 1815 "cast(").append(MonetDriver.getSQLTypeMap("a.\"type\"")).append(" AS int) AS \"DATA_TYPE\", " +
1815 "a.\"type\" AS \"TYPE_NAME\", " + 1816 "a.\"type\" AS \"TYPE_NAME\", " +
1816 "CASE a.\"type\" WHEN 'tinyint' THEN 3 WHEN 'smallint' THEN 5 WHEN 'int' THEN 10 WHEN 'bigint' THEN 19" + 1817 "CASE a.\"type\" WHEN 'tinyint' THEN 3 WHEN 'smallint' THEN 5 WHEN 'int' THEN 10 WHEN 'bigint' THEN 19" +
1817 " WHEN 'hugeint' THEN 38 WHEN 'oid' THEN 19 WHEN 'wrd' THEN 19 ELSE a.\"type_digits\" END AS \"PRECISION\", " + 1818 " WHEN 'hugeint' THEN 38 WHEN 'oid' THEN 19 WHEN 'wrd' THEN 19 ELSE a.\"type_digits\" END AS \"PRECISION\", " +
1818 "CASE a.\"type\" WHEN 'tinyint' THEN 1 WHEN 'smallint' THEN 2 WHEN 'int' THEN 4 WHEN 'bigint' THEN 8" + 1819 "CASE a.\"type\" WHEN 'tinyint' THEN 1 WHEN 'smallint' THEN 2 WHEN 'int' THEN 4 WHEN 'bigint' THEN 8" +
1819 " WHEN 'hugeint' THEN 16 WHEN 'oid' THEN 8 WHEN 'wrd' THEN 8 ELSE a.\"type_digits\" END AS \"LENGTH\", " + 1820 " WHEN 'hugeint' THEN 16 WHEN 'oid' THEN 8 WHEN 'wrd' THEN 8 ELSE a.\"type_digits\" END AS \"LENGTH\", " +
1820 "cast(CASE WHEN a.\"type\" IN ('tinyint','smallint','int','bigint','hugeint','oid','wrd','decimal','numeric'," + 1821 "cast(CASE WHEN a.\"type\" IN ('tinyint','smallint','int','bigint','hugeint','oid','wrd','decimal','numeric'," +
1821 "'time','timetz','timestamp','timestamptz','day_interval','month_interval','sec_interval') THEN a.\"type_scale\" ELSE NULL END AS smallint) AS \"SCALE\", " + 1822 "'time','timetz','timestamp','timestamptz','day_interval','month_interval','sec_interval') THEN a.\"type_scale\" ELSE NULL END AS smallint) AS \"SCALE\", " +
1822 "cast(CASE WHEN a.\"type\" IN ('tinyint','smallint','int','bigint','hugeint','oid','wrd','decimal','numeric','day_interval','month_interval','sec_interval') THEN 10" + 1823 "cast(CASE WHEN a.\"type\" IN ('tinyint','smallint','int','bigint','hugeint','oid','wrd','decimal','numeric','day_interval','month_interval','sec_interval') THEN 10" +
1823 " WHEN a.\"type\" IN ('real','float','double') THEN 2 ELSE NULL END AS smallint) AS \"RADIX\", " + 1824 " WHEN a.\"type\" IN ('real','float','double') THEN 2 ELSE NULL END AS smallint) AS \"RADIX\", " +
1825 // mvd: do not remove next append. The String above is same as used by getFunctionColumns, so shared in class file.
1824 "cast(").append(DatabaseMetaData.procedureNullableUnknown).append(" AS smallint) AS \"NULLABLE\", " + 1826 "cast(").append(DatabaseMetaData.procedureNullableUnknown).append(" AS smallint) AS \"NULLABLE\", " +
1825 "cast(null as char(1)) AS \"REMARKS\", " + 1827 "cast(null as char(1)) AS \"REMARKS\", " +
1826 "cast(null as char(1)) AS \"COLUMN_DEF\", " + 1828 "cast(null as char(1)) AS \"COLUMN_DEF\", " +
1827 "cast(0 as int) AS \"SQL_DATA_TYPE\", " + 1829 "cast(0 as int) AS \"SQL_DATA_TYPE\", " +
1828 "cast(0 as int) AS \"SQL_DATETIME_SUB\", " + 1830 "cast(0 as int) AS \"SQL_DATETIME_SUB\", " +
2175 "cast(0 as int) AS \"BUFFER_LENGTH\", " + 2177 "cast(0 as int) AS \"BUFFER_LENGTH\", " +
2176 "c.\"type_scale\" AS \"DECIMAL_DIGITS\", " + 2178 "c.\"type_scale\" AS \"DECIMAL_DIGITS\", " +
2177 "cast(CASE WHEN c.\"type\" IN ('decimal','numeric','day_interval','month_interval','sec_interval') THEN 10 " + 2179 "cast(CASE WHEN c.\"type\" IN ('decimal','numeric','day_interval','month_interval','sec_interval') THEN 10 " +
2178 "WHEN c.\"type\" IN ('int','smallint','tinyint','bigint','hugeint','float','real','double','oid','wrd') THEN 2 " + 2180 "WHEN c.\"type\" IN ('int','smallint','tinyint','bigint','hugeint','float','real','double','oid','wrd') THEN 2 " +
2179 "ELSE 0 END AS int) AS \"NUM_PREC_RADIX\", " + 2181 "ELSE 0 END AS int) AS \"NUM_PREC_RADIX\", " +
2180 "cast(CASE c.\"null\" WHEN true THEN ").append(ResultSetMetaData.columnNullable) 2182 "cast(CASE c.\"null\" WHEN true THEN " + ResultSetMetaData.columnNullable +
2181 .append(" WHEN false THEN ").append(ResultSetMetaData.columnNoNulls) 2183 " WHEN false THEN " + ResultSetMetaData.columnNoNulls +
2182 .append(" ELSE ").append(ResultSetMetaData.columnNullableUnknown) 2184 " ELSE " + ResultSetMetaData.columnNullableUnknown +
2183 .append(" END AS int) AS \"NULLABLE\", ") 2185 " END AS int) AS \"NULLABLE\", ")
2184 .append(useCommentsTable ? "cm.\"remark\"" : "cast(null AS varchar(9999))").append(" AS \"REMARKS\", " + 2186 .append(useCommentsTable ? "cm.\"remark\"" : "cast(null AS varchar(9999))").append(" AS \"REMARKS\", " +
2185 "c.\"default\" AS \"COLUMN_DEF\", " + 2187 "c.\"default\" AS \"COLUMN_DEF\", " +
2186 "cast(0 as int) AS \"SQL_DATA_TYPE\", " + 2188 "cast(0 as int) AS \"SQL_DATA_TYPE\", " +
2187 "cast(0 as int) AS \"SQL_DATETIME_SUB\", " + 2189 "cast(0 as int) AS \"SQL_DATETIME_SUB\", " +
2188 "cast(CASE WHEN c.\"type\" IN ('char','varchar','clob') THEN c.\"type_digits\" ELSE NULL END as int) AS \"CHAR_OCTET_LENGTH\", " + 2190 "cast(CASE WHEN c.\"type\" IN ('char','varchar','clob') THEN c.\"type_digits\" ELSE NULL END as int) AS \"CHAR_OCTET_LENGTH\", " +
2493 // 3rd cte: tableids 2495 // 3rd cte: tableids
2494 query.append(", tableids as (" + 2496 query.append(", tableids as (" +
2495 "SELECT t.\"id\" " + 2497 "SELECT t.\"id\" " +
2496 "FROM \"sys\".\"tables\" t " + 2498 "FROM \"sys\".\"tables\" t " +
2497 "JOIN \"sys\".\"schemas\" s ON t.\"schema_id\" = s.\"id\" " + 2499 "JOIN \"sys\".\"schemas\" s ON t.\"schema_id\" = s.\"id\" " +
2498 "WHERE t.\"type\" NOT IN (1, 11) "); // exclude all VIEWs and SYSTEM VIEWs 2500 "WHERE t.\"type\" NOT IN (1, 11)"); // exclude all VIEWs and SYSTEM VIEWs
2499 if (catalog != null && !catalog.isEmpty()) { 2501 if (catalog != null && !catalog.isEmpty()) {
2500 // non-empty catalog selection. 2502 // non-empty catalog selection.
2501 // as we do not support catalogs this always results in no rows returned 2503 // as we do not support catalogs this always results in no rows returned
2502 query.append("AND 1=0"); 2504 query.append(" AND 1=0");
2503 } else { 2505 } else {
2504 if (scope == DatabaseMetaData.bestRowSession 2506 if (scope == DatabaseMetaData.bestRowSession
2505 || scope == DatabaseMetaData.bestRowTransaction 2507 || scope == DatabaseMetaData.bestRowTransaction
2506 || scope == DatabaseMetaData.bestRowTemporary) { 2508 || scope == DatabaseMetaData.bestRowTemporary) {
2507 if (schema != null) { 2509 if (schema != null) {
2508 // do not allow wildcard matching with LIKE, as the resultset does not include the schema info 2510 // do not allow wildcard matching with LIKE, as the resultset does not include the schema info
2509 query.append("AND s.\"name\" = ").append(MonetWrapper.sq(schema)); 2511 query.append(" AND s.\"name\" = ").append(MonetWrapper.sq(schema));
2510 } 2512 }
2511 if (table != null) { 2513 if (table != null) {
2512 // do not allow wildcard matching with LIKE, as the resultset does not include the table info 2514 // do not allow wildcard matching with LIKE, as the resultset does not include the table info
2513 query.append(" AND t.\"name\" = ").append(MonetWrapper.sq(table)); 2515 query.append(" AND t.\"name\" = ").append(MonetWrapper.sq(table));
2514 } 2516 }
2515 } else { 2517 } else {
2516 query.append("AND 1=0"); 2518 query.append(" AND 1=0");
2517 } 2519 }
2518 } 2520 }
2519 // 4th cte: cols, this unions 2 (or 4 when incltmpkey == true) select queries 2521 // 4th cte: cols, this unions 2 (or 4 when incltmpkey == true) select queries
2520 query.append("), cols as (" + 2522 query.append("), cols as (" +
2521 "SELECT c.\"name\", c.\"type\", c.\"type_digits\", c.\"type_scale\", o.\"nr\" " + 2523 "SELECT c.\"name\", c.\"type\", c.\"type_digits\", c.\"type_scale\", o.\"nr\" " +
2559 query.append(" AND c.\"null\" = false"); 2561 query.append(" AND c.\"null\" = false");
2560 } 2562 }
2561 } 2563 }
2562 // the final select query 2564 // the final select query
2563 query.append(") SELECT " + 2565 query.append(") SELECT " +
2564 "cast(").append(DatabaseMetaData.bestRowSession).append(" AS smallint) AS \"SCOPE\", " + 2566 "cast(" + DatabaseMetaData.bestRowSession + " AS smallint) AS \"SCOPE\", " +
2565 "c.\"name\" AS \"COLUMN_NAME\", " + 2567 "c.\"name\" AS \"COLUMN_NAME\", " +
2566 "cast(").append(MonetDriver.getSQLTypeMap("c.\"type\"")).append(" AS int) AS \"DATA_TYPE\", " + 2568 "cast(").append(MonetDriver.getSQLTypeMap("c.\"type\"")).append(" AS int) AS \"DATA_TYPE\", " +
2567 "c.\"type\" AS \"TYPE_NAME\", " + 2569 "c.\"type\" AS \"TYPE_NAME\", " +
2568 "c.\"type_digits\" AS \"COLUMN_SIZE\", " + 2570 "c.\"type_digits\" AS \"COLUMN_SIZE\", " +
2569 "cast(0 as int) AS \"BUFFER_LENGTH\", " + 2571 "cast(0 as int) AS \"BUFFER_LENGTH\", " +
2570 "cast(c.\"type_scale\" AS smallint) AS \"DECIMAL_DIGITS\", " + 2572 "cast(c.\"type_scale\" AS smallint) AS \"DECIMAL_DIGITS\", " +
2571 "cast(").append(DatabaseMetaData.bestRowNotPseudo).append(" AS smallint) AS \"PSEUDO_COLUMN\" " + 2573 "cast(" + DatabaseMetaData.bestRowNotPseudo + " AS smallint) AS \"PSEUDO_COLUMN\" " +
2572 "FROM cols c " + 2574 "FROM cols c " +
2573 "ORDER BY \"SCOPE\", c.\"nr\", \"COLUMN_NAME\""); 2575 "ORDER BY \"SCOPE\", c.\"nr\", \"COLUMN_NAME\"");
2574 2576
2575 return executeMetaDataQuery(query.toString()); 2577 return executeMetaDataQuery(query.toString());
2576 } 2578 }
3097 " ELSE NULL END AS varchar(2)) AS \"LITERAL_SUFFIX\", " + 3099 " ELSE NULL END AS varchar(2)) AS \"LITERAL_SUFFIX\", " +
3098 "CASE WHEN \"sqlname\" IN ('char','varchar') THEN 'max length'" + 3100 "CASE WHEN \"sqlname\" IN ('char','varchar') THEN 'max length'" +
3099 " WHEN \"sqlname\" = 'decimal' THEN 'precision, scale'" + 3101 " WHEN \"sqlname\" = 'decimal' THEN 'precision, scale'" +
3100 " WHEN \"sqlname\" IN ('time','timetz','timestamp','timestamptz','sec_interval') THEN 'precision'" + 3102 " WHEN \"sqlname\" IN ('time','timetz','timestamp','timestamptz','sec_interval') THEN 'precision'" +
3101 " ELSE NULL END AS \"CREATE_PARAMS\", " + 3103 " ELSE NULL END AS \"CREATE_PARAMS\", " +
3102 "cast(CASE WHEN \"systemname\" = 'oid' THEN ").append(DatabaseMetaData.typeNoNulls) 3104 "cast(CASE WHEN \"systemname\" = 'oid' THEN " + DatabaseMetaData.typeNoNulls +
3103 .append(" ELSE ").append(DatabaseMetaData.typeNullable).append(" END AS smallint) AS \"NULLABLE\", " + 3105 " ELSE " + DatabaseMetaData.typeNullable + " END AS smallint) AS \"NULLABLE\", " +
3104 "CASE WHEN \"systemname\" IN ('str','json','url','xml') THEN true ELSE false END AS \"CASE_SENSITIVE\", " + 3106 "CASE WHEN \"systemname\" IN ('str','json','url','xml') THEN true ELSE false END AS \"CASE_SENSITIVE\", " +
3105 "cast(CASE WHEN \"systemname\" IN ('str','inet','json','url','uuid','xml') THEN ").append(DatabaseMetaData.typeSearchable) 3107 "cast(CASE WHEN \"systemname\" IN ('str','inet','json','url','uuid','xml') THEN " + DatabaseMetaData.typeSearchable +
3106 .append(" ELSE ").append(DatabaseMetaData.typePredBasic).append(" END AS smallint) AS \"SEARCHABLE\", " + 3108 " ELSE " + DatabaseMetaData.typePredBasic + " END AS smallint) AS \"SEARCHABLE\", " +
3107 "CASE WHEN \"sqlname\" IN ('tinyint','smallint','int','bigint','hugeint','decimal','real','double'" + 3109 "CASE WHEN \"sqlname\" IN ('tinyint','smallint','int','bigint','hugeint','decimal','real','double'" +
3108 ",'day_interval','month_interval','sec_interval') THEN false ELSE true END AS \"UNSIGNED_ATTRIBUTE\", " + 3110 ",'day_interval','month_interval','sec_interval') THEN false ELSE true END AS \"UNSIGNED_ATTRIBUTE\", " +
3109 "CASE \"sqlname\" WHEN 'decimal' THEN true ELSE false END AS \"FIXED_PREC_SCALE\", " + 3111 "CASE \"sqlname\" WHEN 'decimal' THEN true ELSE false END AS \"FIXED_PREC_SCALE\", " +
3110 "CASE WHEN \"sqlname\" IN ('tinyint','smallint','int','bigint') THEN true ELSE false END AS \"AUTO_INCREMENT\", " + 3112 "CASE WHEN \"sqlname\" IN ('tinyint','smallint','int','bigint') THEN true ELSE false END AS \"AUTO_INCREMENT\", " +
3111 "CASE WHEN \"sqlname\" IN ('sec_interval','day_interval','month_interval') THEN \"sqlname\" ELSE \"systemname\" END AS \"LOCAL_TYPE_NAME\", " + 3113 "CASE WHEN \"sqlname\" IN ('sec_interval','day_interval','month_interval') THEN \"sqlname\" ELSE \"systemname\" END AS \"LOCAL_TYPE_NAME\", " +
3210 "s.\"name\" AS \"TABLE_SCHEM\", " + 3212 "s.\"name\" AS \"TABLE_SCHEM\", " +
3211 "t.\"name\" AS \"TABLE_NAME\", " + 3213 "t.\"name\" AS \"TABLE_NAME\", " +
3212 "CASE WHEN k.\"name\" IS NULL THEN true ELSE false END AS \"NON_UNIQUE\", " + 3214 "CASE WHEN k.\"name\" IS NULL THEN true ELSE false END AS \"NON_UNIQUE\", " +
3213 "cast(null AS char(1)) AS \"INDEX_QUALIFIER\", " + 3215 "cast(null AS char(1)) AS \"INDEX_QUALIFIER\", " +
3214 "i.\"name\" AS \"INDEX_NAME\", " + 3216 "i.\"name\" AS \"INDEX_NAME\", " +
3215 "CASE i.\"type\" WHEN 0 THEN ").append(DatabaseMetaData.tableIndexHashed).append(" ELSE ").append(DatabaseMetaData.tableIndexOther).append(" END AS \"TYPE\", " + 3217 "CASE i.\"type\" WHEN 0 THEN " + DatabaseMetaData.tableIndexHashed + " ELSE " + DatabaseMetaData.tableIndexOther + " END AS \"TYPE\", " +
3216 "cast(o.\"nr\" +1 AS smallint) AS \"ORDINAL_POSITION\", "+ 3218 "cast(o.\"nr\" +1 AS smallint) AS \"ORDINAL_POSITION\", "+
3217 "c.\"name\" AS \"COLUMN_NAME\", " + 3219 "c.\"name\" AS \"COLUMN_NAME\", " +
3218 "cast(null AS char(1)) AS \"ASC_OR_DESC\", " + // sort sequence currently not supported in keys or indexes in MonetDB 3220 "cast(null AS char(1)) AS \"ASC_OR_DESC\", " + // sort sequence currently not supported in keys or indexes in MonetDB
3219 "cast(").append(table_row_count).append(" AS int) AS \"CARDINALITY\", " + 3221 "cast(").append(table_row_count).append(" AS int) AS \"CARDINALITY\", " +
3220 "cast(0 AS int) AS \"PAGES\", " + 3222 "cast(0 AS int) AS \"PAGES\", " +
3257 "s.\"name\" AS \"TABLE_SCHEM\", " + 3259 "s.\"name\" AS \"TABLE_SCHEM\", " +
3258 "t.\"name\" AS \"TABLE_NAME\", " + 3260 "t.\"name\" AS \"TABLE_NAME\", " +
3259 "CASE WHEN k.\"name\" IS NULL THEN true ELSE false END AS \"NON_UNIQUE\", " + 3261 "CASE WHEN k.\"name\" IS NULL THEN true ELSE false END AS \"NON_UNIQUE\", " +
3260 "cast(null AS char(1)) AS \"INDEX_QUALIFIER\", " + 3262 "cast(null AS char(1)) AS \"INDEX_QUALIFIER\", " +
3261 "i.\"name\" AS \"INDEX_NAME\", " + 3263 "i.\"name\" AS \"INDEX_NAME\", " +
3262 "CASE i.\"type\" WHEN 0 THEN ").append(DatabaseMetaData.tableIndexHashed).append(" ELSE ").append(DatabaseMetaData.tableIndexOther).append(" END AS \"TYPE\", " + 3264 "CASE i.\"type\" WHEN 0 THEN " + DatabaseMetaData.tableIndexHashed + " ELSE " + DatabaseMetaData.tableIndexOther + " END AS \"TYPE\", " +
3263 "cast(o.\"nr\" +1 AS smallint) AS \"ORDINAL_POSITION\", "+ 3265 "cast(o.\"nr\" +1 AS smallint) AS \"ORDINAL_POSITION\", "+
3264 "c.\"name\" AS \"COLUMN_NAME\", " + 3266 "c.\"name\" AS \"COLUMN_NAME\", " +
3265 "cast(null AS char(1)) AS \"ASC_OR_DESC\", " + // sort sequence currently not supported in keys or indexes in MonetDB 3267 "cast(null AS char(1)) AS \"ASC_OR_DESC\", " + // sort sequence currently not supported in keys or indexes in MonetDB
3266 "cast(").append(table_row_count).append(" AS int) AS \"CARDINALITY\", " + 3268 "cast(").append(table_row_count).append(" AS int) AS \"CARDINALITY\", " +
3267 "cast(0 AS int) AS \"PAGES\", " + 3269 "cast(0 AS int) AS \"PAGES\", " +
3975 final StringBuilder query = new StringBuilder(800); 3977 final StringBuilder query = new StringBuilder(800);
3976 query.append("SELECT cast(null as char(1)) AS \"FUNCTION_CAT\", " + 3978 query.append("SELECT cast(null as char(1)) AS \"FUNCTION_CAT\", " +
3977 "s.\"name\" AS \"FUNCTION_SCHEM\", " + 3979 "s.\"name\" AS \"FUNCTION_SCHEM\", " +
3978 "f.\"name\" AS \"FUNCTION_NAME\", ") 3980 "f.\"name\" AS \"FUNCTION_NAME\", ")
3979 .append(useCommentsTable ? "COALESCE(cm.\"remark\", cast(f.\"func\" as varchar(9999)))" : "cast(f.\"func\" as varchar(9999))").append(" AS \"REMARKS\", " + 3981 .append(useCommentsTable ? "COALESCE(cm.\"remark\", cast(f.\"func\" as varchar(9999)))" : "cast(f.\"func\" as varchar(9999))").append(" AS \"REMARKS\", " +
3980 "CASE WHEN f.\"type\" IN (1,2,3,4,6) THEN ").append(DatabaseMetaData.functionNoTable) 3982 "CASE WHEN f.\"type\" IN (1,2,3,4,6) THEN " + DatabaseMetaData.functionNoTable +
3981 .append(" WHEN f.\"type\" IN (5,7) THEN ").append(DatabaseMetaData.functionReturnsTable) 3983 " WHEN f.\"type\" IN (5,7) THEN " + DatabaseMetaData.functionReturnsTable +
3982 .append(" ELSE ").append(DatabaseMetaData.functionResultUnknown).append(" END AS \"FUNCTION_TYPE\", " + 3984 " ELSE " + DatabaseMetaData.functionResultUnknown + " END AS \"FUNCTION_TYPE\", " +
3983 // only the id value uniquely identifies a function. Include it to be able to differentiate between multiple overloaded functions with the same name 3985 // only the id value uniquely identifies a function. Include it to be able to differentiate between multiple overloaded functions with the same name
3984 "cast(f.\"id\" as varchar(10)) AS \"SPECIFIC_NAME\" " + 3986 "cast(f.\"id\" as varchar(10)) AS \"SPECIFIC_NAME\" " +
3985 "FROM \"sys\".\"functions\" f " + 3987 "FROM \"sys\".\"functions\" f " +
3986 "JOIN \"sys\".\"schemas\" s ON f.\"schema_id\" = s.\"id\" "); 3988 "JOIN \"sys\".\"schemas\" s ON f.\"schema_id\" = s.\"id\" ");
3987 if (useCommentsTable) { 3989 if (useCommentsTable) {
3988 query.append("LEFT OUTER JOIN \"sys\".\"comments\" cm ON (f.\"id\" = cm.\"id\") "); 3990 query.append("LEFT OUTER JOIN \"sys\".\"comments\" cm ON f.\"id\" = cm.\"id\" ");
3989 } 3991 }
3990 // only functions, so exclude procedures (type = 2). Those will to be returned via getProcedures() 3992 // only functions, so exclude procedures (type = 2). Those will to be returned via getProcedures()
3991 query.append("WHERE f.\"type\" <> 2"); 3993 query.append("WHERE f.\"type\" <> 2");
3992 3994
3993 if (catalog != null && !catalog.isEmpty()) { 3995 if (catalog != null && !catalog.isEmpty()) {
4079 query.append("SELECT cast(null as char(1)) AS \"FUNCTION_CAT\", " + 4081 query.append("SELECT cast(null as char(1)) AS \"FUNCTION_CAT\", " +
4080 "s.\"name\" AS \"FUNCTION_SCHEM\", " + 4082 "s.\"name\" AS \"FUNCTION_SCHEM\", " +
4081 "f.\"name\" AS \"FUNCTION_NAME\", " + 4083 "f.\"name\" AS \"FUNCTION_NAME\", " +
4082 "a.\"name\" AS \"COLUMN_NAME\", " + 4084 "a.\"name\" AS \"COLUMN_NAME\", " +
4083 "cast(CASE a.\"inout\"" + 4085 "cast(CASE a.\"inout\"" +
4084 " WHEN 0 THEN (CASE a.\"number\" WHEN 0 THEN ") 4086 " WHEN 0 THEN (CASE a.\"number\" WHEN 0 THEN " + DatabaseMetaData.functionReturn + " ELSE " + DatabaseMetaData.functionColumnOut + " END)" +
4085 .append(DatabaseMetaData.functionReturn).append(" ELSE ").append(DatabaseMetaData.functionColumnOut).append(" END)" + 4087 " WHEN 1 THEN " + DatabaseMetaData.functionColumnIn +
4086 " WHEN 1 THEN ").append(DatabaseMetaData.functionColumnIn) 4088 " ELSE " + DatabaseMetaData.functionColumnUnknown + " END AS smallint) AS \"COLUMN_TYPE\", " +
4087 .append(" ELSE ").append(DatabaseMetaData.functionColumnUnknown).append(" END AS smallint) AS \"COLUMN_TYPE\", " +
4088 "cast(").append(MonetDriver.getSQLTypeMap("a.\"type\"")).append(" AS int) AS \"DATA_TYPE\", " + 4089 "cast(").append(MonetDriver.getSQLTypeMap("a.\"type\"")).append(" AS int) AS \"DATA_TYPE\", " +
4089 "a.\"type\" AS \"TYPE_NAME\", " + 4090 "a.\"type\" AS \"TYPE_NAME\", " +
4090 "CASE a.\"type\" WHEN 'tinyint' THEN 3 WHEN 'smallint' THEN 5 WHEN 'int' THEN 10 WHEN 'bigint' THEN 19" + 4091 "CASE a.\"type\" WHEN 'tinyint' THEN 3 WHEN 'smallint' THEN 5 WHEN 'int' THEN 10 WHEN 'bigint' THEN 19" +
4091 " WHEN 'hugeint' THEN 38 WHEN 'oid' THEN 19 WHEN 'wrd' THEN 19 ELSE a.\"type_digits\" END AS \"PRECISION\", " + 4092 " WHEN 'hugeint' THEN 38 WHEN 'oid' THEN 19 WHEN 'wrd' THEN 19 ELSE a.\"type_digits\" END AS \"PRECISION\", " +
4092 "CASE a.\"type\" WHEN 'tinyint' THEN 1 WHEN 'smallint' THEN 2 WHEN 'int' THEN 4 WHEN 'bigint' THEN 8" + 4093 "CASE a.\"type\" WHEN 'tinyint' THEN 1 WHEN 'smallint' THEN 2 WHEN 'int' THEN 4 WHEN 'bigint' THEN 8" +
4093 " WHEN 'hugeint' THEN 16 WHEN 'oid' THEN 8 WHEN 'wrd' THEN 8 ELSE a.\"type_digits\" END AS \"LENGTH\", " + 4094 " WHEN 'hugeint' THEN 16 WHEN 'oid' THEN 8 WHEN 'wrd' THEN 8 ELSE a.\"type_digits\" END AS \"LENGTH\", " +
4094 "cast(CASE WHEN a.\"type\" IN ('tinyint','smallint','int','bigint','hugeint','oid','wrd','decimal','numeric'," + 4095 "cast(CASE WHEN a.\"type\" IN ('tinyint','smallint','int','bigint','hugeint','oid','wrd','decimal','numeric'," +
4095 "'time','timetz','timestamp','timestamptz','day_interval','month_interval','sec_interval') THEN a.\"type_scale\" ELSE NULL END AS smallint) AS \"SCALE\", " + 4096 "'time','timetz','timestamp','timestamptz','day_interval','month_interval','sec_interval') THEN a.\"type_scale\" ELSE NULL END AS smallint) AS \"SCALE\", " +
4096 "cast(CASE WHEN a.\"type\" IN ('tinyint','smallint','int','bigint','hugeint','oid','wrd','decimal','numeric','day_interval','month_interval','sec_interval') THEN 10" + 4097 "cast(CASE WHEN a.\"type\" IN ('tinyint','smallint','int','bigint','hugeint','oid','wrd','decimal','numeric','day_interval','month_interval','sec_interval') THEN 10" +
4097 " WHEN a.\"type\" IN ('real','float','double') THEN 2 ELSE NULL END AS smallint) AS \"RADIX\", " + 4098 " WHEN a.\"type\" IN ('real','float','double') THEN 2 ELSE NULL END AS smallint) AS \"RADIX\", " +
4099 // mvd: do not remove next append. The String above is same as used by getProcedureColumns, so shared in class file.
4098 "cast(").append(DatabaseMetaData.functionNullableUnknown).append(" AS smallint) AS \"NULLABLE\", " + 4100 "cast(").append(DatabaseMetaData.functionNullableUnknown).append(" AS smallint) AS \"NULLABLE\", " +
4099 "cast(null as char(1)) AS \"REMARKS\", " + 4101 "cast(null as char(1)) AS \"REMARKS\", " +
4100 "cast(CASE WHEN a.\"type\" IN ('char','varchar','clob') THEN a.\"type_digits\" ELSE NULL END as int) AS \"CHAR_OCTET_LENGTH\", " + 4102 "cast(CASE WHEN a.\"type\" IN ('char','varchar','clob') THEN a.\"type_digits\" ELSE NULL END as int) AS \"CHAR_OCTET_LENGTH\", " +
4101 "cast(a.\"number\" as int) AS \"ORDINAL_POSITION\", " + 4103 "cast(a.\"number\" as int) AS \"ORDINAL_POSITION\", " +
4102 "cast('' as varchar(3)) AS \"IS_NULLABLE\", " + 4104 "cast('' as varchar(3)) AS \"IS_NULLABLE\", " +