From 95d0db424ea8dfb4cc00657cddb8bbf12fe1579d Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Sat, 31 Jan 2015 19:30:55 +0000 Subject: [PATCH] Make ColumnBuilder.setMaxLength do the right thing regardless of column type. Add setMaxScale and setMaxPrecision helpers. Make default length for TEXT columns the max length git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@910 f203690c-595d-4dc9-a70b-905162fa7fd2 --- src/changes/changes.xml | 6 ++++ .../jackcess/ColumnBuilder.java | 31 +++++++++++++++++-- .../jackcess/DataType.java | 4 +-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 5244f96..23c1f09 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -4,6 +4,12 @@ Tim McCune + + + Make ColumnBuilder.setMaxLength do the right thing regardless of + column type. + + Add newer sql type to access type mappings if the jvm supports them. diff --git a/src/main/java/com/healthmarketscience/jackcess/ColumnBuilder.java b/src/main/java/com/healthmarketscience/jackcess/ColumnBuilder.java index bbfca27..f013e3b 100644 --- a/src/main/java/com/healthmarketscience/jackcess/ColumnBuilder.java +++ b/src/main/java/com/healthmarketscience/jackcess/ColumnBuilder.java @@ -129,6 +129,17 @@ public class ColumnBuilder { return ((_precision != null) ? _precision : (byte)_type.getDefaultPrecision()); } + /** + * Sets the precision for the new column to the max length for the type. + * Does nothing for types which do not have a precision. + */ + public ColumnBuilder setMaxPrecision() { + if(_type.getHasScalePrecision()) { + setPrecision(_type.getMaxPrecision()); + } + return this; + } + /** * Sets the scale for the new column. */ @@ -141,6 +152,17 @@ public class ColumnBuilder { return ((_scale != null) ? _scale : (byte)_type.getDefaultScale()); } + /** + * Sets the scale for the new column to the max length for the type. Does + * nothing for types which do not have a scale. + */ + public ColumnBuilder setMaxScale() { + if(_type.getHasScalePrecision()) { + setScale(_type.getMaxScale()); + } + return this; + } + /** * Sets the length (in bytes) for the new column. */ @@ -163,10 +185,15 @@ public class ColumnBuilder { } /** - * Sets the length for the new column to the max length for the type. + * Sets the length for the new column to the max length for the type. Does + * nothing for types which are not variable length. */ public ColumnBuilder setMaxLength() { - return setLength(_type.getMaxSize()); + // length setting only makes sense for variable length columns + if(_type.isVariableLength()) { + setLength(_type.getMaxSize()); + } + return this; } /** diff --git a/src/main/java/com/healthmarketscience/jackcess/DataType.java b/src/main/java/com/healthmarketscience/jackcess/DataType.java index ffd5bf4..ad6deaf 100644 --- a/src/main/java/com/healthmarketscience/jackcess/DataType.java +++ b/src/main/java/com/healthmarketscience/jackcess/DataType.java @@ -114,8 +114,8 @@ public enum DataType { * null}. Equivalent to SQL {@link Types#VARCHAR}, {@link Types#CHAR}. */ TEXT((byte) 0x0A, Types.VARCHAR, null, true, false, 0, - 50 * JetFormat.TEXT_FIELD_UNIT_SIZE, - JetFormat.TEXT_FIELD_MAX_LENGTH, JetFormat.TEXT_FIELD_UNIT_SIZE), + JetFormat.TEXT_FIELD_MAX_LENGTH, JetFormat.TEXT_FIELD_MAX_LENGTH, + JetFormat.TEXT_FIELD_UNIT_SIZE), /** * Corresponds to a java {@code byte[]} of max length 16777215 bytes. * Accepts a {@code byte[]}, or {@code null}. Equivalent to SQL -- 2.39.5