Skip to content

Commit

Permalink
feat: EXPOSED-729 [Oracle] Allow setting limit with DELETE
Browse files Browse the repository at this point in the history
It is currently only possibe to set a limit on update() even though the same ROWNUM
syntax that is used for that function provider also applies to delete().

This logic has now been shared across both and tests adjusted.
  • Loading branch information
bog-walk committed Feb 11, 2025
1 parent a32e1f6 commit d9c2983
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,7 @@ internal object OracleFunctionProvider : FunctionProvider() {
transaction: Transaction
): String {
val def = super.update(target, columnsAndValues, null, where, transaction)
return when {
limit != null && where != null -> "$def AND ROWNUM <= $limit"
limit != null -> "$def WHERE ROWNUM <= $limit"
else -> def
}
return def.appendLimitClause(limit, endsWithWhere = where != null)
}

override fun update(
Expand Down Expand Up @@ -318,10 +314,16 @@ internal object OracleFunctionProvider : FunctionProvider() {
limit: Int?,
transaction: Transaction
): String {
if (limit != null) {
transaction.throwUnsupportedException("Oracle doesn't support LIMIT in DELETE clause.")
val def = super.delete(ignore, table, where, null, transaction)
return def.appendLimitClause(limit, endsWithWhere = where != null)
}

private fun String.appendLimitClause(limit: Int?, endsWithWhere: Boolean): String {
return when {
limit != null && endsWithWhere -> "$this AND ROWNUM <= $limit"
limit != null -> "$this WHERE ROWNUM <= $limit"
else -> this
}
return super.delete(ignore, table, where, null, transaction)
}

override fun delete(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import kotlin.test.expect
class DeleteTests : DatabaseTestsBase() {
private val limitNotSupported by lazy {
val extra = setOf(TestDB.SQLITE).takeUnless { SQLiteDialect.ENABLE_UPDATE_DELETE_LIMIT }.orEmpty()
TestDB.ALL_POSTGRES_LIKE + TestDB.ALL_ORACLE_LIKE + extra
TestDB.ALL_POSTGRES_LIKE + extra
}

@Test
Expand Down

0 comments on commit d9c2983

Please sign in to comment.