From eefd19f66057b3c3fd9f4ff405365e11a4239cb7 Mon Sep 17 00:00:00 2001 From: lukaseder Date: Mon, 25 Jul 2016 16:40:21 +0200 Subject: [PATCH] [#5437] Partial implementation (fix ordering by ordinal position) --- .../jooq/impl/InformationSchemaMetaImpl.java | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/impl/InformationSchemaMetaImpl.java b/jOOQ/src/main/java/org/jooq/impl/InformationSchemaMetaImpl.java index a8af667f41..8efb0ef3b7 100644 --- a/jOOQ/src/main/java/org/jooq/impl/InformationSchemaMetaImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/InformationSchemaMetaImpl.java @@ -43,6 +43,8 @@ package org.jooq.impl; import static java.util.Collections.unmodifiableList; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -109,21 +111,44 @@ final class InformationSchemaMetaImpl implements Meta { tablesByName.put(xt.getTableName(), it); } - for (Column xc : meta.getColumns()) { + List columns = new ArrayList(meta.getColumns()); + Collections.sort(columns, new Comparator() { + @Override + public int compare(Column o1, Column o2) { + Integer p1 = o1.getOrdinalPosition(); + Integer p2 = o2.getOrdinalPosition(); + + if (p1 == p2) + return 0; + if (p1 == null) + return -1; + if (p2 == null) + return 1; + + return p1.compareTo(p2); + } + }); + + for (Column xc : columns) { String typeName = xc.getDataType(); + int length = xc.getCharacterMaximumLength() == null ? 0 : xc.getCharacterMaximumLength(); int precision = xc.getNumericPrecision() == null ? 0 : xc.getNumericPrecision(); int scale = xc.getNumericScale() == null ? 0 : xc.getNumericScale(); boolean nullable = xc.isIsNullable() == null ? true : xc.isIsNullable(); + if (precision == 0) + precision = xc.getCharacterMaximumLength() == null ? 0 : xc.getCharacterMaximumLength(); + // TODO: Exception handling should be moved inside SQLDataType DataType type = null; try { - type = DefaultDataType.getDataType(configuration.family(), typeName, precision, scale); - - // JDBC doesn't distinguish between precision and length - type = type.precision(precision, scale); - type = type.length(precision); + type = DefaultDataType.getDataType(configuration.family(), typeName); type = type.nullable(nullable); + + if (length != 0) + type = type.length(length); + else if (precision != 0 || scale != 0) + type = type.precision(precision, scale); } catch (SQLDialectNotSupportedException e) { type = SQLDataType.OTHER;