comparison src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java @ 682:78253fdb3c3f

Corrected returned SQL TypeName values for the MonetDB interval types: 'day_interval', 'month_interval' and 'sec_interval'. Those MonetDB type names can not be used in CREATE TABLE statements. Instead one has to use SQL type names: 'interval day', 'interval month' or 'interval second'. The JDBC driver now returns those SQL type names. This applies to methods: DatabaseMetaData.getTypeInfo() for the output column TYPE_NAME (the output column LOCAL_TYPE_NAME now returns the original type name), ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName().
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Fri, 04 Nov 2022 00:04:42 +0100 (2022-11-03)
parents 238d6a3a6469
children bdeabbd46ec6
comparison
equal deleted inserted replaced
681:32e7ac7b979e 682:78253fdb3c3f
3033 * @return ResultSet each row is a SQL type description 3033 * @return ResultSet each row is a SQL type description
3034 * @throws SQLException if a database error occurs 3034 * @throws SQLException if a database error occurs
3035 */ 3035 */
3036 @Override 3036 @Override
3037 public ResultSet getTypeInfo() throws SQLException { 3037 public ResultSet getTypeInfo() throws SQLException {
3038 final StringBuilder query = new StringBuilder(2300); 3038 final StringBuilder query = new StringBuilder(3200);
3039 query.append("SELECT \"sqlname\" AS \"TYPE_NAME\", " + 3039 query.append("SELECT CASE \"sqlname\" WHEN 'day_interval' THEN 'interval day'" +
3040 // TODO map 'day_interval' to 'interval day' (or 'interval day to second'), 'month_interval' to 'interval month' (or 'interval year to month'), 'sec_interval' to 'interval second' 3040 " WHEN 'month_interval' THEN 'interval month'" +
3041 " WHEN 'sec_interval' THEN 'interval second'" +
3042 " ELSE \"sqlname\" END AS \"TYPE_NAME\", " +
3041 "cast(").append(MonetDriver.getSQLTypeMap("\"sqlname\"")).append(" AS int) AS \"DATA_TYPE\", " + 3043 "cast(").append(MonetDriver.getSQLTypeMap("\"sqlname\"")).append(" AS int) AS \"DATA_TYPE\", " +
3042 "\"digits\" AS \"PRECISION\", " + // note that when radix is 2 the precision shows the number of bits 3044 "\"digits\" AS \"PRECISION\", " + // note that when radix is 2 the precision shows the number of bits
3043 "cast(CASE WHEN \"sqlname\" IN ('char','varchar','sec_interval','day_interval','month_interval') THEN ''''" + 3045 "cast(CASE WHEN \"sqlname\" IN ('char','varchar','sec_interval','day_interval','month_interval') THEN ''''" +
3044 " WHEN \"sqlname\" IN ('clob','inet','json','url','uuid','date','time','timetz','timestamp','timestamptz','blob','sqlblob','xml') THEN \"sqlname\"||' '''" + 3046 " WHEN \"sqlname\" IN ('clob','inet','json','url','uuid','date','time','timetz','timestamp','timestamptz','blob','sqlblob','xml') THEN \"sqlname\"||' '''" +
3045 " ELSE NULL END AS varchar(16)) AS \"LITERAL_PREFIX\", " + 3047 " ELSE NULL END AS varchar(16)) AS \"LITERAL_PREFIX\", " +
3057 .append(" ELSE ").append(DatabaseMetaData.typePredBasic).append(" END AS smallint) AS \"SEARCHABLE\", " + 3059 .append(" ELSE ").append(DatabaseMetaData.typePredBasic).append(" END AS smallint) AS \"SEARCHABLE\", " +
3058 "CASE WHEN \"sqlname\" IN ('tinyint','smallint','int','bigint','hugeint','decimal','real','double'" + 3060 "CASE WHEN \"sqlname\" IN ('tinyint','smallint','int','bigint','hugeint','decimal','real','double'" +
3059 ",'day_interval','month_interval','sec_interval') THEN false ELSE true END AS \"UNSIGNED_ATTRIBUTE\", " + 3061 ",'day_interval','month_interval','sec_interval') THEN false ELSE true END AS \"UNSIGNED_ATTRIBUTE\", " +
3060 "CASE \"sqlname\" WHEN 'decimal' THEN true ELSE false END AS \"FIXED_PREC_SCALE\", " + 3062 "CASE \"sqlname\" WHEN 'decimal' THEN true ELSE false END AS \"FIXED_PREC_SCALE\", " +
3061 "CASE WHEN \"sqlname\" IN ('tinyint','smallint','int','bigint') THEN true ELSE false END AS \"AUTO_INCREMENT\", " + 3063 "CASE WHEN \"sqlname\" IN ('tinyint','smallint','int','bigint') THEN true ELSE false END AS \"AUTO_INCREMENT\", " +
3062 "\"systemname\" AS \"LOCAL_TYPE_NAME\", " + 3064 "CASE WHEN \"sqlname\" IN ('sec_interval','day_interval','month_interval') THEN \"sqlname\" ELSE \"systemname\" END AS \"LOCAL_TYPE_NAME\", " +
3063 "cast(0 AS smallint) AS \"MINIMUM_SCALE\", " + 3065 "cast(0 AS smallint) AS \"MINIMUM_SCALE\", " +
3064 "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)" + 3066 "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)" +
3065 " WHEN \"sqlname\" IN ('time','timetz','timestamp','timestamptz','sec_interval') THEN 6 ELSE 0 END AS smallint) AS \"MAXIMUM_SCALE\", " + 3067 " WHEN \"sqlname\" IN ('time','timetz','timestamp','timestamptz','sec_interval') THEN 6 ELSE 0 END AS smallint) AS \"MAXIMUM_SCALE\", " +
3066 "cast(0 AS int) AS \"SQL_DATA_TYPE\", " + 3068 "cast(0 AS int) AS \"SQL_DATA_TYPE\", " +
3067 "cast(0 AS int) AS \"SQL_DATETIME_SUB\", " + 3069 "cast(0 AS int) AS \"SQL_DATETIME_SUB\", " +
3068 "cast(CASE WHEN \"sqlname\" IN ('time','timetz','timestamp','timestamptz','sec_interval') THEN 10 ELSE \"radix\" END AS int) AS \"NUM_PREC_RADIX\" " + 3070 "cast(CASE WHEN \"sqlname\" IN ('time','timetz','timestamp','timestamptz','sec_interval') THEN 10 ELSE \"radix\" END AS int) AS \"NUM_PREC_RADIX\" " +
3069 "FROM \"sys\".\"types\" " + 3071 "FROM \"sys\".\"types\" " +
3070 "ORDER BY \"DATA_TYPE\", \"sqlname\", \"id\""); 3072 "ORDER BY \"DATA_TYPE\", \"sqlname\", \"id\"");
3071 3073
3074 /* if (query.length() >= 3200) System.err.println("getTypeInfo(), extend query default size to: " + query.length()); */
3072 return executeMetaDataQuery(query.toString()); 3075 return executeMetaDataQuery(query.toString());
3073 } 3076 }
3074 3077
3075 /** 3078 /**
3076 * Retrieves a description of the given table's indices and statistics. 3079 * Retrieves a description of the given table's indices and statistics.