Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: EXPOSED-729 [Oracle] Allow setting limit with DELETE #2403

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading