Skip to content

Commit

Permalink
fix: EXPOSED-145 Quoted table name breaks create sequence in Oracle (#…
Browse files Browse the repository at this point in the history
…1836)

If a table with an autoincrement column is created and provided a table name that
has escaped double quotes, the CREATE SEQUENCE statement throws a syntax error
because of the double quotes.

java.sql.SQLSyntaxErrorException: ORA-01741: illegal zero-length identifier
Statement(s): CREATE SEQUENCE ""Parent"_id_seq" START WITH 1 MINVALUE 1 MAXVALUE 9223372036854775807

Oracle is the only dialect that uses the fallback sequence name, so this has all
double quotes now replaced, as is done for foreign key constraint names.
  • Loading branch information
bog-walk authored Aug 17, 2023
1 parent 94564d0 commit 8fe5c1c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,9 @@ open class Table(name: String = "") : ColumnSet(), DdlAware {
private fun <T> Column<T>.cloneWithAutoInc(idSeqName: String?): Column<T> = when (columnType) {
is AutoIncColumnType -> this
is ColumnType -> {
this.withColumnType(AutoIncColumnType(columnType, idSeqName, "${tableName}_${name}_seq"))
this.withColumnType(
AutoIncColumnType(columnType, idSeqName, "${tableName?.replace("\"", "")}_${name}_seq")
)
}

else -> error("Unsupported column type for auto-increment $columnType")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,16 +335,14 @@ class CreateTableTests : DatabaseTestsBase() {
onDelete = ReferenceOption.NO_ACTION,
)
}
withTables(excludeSettings = listOf(TestDB.H2_ORACLE, TestDB.ORACLE), parent, child) {
val expected = listOf(
"CREATE TABLE " + addIfNotExistsIfSupported() + "${this.identity(child)} (" +
"${child.columns.joinToString { it.descriptionDdl(false) }}," +
" CONSTRAINT ${"fk_Child_parent_id__id".inProperCase()}" +
" FOREIGN KEY (${this.identity(child.parentId)})" +
" REFERENCES ${this.identity(parent)}(${this.identity(parent.id)})" +
")"
)
assertEqualCollections(child.ddl, expected)
withTables(parent, child) {
val expected = "CREATE TABLE " + addIfNotExistsIfSupported() + "${this.identity(child)} (" +
"${child.columns.joinToString { it.descriptionDdl(false) }}," +
" CONSTRAINT ${"fk_Child_parent_id__id".inProperCase()}" +
" FOREIGN KEY (${this.identity(child.parentId)})" +
" REFERENCES ${this.identity(parent)}(${this.identity(parent.id)})" +
")"
assertEquals(child.ddl.last(), expected)
}
}

Expand Down

0 comments on commit 8fe5c1c

Please sign in to comment.