-
Notifications
You must be signed in to change notification settings - Fork 696
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
fix: EXPOSED-701 [Oracle] Insert into table using only database default values fails #2371
base: main
Are you sure you want to change the base?
Conversation
override fun insert( | ||
ignore: Boolean, | ||
table: Table, | ||
columns: List<Column<*>>, | ||
expr: String, | ||
transaction: Transaction | ||
): String { | ||
val def = super.insert(ignore, table, columns, expr, transaction) | ||
return if (def.endsWith(" $DEFAULT_VALUE_EXPRESSION")) { | ||
val oracleDefaults = "VALUES(DEFAULT${", DEFAULT".repeat(table.columns.lastIndex)})" | ||
"${def.removeSuffix(DEFAULT_VALUE_EXPRESSION)}$oracleDefaults" | ||
} else { | ||
def | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, if the string checks seem error-prone, a new branch dependent on currentDialect
could be added to the default insert()
implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good question. OracleFunctionProvider
extends FunctionProvider
, so it doesn't look too good to add checks for dialect inside base FunctionProvider
class.
The current check looks a bit fragile due to string check, but test should save us from regression.
I didn't check it, but looking at the check columns.isNotEmpty() -> columns to expr
, could it be reasonable to check for columns.isNotEmpty()
inside OracleFunctionProvider::insert()
, and if columns
are empty pass "${def.removeSuffix(DEFAULT_VALUE_EXPRESSION)}$oracleDefaults"
instead of expression
?
I feel like expr
could be non empty, and it will not work, but I don't understand now what could be in expr
if columns
are empty...
…lt values fails Oracle currently generates a statement like `INSERT ... DEFAULT VALUES` if an insert operation is performed with no provided column set. This fails because that syntax is not supported. This switches to the `INSERT ... VALUES(DEFAULT, ...)` syntax instead and includes a test for this case.
…lt values fails - Refactor to include dialect check & logic in default insert()
d395aa1
to
f670fc8
Compare
Description
Summary of the change: Oracle insert statement now uses valid syntax for inserting only default values.
Detailed description:
Oracle currently generates a statement like
INSERT ... DEFAULT VALUES
if an insert operation is performed with no provided column set, likeTable.insert { }
.This was not caught because there is actually no test for insertion of only truly database-side defaults; all tests either insert at minimum 1 column, an expression, or implicit auto-inc value for example.
The above syntax causes
java.sql.SQLSyntaxErrorException: ORA-00926: missing VALUES keyword
because it is not supported. More details hereFunctionProvider.insert()
implementation. It uses theINSERT ... VALUES(DEFAULT, ...)
syntax if a defaults-only expression is detected.Type of Change
Please mark the relevant options with an "X":
Affected databases:
Checklist
Related Issues
EXPOSED-701