Skip to content

Commit

Permalink
Fix Update 0439 (#241)
Browse files Browse the repository at this point in the history
* Fix Update 0439

* Catch nur für MySQL
  • Loading branch information
JohannMaierhofer committed Jun 14, 2024
1 parent ec112e3 commit 1751159
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
25 changes: 17 additions & 8 deletions src/de/jost_net/JVerein/server/DDLTool/AbstractDDLUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,29 +312,38 @@ public String createForeignKey(String constraintname, String table,

}

public String createForeignKeyIfNotExistsNocheck(String constraintname, String table,
public void createForeignKeyIfNotExistsNocheck(String constraintname, String table,
String column, String reftable, String refcolumn, String ondelete,
String onupdate)
String onupdate) throws ApplicationException
{
switch (drv)
{
case H2:
{
return "ALTER TABLE " + table + " ADD CONSTRAINT IF NOT EXISTS " + constraintname
execute( "ALTER TABLE " + table + " ADD CONSTRAINT IF NOT EXISTS " + constraintname
+ " FOREIGN KEY (" + column + ") REFERENCES " + reftable + "("
+ refcolumn + ") ON DELETE " + ondelete + " ON UPDATE " + onupdate
+ " NOCHECK;\n";
+ " NOCHECK;\n", true);
}
break;
case MYSQL:
{
return "ALTER TABLE " + table + " ADD CONSTRAINT IF NOT EXISTS " + " FOREIGN KEY "
String statement = "ALTER TABLE " + table + " ADD CONSTRAINT " + " FOREIGN KEY "
+ constraintname + "(" + column + ") REFERENCES " + reftable + " ("
+ refcolumn + ") ON DELETE " + ondelete + " ON UPDATE " + onupdate
+ " NOCHECK;\n";
+ ";\n";
try
{
Logger.debug(statement);
ScriptExecutor.execute(new StringReader(statement), conn, null);
}
catch (Exception e)
{
// Wenn Foreign Key schon existiert ist es auch ok;
}
setNewVersion(nr);
}
}
return "";

}

public String dropTable(String table)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public void run() throws ApplicationException
// Weil wegen gelöschter Buchungsklassen die Integrität verletzt sein
// könnte, muss der Foreign Key mit NOCHECK erzeugt werden

execute(createForeignKeyIfNotExistsNocheck("fkKonto1", "konto",
"buchungsart", "buchungsart", "id", "SET NULL", "NO ACTION"));
createForeignKeyIfNotExistsNocheck("fkKonto1", "konto",
"buchungsart", "buchungsart", "id", "SET NULL", "NO ACTION");

}
}

0 comments on commit 1751159

Please sign in to comment.