From: James Ahlborn Date: Wed, 26 Nov 2014 17:14:36 +0000 (+0000) Subject: Add newer sql type to access type mappings if the jvm supports them. fixes #113 X-Git-Tag: jackcess-2.0.8~7 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bae32bb3b12b3857b7e7f2c8e8df7bc247eddb64;p=jackcess.git Add newer sql type to access type mappings if the jvm supports them. fixes #113 git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@899 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index f273678..e745224 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -4,6 +4,11 @@ Tim McCune + + + Add newer sql type to access type mappings if the jvm supports them. + + Unicode compression support was not correct for all possibly diff --git a/src/main/java/com/healthmarketscience/jackcess/DataType.java b/src/main/java/com/healthmarketscience/jackcess/DataType.java index e115cdf..ffd5bf4 100644 --- a/src/main/java/com/healthmarketscience/jackcess/DataType.java +++ b/src/main/java/com/healthmarketscience/jackcess/DataType.java @@ -200,6 +200,14 @@ public enum DataType { ALT_SQL_TYPES.put(Types.VARCHAR, MEMO); ALT_SQL_TYPES.put(Types.VARBINARY, OLE); ALT_SQL_TYPES.put(Types.BINARY, OLE); + + // add newer sql types if available in this jvm + addNewSqlType("NCHAR", TEXT, null); + addNewSqlType("NVARCHAR", TEXT, MEMO); + addNewSqlType("LONGNVARCHAR", MEMO, null); + addNewSqlType("NCLOB", MEMO, null); + addNewSqlType("TIME_WITH_TIMEZONE", SHORT_DATE_TIME, null); + addNewSqlType("TIMESTAMP_WITH_TIMEZONE", SHORT_DATE_TIME, null); } private static Map DATA_TYPES = new HashMap(); @@ -481,4 +489,23 @@ public enum DataType { return rtn; } + /** + * Adds mappings for a sql type which was added after jdk 1.5 (using + * reflection). + */ + private static void addNewSqlType(String typeName, DataType type, + DataType altType) + { + try { + java.lang.reflect.Field sqlTypeField = Types.class.getField(typeName); + Integer value = (Integer)sqlTypeField.get(null); + SQL_TYPES.put(value, type); + if(altType != null) { + ALT_SQL_TYPES.put(value, altType); + } + } catch(Exception ignored) { + // must not be available + } + } + }