Skip to content

Commit

Permalink
[#6466] Support fetching HSQLDB arrays from plain SQL results
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaseder committed Jul 28, 2017
1 parent f11efe0 commit a6464be
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
36 changes: 22 additions & 14 deletions jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java
Expand Up @@ -750,26 +750,34 @@ public static DataType<Object> getDefaultDataType(SQLDialect dialect, String typ

public static DataType<?> getDataType(SQLDialect dialect, String typeName) {
int ordinal = dialect.ordinal();
DataType<?> result = TYPES_BY_NAME[ordinal].get(typeName.toUpperCase());
String upper = typeName.toUpperCase();
String normalised = typeName;
DataType<?> result = TYPES_BY_NAME[ordinal].get(upper);

// [#3225] Normalise only if necessary
if (result == null) {
typeName = DefaultDataType.normalise(typeName);
result = TYPES_BY_NAME[ordinal].get(typeName);
}
result = TYPES_BY_NAME[ordinal].get(normalised = DefaultDataType.normalise(typeName));

// UDT data types and others are registered using DEFAULT
if (result == null) {
result = TYPES_BY_NAME[SQLDialect.DEFAULT.ordinal()].get(normalised);

// UDT data types and others are registered using DEFAULT
if (result == null)
result = TYPES_BY_NAME[SQLDialect.DEFAULT.ordinal()].get(typeName);
// [#4065] PostgreSQL reports array types as _typename, e.g. _varchar
if (result == null && dialect.family() == SQLDialect.POSTGRES && normalised.charAt(0) == '_') {
result = getDataType(dialect, normalised.substring(1)).getArrayDataType();

// [#4065] PostgreSQL reports array types as _typename, e.g. _varchar
if (result == null && dialect.family() == SQLDialect.POSTGRES && typeName.charAt(0) == '_')
result = getDataType(dialect, typeName.substring(1)).getArrayDataType();
// [#6466] HSQLDB reports array types as XYZARRAY
if (result == null && dialect.family() == SQLDialect.HSQLDB && upper.endsWith(" ARRAY")) {
result = getDataType(dialect, typeName.substring(0, typeName.length() - 6)).getArrayDataType();

// [#366] Don't log a warning here. The warning is logged when
// catching the exception in jOOQ-codegen
if (result == null)
throw new SQLDialectNotSupportedException("Type " + typeName + " is not supported in dialect " + dialect, false);
// [#366] Don't log a warning here. The warning is logged when
// catching the exception in jOOQ-codegen
if (result == null)
throw new SQLDialectNotSupportedException("Type " + typeName + " is not supported in dialect " + dialect, false);
}
}
}
}

return result;
}
Expand Down
13 changes: 5 additions & 8 deletions jOOQ/src/main/java/org/jooq/impl/MetaDataFieldProvider.java
Expand Up @@ -77,7 +77,7 @@ final class MetaDataFieldProvider implements Serializable {
this.fields = init(configuration, meta);
}

private Fields<Record> init(Configuration configuration, ResultSetMetaData meta) {
private static Fields<Record> init(Configuration configuration, ResultSetMetaData meta) {
Field<?>[] fields;
int columnCount = 0;

Expand Down Expand Up @@ -125,17 +125,14 @@ private Fields<Record> init(Configuration configuration, ResultSetMetaData meta)
try {
dataType = DefaultDataType.getDataType(configuration.family(), type, precision, scale);

if (dataType.hasPrecision()) {
if (dataType.hasPrecision())
dataType = dataType.precision(precision);
}
if (dataType.hasScale()) {
if (dataType.hasScale())
dataType = dataType.scale(scale);
}
if (dataType.hasLength()) {

// JDBC doesn't distinguish between precision and length
// JDBC doesn't distinguish between precision and length
if (dataType.hasLength())
dataType = dataType.length(precision);
}
}

// [#650, #667] All types should be known at this point, but in plain
Expand Down

0 comments on commit a6464be

Please sign in to comment.