comparison src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java @ 818:4117aa40a6b9

Fix the computed CHAR_OCTET_LENGTH value of resultsets returned by getColumns(), getFunctionColumns() and getProcedureColumns(). It now also returns a bigint instead of int to prevent computation overflow.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Wed, 13 Dec 2023 19:24:07 +0100 (16 months ago)
parents 93b256bf29a7
children ad4491372c2c
comparison
equal deleted inserted replaced
817:93b256bf29a7 818:4117aa40a6b9
1813 "cast(").append(DatabaseMetaData.procedureNullableUnknown).append(" AS smallint) AS \"NULLABLE\", " + 1813 "cast(").append(DatabaseMetaData.procedureNullableUnknown).append(" AS smallint) AS \"NULLABLE\", " +
1814 "cast(null as char(1)) AS \"REMARKS\", " + 1814 "cast(null as char(1)) AS \"REMARKS\", " +
1815 "cast(null as char(1)) AS \"COLUMN_DEF\", " + 1815 "cast(null as char(1)) AS \"COLUMN_DEF\", " +
1816 "cast(0 as int) AS \"SQL_DATA_TYPE\", " + 1816 "cast(0 as int) AS \"SQL_DATA_TYPE\", " +
1817 "cast(0 as int) AS \"SQL_DATETIME_SUB\", " + 1817 "cast(0 as int) AS \"SQL_DATETIME_SUB\", " +
1818 "cast(CASE WHEN a.\"type\" IN ('char','varchar','clob') THEN a.\"type_digits\" ELSE NULL END as int) AS \"CHAR_OCTET_LENGTH\", " + 1818 "cast(CASE WHEN a.\"type\" IN ('varchar','clob','char','json','url','xml') THEN 4 * a.\"type_digits\" WHEN a.\"type\" = 'blob' THEN a.\"type_digits\" ELSE NULL END as bigint) AS \"CHAR_OCTET_LENGTH\", " +
1819 // in MonetDB procedures have no return value by design. The arguments in sys.args are numbered from 0 so we must add 1 to comply with the API specification. 1819 // in MonetDB procedures have no return value by design. The arguments in sys.args are numbered from 0 so we must add 1 to comply with the API specification.
1820 "cast(a.\"number\" + 1 as int) AS \"ORDINAL_POSITION\", " + 1820 "cast(a.\"number\" + 1 as int) AS \"ORDINAL_POSITION\", " +
1821 "cast('' as varchar(3)) AS \"IS_NULLABLE\", " + 1821 "cast('' as varchar(3)) AS \"IS_NULLABLE\", " +
1822 // the specific name contains the function id, in order to be able to match the args to the correct overloaded procedure name 1822 // the specific name contains the function id, in order to be able to match the args to the correct overloaded procedure name
1823 "cast(f.\"id\" as varchar(10)) AS \"SPECIFIC_NAME\" " + 1823 "cast(f.\"id\" as varchar(10)) AS \"SPECIFIC_NAME\" " +
2129 " END AS int) AS \"NULLABLE\", ") 2129 " END AS int) AS \"NULLABLE\", ")
2130 .append(useCommentsTable ? "cm.\"remark\"" : "cast(null AS varchar(9999))").append(" AS \"REMARKS\", " + 2130 .append(useCommentsTable ? "cm.\"remark\"" : "cast(null AS varchar(9999))").append(" AS \"REMARKS\", " +
2131 "c.\"default\" AS \"COLUMN_DEF\", " + 2131 "c.\"default\" AS \"COLUMN_DEF\", " +
2132 "cast(0 as int) AS \"SQL_DATA_TYPE\", " + 2132 "cast(0 as int) AS \"SQL_DATA_TYPE\", " +
2133 "cast(0 as int) AS \"SQL_DATETIME_SUB\", " + 2133 "cast(0 as int) AS \"SQL_DATETIME_SUB\", " +
2134 "cast(CASE WHEN c.\"type\" IN ('char','varchar','clob') THEN c.\"type_digits\" ELSE NULL END as int) AS \"CHAR_OCTET_LENGTH\", " + 2134 "cast(CASE WHEN c.\"type\" IN ('varchar','clob','char','json','url','xml') THEN 4 * c.\"type_digits\" ELSE NULL END as bigint) AS \"CHAR_OCTET_LENGTH\", " +
2135 "cast(c.\"number\" + 1 as int) AS \"ORDINAL_POSITION\", " + 2135 "cast(c.\"number\" + 1 as int) AS \"ORDINAL_POSITION\", " +
2136 "cast(CASE c.\"null\" WHEN true THEN 'YES' WHEN false THEN 'NO' ELSE '' END AS varchar(3)) AS \"IS_NULLABLE\", " + 2136 "cast(CASE c.\"null\" WHEN true THEN 'YES' WHEN false THEN 'NO' ELSE '' END AS varchar(3)) AS \"IS_NULLABLE\", " +
2137 "cast(null AS char(1)) AS \"SCOPE_CATALOG\", " + 2137 "cast(null AS char(1)) AS \"SCOPE_CATALOG\", " +
2138 "cast(null AS char(1)) AS \"SCOPE_SCHEMA\", " + 2138 "cast(null AS char(1)) AS \"SCOPE_SCHEMA\", " +
2139 "cast(null AS char(1)) AS \"SCOPE_TABLE\", " + 2139 "cast(null AS char(1)) AS \"SCOPE_TABLE\", " +
3032 query.append("SELECT CASE \"sqlname\" WHEN 'day_interval' THEN 'interval day'" + 3032 query.append("SELECT CASE \"sqlname\" WHEN 'day_interval' THEN 'interval day'" +
3033 " WHEN 'month_interval' THEN 'interval month'" + 3033 " WHEN 'month_interval' THEN 'interval month'" +
3034 " WHEN 'sec_interval' THEN 'interval second'" + 3034 " WHEN 'sec_interval' THEN 'interval second'" +
3035 " ELSE \"sqlname\" END AS \"TYPE_NAME\", " + 3035 " ELSE \"sqlname\" END AS \"TYPE_NAME\", " +
3036 "cast(").append(MonetDriver.getSQLTypeMap("\"sqlname\"")).append(" AS int) AS \"DATA_TYPE\", " + 3036 "cast(").append(MonetDriver.getSQLTypeMap("\"sqlname\"")).append(" AS int) AS \"DATA_TYPE\", " +
3037 "\"digits\" AS \"PRECISION\", " + // note that when radix is 2 the precision shows the number of bits 3037 "cast(CASE WHEN \"sqlname\" IN ('time','timetz','timestamp','timestamptz') THEN \"digits\" -1" +
3038 " WHEN \"sqlname\" IN ('sec_interval','day_interval') THEN 3" +
3039 " WHEN \"sqlname\" = 'month_interval' THEN 0 ELSE \"digits\" END AS int) AS \"PRECISION\", " + // note that when radix is 2 the precision shows the number of bits
3038 "cast(CASE WHEN \"sqlname\" IN ('char','varchar','sec_interval','day_interval','month_interval') THEN ''''" + 3040 "cast(CASE WHEN \"sqlname\" IN ('char','varchar','sec_interval','day_interval','month_interval') THEN ''''" +
3039 " WHEN \"sqlname\" IN ('clob','inet','json','url','uuid','date','time','timetz','timestamp','timestamptz','blob','sqlblob','xml') THEN \"sqlname\"||' '''" + 3041 " WHEN \"sqlname\" IN ('clob','inet','json','url','uuid','date','time','timetz','timestamp','timestamptz','blob','sqlblob','xml') THEN \"sqlname\"||' '''" +
3040 " ELSE NULL END AS varchar(16)) AS \"LITERAL_PREFIX\", " + 3042 " ELSE NULL END AS varchar(16)) AS \"LITERAL_PREFIX\", " +
3041 "cast(CASE WHEN \"sqlname\" IN ('char','varchar','sec_interval','day_interval','month_interval'" + 3043 "cast(CASE WHEN \"sqlname\" IN ('char','varchar','sec_interval','day_interval','month_interval'" +
3042 ",'clob','inet','json','url','uuid','date','time','timetz','timestamp','timestamptz','blob','sqlblob','xml') THEN ''''" + 3044 ",'clob','inet','json','url','uuid','date','time','timetz','timestamp','timestamptz','blob','sqlblob','xml') THEN ''''" +
3043 " ELSE NULL END AS varchar(2)) AS \"LITERAL_SUFFIX\", " + 3045 " ELSE NULL END AS varchar(2)) AS \"LITERAL_SUFFIX\", " +
3044 "CASE WHEN \"sqlname\" IN ('char','varchar') THEN 'max length'" + 3046 "CASE WHEN \"sqlname\" IN ('char','varchar') THEN 'max length'" +
3045 " WHEN \"sqlname\" = 'decimal' THEN 'precision, scale'" + 3047 " WHEN \"sqlname\" = 'decimal' THEN 'precision, scale'" +
3046 " WHEN \"sqlname\" IN ('time','timetz','timestamp','timestamptz','sec_interval') THEN 'precision'" + 3048 " WHEN \"sqlname\" IN ('time','timetz','timestamp','timestamptz') THEN 'precision'" +
3047 " ELSE NULL END AS \"CREATE_PARAMS\", " + 3049 " ELSE NULL END AS \"CREATE_PARAMS\", " +
3048 "cast(CASE WHEN \"systemname\" = 'oid' THEN " + DatabaseMetaData.typeNoNulls + 3050 "cast(CASE WHEN \"systemname\" = 'oid' THEN " + DatabaseMetaData.typeNoNulls +
3049 " ELSE " + DatabaseMetaData.typeNullable + " END AS smallint) AS \"NULLABLE\", " + 3051 " ELSE " + DatabaseMetaData.typeNullable + " END AS smallint) AS \"NULLABLE\", " +
3050 "CASE WHEN \"systemname\" IN ('str','json','url','xml') THEN true ELSE false END AS \"CASE_SENSITIVE\", " + 3052 "CASE WHEN \"systemname\" IN ('str','json','url','xml') THEN true ELSE false END AS \"CASE_SENSITIVE\", " +
3051 "cast(CASE WHEN \"systemname\" IN ('str','inet','json','url','uuid','xml') THEN " + DatabaseMetaData.typeSearchable + 3053 "cast(CASE WHEN \"systemname\" IN ('str','inet','json','url','uuid','xml') THEN " + DatabaseMetaData.typeSearchable +
3055 "CASE \"sqlname\" WHEN 'decimal' THEN true ELSE false END AS \"FIXED_PREC_SCALE\", " + 3057 "CASE \"sqlname\" WHEN 'decimal' THEN true ELSE false END AS \"FIXED_PREC_SCALE\", " +
3056 "CASE WHEN \"sqlname\" IN ('tinyint','smallint','int','bigint') THEN true ELSE false END AS \"AUTO_INCREMENT\", " + 3058 "CASE WHEN \"sqlname\" IN ('tinyint','smallint','int','bigint') THEN true ELSE false END AS \"AUTO_INCREMENT\", " +
3057 "CASE WHEN \"sqlname\" IN ('sec_interval','day_interval','month_interval') THEN \"sqlname\" ELSE \"systemname\" END AS \"LOCAL_TYPE_NAME\", " + 3059 "CASE WHEN \"sqlname\" IN ('sec_interval','day_interval','month_interval') THEN \"sqlname\" ELSE \"systemname\" END AS \"LOCAL_TYPE_NAME\", " +
3058 "cast(0 AS smallint) AS \"MINIMUM_SCALE\", " + 3060 "cast(0 AS smallint) AS \"MINIMUM_SCALE\", " +
3059 "cast(CASE WHEN \"sqlname\" = 'decimal' THEN (CASE \"systemname\" WHEN 'int' THEN 9 WHEN 'lng' THEN 18 WHEN 'sht' THEN 4 WHEN 'hge' THEN 38 WHEN 'bte' THEN 2 ELSE 0 END)" + 3061 "cast(CASE WHEN \"sqlname\" = 'decimal' THEN (CASE \"systemname\" WHEN 'int' THEN 9 WHEN 'lng' THEN 18 WHEN 'sht' THEN 4 WHEN 'hge' THEN 38 WHEN 'bte' THEN 2 ELSE 0 END)" +
3060 " WHEN \"sqlname\" IN ('time','timetz','timestamp','timestamptz','sec_interval') THEN 6 ELSE 0 END AS smallint) AS \"MAXIMUM_SCALE\", " + 3062 " WHEN \"sqlname\" IN ('time','timetz','timestamp','timestamptz') THEN 6" +
3063 " WHEN \"sqlname\" IN ('day_interval','sec_interval') THEN 3 ELSE 0 END AS smallint) AS \"MAXIMUM_SCALE\", " +
3061 "cast(0 AS int) AS \"SQL_DATA_TYPE\", " + 3064 "cast(0 AS int) AS \"SQL_DATA_TYPE\", " +
3062 "cast(0 AS int) AS \"SQL_DATETIME_SUB\", " + 3065 "cast(0 AS int) AS \"SQL_DATETIME_SUB\", " +
3063 "cast(CASE WHEN \"sqlname\" IN ('time','timetz','timestamp','timestamptz','sec_interval') THEN 10 ELSE \"radix\" END AS int) AS \"NUM_PREC_RADIX\" " + 3066 "cast(CASE WHEN \"sqlname\" IN ('time','timetz','timestamp','timestamptz','sec_interval') THEN 10 ELSE \"radix\" END AS int) AS \"NUM_PREC_RADIX\" " +
3064 "FROM \"sys\".\"types\" " + 3067 "FROM \"sys\".\"types\" " +
3065 "ORDER BY \"DATA_TYPE\", \"sqlname\", \"id\""); 3068 "ORDER BY \"DATA_TYPE\", \"sqlname\", \"id\"");
4041 "cast(CASE WHEN a.\"type\" IN ('tinyint','smallint','int','bigint','hugeint','oid','wrd','decimal','numeric','day_interval','month_interval','sec_interval') THEN 10" + 4044 "cast(CASE WHEN a.\"type\" IN ('tinyint','smallint','int','bigint','hugeint','oid','wrd','decimal','numeric','day_interval','month_interval','sec_interval') THEN 10" +
4042 " WHEN a.\"type\" IN ('real','float','double') THEN 2 ELSE NULL END AS smallint) AS \"RADIX\", " + 4045 " WHEN a.\"type\" IN ('real','float','double') THEN 2 ELSE NULL END AS smallint) AS \"RADIX\", " +
4043 // mvd: do not remove next append. The String above is same as used by getProcedureColumns, so shared in class file. 4046 // mvd: do not remove next append. The String above is same as used by getProcedureColumns, so shared in class file.
4044 "cast(").append(DatabaseMetaData.functionNullableUnknown).append(" AS smallint) AS \"NULLABLE\", " + 4047 "cast(").append(DatabaseMetaData.functionNullableUnknown).append(" AS smallint) AS \"NULLABLE\", " +
4045 "cast(null as char(1)) AS \"REMARKS\", " + 4048 "cast(null as char(1)) AS \"REMARKS\", " +
4046 "cast(CASE WHEN a.\"type\" IN ('char','varchar','clob') THEN a.\"type_digits\" ELSE NULL END as int) AS \"CHAR_OCTET_LENGTH\", " + 4049 "cast(CASE WHEN a.\"type\" IN ('varchar','clob','char','json','url','xml') THEN 4 * a.\"type_digits\" WHEN a.\"type\" = 'blob' THEN a.\"type_digits\" ELSE NULL END as bigint) AS \"CHAR_OCTET_LENGTH\", " +
4047 "cast(a.\"number\" as int) AS \"ORDINAL_POSITION\", " + 4050 "cast(a.\"number\" as int) AS \"ORDINAL_POSITION\", " +
4048 "cast('' as varchar(3)) AS \"IS_NULLABLE\", " + 4051 "cast('' as varchar(3)) AS \"IS_NULLABLE\", " +
4049 // the specific name contains the function id, in order to be able to match the args to the correct overloaded function name 4052 // the specific name contains the function id, in order to be able to match the args to the correct overloaded function name
4050 "cast(f.\"id\" as varchar(10)) AS \"SPECIFIC_NAME\" " + 4053 "cast(f.\"id\" as varchar(10)) AS \"SPECIFIC_NAME\" " +
4051 "FROM \"sys\".\"args\" a " + 4054 "FROM \"sys\".\"args\" a " +