Skip to content

Commit

Permalink
fix: Exception when using RESTRICT reference option with Oracle
Browse files Browse the repository at this point in the history
The following exception is thrown because Oracle does not have the RESTRICT reference option:
java.sql.SQLSyntaxErrorException: ORA-00905: missing keyword

Preventing the deletion of a parent row if a child row references it is the default behaviour.
  • Loading branch information
joc-a committed Sep 20, 2023
1 parent 11be2e0 commit 1f13967
Showing 1 changed file with 38 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,32 +118,48 @@ data class ForeignKeyConstraint(
append("CONSTRAINT $fkName ")
}
append("FOREIGN KEY ($fromColumns) REFERENCES $targetTableName($targetColumns)")

if (deleteRule != ReferenceOption.NO_ACTION) {
if (currentDialect is SQLServerDialect && deleteRule == ReferenceOption.RESTRICT) {
exposedLogger.warn(
"SQLServer doesn't support FOREIGN KEY with RESTRICT reference option with ON DELETE clause. " +
"Please check your $fromTableName table."
)
} else if (deleteRule == ReferenceOption.SET_DEFAULT) {
when (currentDialect) {
is MariaDBDialect -> exposedLogger.warn(
"MariaDB doesn't support FOREIGN KEY with SET DEFAULT reference option with ON DELETE clause. " +
"Please check your $fromTableName table."
)
is MysqlDialect -> exposedLogger.warn(
"MySQL doesn't support FOREIGN KEY with SET DEFAULT reference option with ON DELETE clause. " +
"Please check your $fromTableName table."
)
is OracleDialect -> exposedLogger.warn(
"Oracle doesn't support FOREIGN KEY with SET DEFAULT reference option with ON DELETE clause. " +
"Please check your $fromTableName table."
)
else -> append(" ON DELETE $deleteRule")
when (deleteRule) {
ReferenceOption.RESTRICT -> {
when (currentDialect) {
is SQLServerDialect -> {
exposedLogger.warn(
"SQLServer doesn't support FOREIGN KEY with RESTRICT reference option with ON DELETE clause. " +
"Please check your $fromTableName table."
)
}
is OracleDialect -> {
exposedLogger.warn(
"Oracle doesn't support FOREIGN KEY with RESTRICT reference option with ON DELETE clause. " +
"Preventing the deletion of a parent row if a child row references it is the default behaviour." +
"Please check your $fromTableName table."
)
}
else -> append(" ON DELETE $deleteRule")
}
}
} else {
append(" ON DELETE $deleteRule")
ReferenceOption.SET_DEFAULT -> {
when (currentDialect) {
is MariaDBDialect -> exposedLogger.warn(
"MariaDB doesn't support FOREIGN KEY with SET DEFAULT reference option with ON DELETE clause. " +
"Please check your $fromTableName table."
)
is MysqlDialect -> exposedLogger.warn(
"MySQL doesn't support FOREIGN KEY with SET DEFAULT reference option with ON DELETE clause. " +
"Please check your $fromTableName table."
)
is OracleDialect -> exposedLogger.warn(
"Oracle doesn't support FOREIGN KEY with SET DEFAULT reference option with ON DELETE clause. " +
"Please check your $fromTableName table."
)
else -> append(" ON DELETE $deleteRule")
}
}
else -> append(" ON DELETE $deleteRule")
}
}

if (updateRule != ReferenceOption.NO_ACTION) {
if (currentDialect is OracleDialect || currentDialect.h2Mode == H2Dialect.H2CompatibilityMode.Oracle) {
exposedLogger.warn("Oracle doesn't support FOREIGN KEY with ON UPDATE clause. Please check your $fromTableName table.")
Expand Down

0 comments on commit 1f13967

Please sign in to comment.