From 112cb827e960be047f38cd7c60b27b4202f02596 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Mon, 17 Dec 2018 21:39:40 +0000 Subject: Ignore column validators for read-only dbs. This will avoid irrelevant failures when reading databases which have invalid column properties. Fixes #150 git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1240 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../healthmarketscience/jackcess/impl/ColumnImpl.java | 6 ++++++ .../healthmarketscience/jackcess/impl/DatabaseImpl.java | 16 +++++++++++++--- .../jackcess/impl/expr/DefaultTextFunctions.java | 8 ++++---- 3 files changed, 23 insertions(+), 7 deletions(-) (limited to 'src/main/java/com/healthmarketscience/jackcess/impl') diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java index 6d237b4..0016687 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java @@ -491,6 +491,12 @@ public class ColumnImpl implements Column, Comparable { } void initColumnValidator() throws IOException { + + if(getDatabase().isReadOnly()) { + // validators are irrelevant for read-only databases + return; + } + // first initialize any "external" (user-defined) validator setColumnValidator(null); diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java index 6831e99..bb74bba 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java @@ -255,6 +255,8 @@ public class DatabaseImpl implements Database private final File _file; /** the simple name of the database */ private final String _name; + /** whether or not this db is read-only */ + private final boolean _readOnly; /** Buffer to hold database pages */ private ByteBuffer _buffer; /** ID of the Tables system object */ @@ -399,7 +401,8 @@ public class DatabaseImpl implements Database } DatabaseImpl db = new DatabaseImpl(mdbFile, channel, closeChannel, autoSync, - null, charset, timeZone, provider); + null, charset, timeZone, provider, + readOnly); success = true; return db; @@ -458,7 +461,8 @@ public class DatabaseImpl implements Database transferDbFrom(channel, getResourceAsStream(details.getEmptyFilePath())); channel.force(true); DatabaseImpl db = new DatabaseImpl(mdbFile, channel, closeChannel, autoSync, - fileFormat, charset, timeZone, null); + fileFormat, charset, timeZone, null, + false); success = true; return db; } finally { @@ -510,11 +514,13 @@ public class DatabaseImpl implements Database */ protected DatabaseImpl(File file, FileChannel channel, boolean closeChannel, boolean autoSync, FileFormat fileFormat, Charset charset, - TimeZone timeZone, CodecProvider provider) + TimeZone timeZone, CodecProvider provider, + boolean readOnly) throws IOException { _file = file; _name = getName(file); + _readOnly = readOnly; _format = JetFormat.getFormat(channel); _charset = ((charset == null) ? getDefaultCharset(_format) : charset); _columnOrder = getDefaultColumnOrder(); @@ -543,6 +549,10 @@ public class DatabaseImpl implements Database return _name; } + public boolean isReadOnly() { + return _readOnly; + } + /** * @usage _advanced_method_ */ diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultTextFunctions.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultTextFunctions.java index 5643766..74856aa 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultTextFunctions.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultTextFunctions.java @@ -425,7 +425,7 @@ public class DefaultTextFunctions } }); - public static final Function FORMAT = registerFunc(new FuncVar("Format", 1, 4) { + public static final Function FORMAT = registerStringFunc(new FuncVar("Format", 1, 4) { @Override protected Value evalVar(EvalContext ctx, Value[] params) { @@ -441,11 +441,11 @@ public class DefaultTextFunctions String fmtStr = params[1].getAsString(ctx); int firstDay = DefaultDateFunctions.getFirstDayParam(ctx, params, 2); int firstWeekType = DefaultDateFunctions.getFirstWeekTypeParam(ctx, params, 3); - + return FormatUtil.format(ctx, expr, fmtStr, firstDay, firstWeekType); } }); - + private static String nchars(int num, char c) { StringBuilder sb = new StringBuilder(num); nchars(sb, num, c); @@ -457,7 +457,7 @@ public class DefaultTextFunctions sb.append(c); } } - + private static String trim(String str, boolean doLeft, boolean doRight) { int start = 0; int end = str.length(); -- cgit v1.2.3