diff --git a/src/main/engine/net/sf/jailer/datamodel/DataModel.java b/src/main/engine/net/sf/jailer/datamodel/DataModel.java index f80c6a853..1a1e1353c 100644 --- a/src/main/engine/net/sf/jailer/datamodel/DataModel.java +++ b/src/main/engine/net/sf/jailer/datamodel/DataModel.java @@ -810,19 +810,23 @@ public class DataModel { public static class NoPrimaryKeyException extends RuntimeException { private static final long serialVersionUID = 4523935351640139649L; public final Table table; - public NoPrimaryKeyException(Table table) { - super("Table '" + table.getName() + "' has no primary key"); + public NoPrimaryKeyException(Table table, String message) { + super("Table '" + table.getName() + "' " + message); this.table = table; } + public NoPrimaryKeyException(Table table) { + this(table, "has no primary key"); + } } /** * Checks whether all tables in the closure of a given subject have primary keys. + * @param hasRowID * * @param subject the subject * @throws NoPrimaryKeyException if a table has no primary key */ - public void checkForPrimaryKey(Set subjects, boolean forDeletion) throws NoPrimaryKeyException { + public void checkForPrimaryKey(Set
subjects, boolean forDeletion, boolean hasRowID) throws NoPrimaryKeyException { Set
checked = new HashSet
(); for (Table subject: subjects) { Set
toCheck = new HashSet
(subject.closure(checked, true)); @@ -838,8 +842,13 @@ public class DataModel { toCheck.addAll(border); } for (Table table: toCheck) { - if (table.primaryKey.getColumns().isEmpty()) { - throw new NoPrimaryKeyException(table); + if (!hasRowID) { + if (table.primaryKey.getColumns().isEmpty()) { + throw new NoPrimaryKeyException(table); + } + } + if (table.getColumns().isEmpty()) { + throw new NoPrimaryKeyException(table, "has no column"); } } checked.addAll(toCheck); diff --git a/src/main/engine/net/sf/jailer/subsetting/SubsettingEngine.java b/src/main/engine/net/sf/jailer/subsetting/SubsettingEngine.java index f2b4f2088..f2239882c 100644 --- a/src/main/engine/net/sf/jailer/subsetting/SubsettingEngine.java +++ b/src/main/engine/net/sf/jailer/subsetting/SubsettingEngine.java @@ -1353,11 +1353,9 @@ public class SubsettingEngine { } } } - if (session.dbms.getRowidName() == null || executionContext.getNoRowid() || !insertOnly || deleteScriptFileName != null) { - toCheck.add(extractionModel.subject); - extractionModel.dataModel.checkForPrimaryKey(toCheck, deleteScriptFileName != null); - } - + toCheck.add(extractionModel.subject); + extractionModel.dataModel.checkForPrimaryKey(toCheck, deleteScriptFileName != null, !(session.dbms.getRowidName() == null || executionContext.getNoRowid() || !insertOnly || deleteScriptFileName != null)); + subjectCondition = ParameterHandler.assignParameterValues(subjectCondition, executionContext.getParameters()); if (!executionContext.getParameters().isEmpty()) { diff --git a/src/main/gui/net/sf/jailer/ui/ExtractionModelFrame.java b/src/main/gui/net/sf/jailer/ui/ExtractionModelFrame.java index 42d93b9c3..753e1870a 100644 --- a/src/main/gui/net/sf/jailer/ui/ExtractionModelFrame.java +++ b/src/main/gui/net/sf/jailer/ui/ExtractionModelFrame.java @@ -1094,7 +1094,7 @@ public class ExtractionModelFrame extends javax.swing.JFrame { Session session = SessionForUI.createSession(dataSource, dataSource.dbms, this); if (session != null) { - if (extractionModelEditor.dataModel != null && session.dbms.getRowidName() == null) { + if (extractionModelEditor.dataModel != null) { Set
toCheck = new HashSet
(); if (extractionModelEditor.extractionModel != null) { if (extractionModelEditor.extractionModel.additionalSubjects != null) { @@ -1104,7 +1104,7 @@ public class ExtractionModelFrame extends javax.swing.JFrame { } } toCheck.add(extractionModelEditor.subject); - extractionModelEditor.dataModel.checkForPrimaryKey(toCheck, false); + extractionModelEditor.dataModel.checkForPrimaryKey(toCheck, false, session.dbms.getRowidName() != null); } ExportDialog exportDialog = new ExportDialog(this, extractionModelEditor.dataModel, extractionModelEditor.getSubject(), extractionModelEditor.getSubjectCondition(), extractionModelEditor.extractionModel.additionalSubjects, session, args, dbConnectionDialog.getUser(), dbConnectionDialog.getPassword(), checkRI, dbConnectionDialog, extractionModelEditor.extractionModelFile, executionContext);