aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2016-03-21 02:15:47 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2016-03-21 02:15:47 +0000
commit914e5af35c01d96754b9aa267c1ed4ff4062d43c (patch)
treef0789ad64d54353f2070d0aa689fcabd00c36e1b /src/main
parent4e5fe7ec04eff9ea4e64a8c6d1e3f7fd51257e06 (diff)
downloadjackcess-914e5af35c01d96754b9aa267c1ed4ff4062d43c.tar.gz
jackcess-914e5af35c01d96754b9aa267c1ed4ff4062d43c.zip
Allow null values in foreign key fields when enforcing referential integrity. Fixes issue #136
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@980 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/FKEnforcer.java13
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();
}