diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/healthmarketscience/jackcess/impl/FKEnforcer.java | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/FKEnforcer.java b/src/main/java/com/healthmarketscience/jackcess/impl/FKEnforcer.java index bf5138c..470035d 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/FKEnforcer.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/FKEnforcer.java @@ -219,8 +219,8 @@ final class FKEnforcer throws IOException { // ensure that the relevant rows exist in the primary tables for which - // this table is a secondary table. - if(!joiner.hasRows(row)) { + // this table is a secondary table. however, null values are allowed + if(!areNull(joiner, row) && !joiner.hasRows(row)) { throw new ConstraintViolationException( "Adding new row " + Arrays.asList(row) + " violates constraint " + joiner.toFKString()); @@ -288,6 +288,15 @@ final class FKEnforcer return false; } + private static boolean areNull(Joiner joiner, Object[] row) { + for(Index.Column col : joiner.getColumns()) { + if(col.getColumn().getRowValue(row) != null) { + return false; + } + } + return true; + } + private boolean enforcing() { return _table.getDatabase().isEnforceForeignKeys(); } |