From 6b98d02e3ddc6f10850729a04a75495410274837 Mon Sep 17 00:00:00 2001 From: Chantal Loncle <82039410+bog-walk@users.noreply.github.com> Date: Wed, 16 Aug 2023 17:02:57 -0400 Subject: [PATCH] fix: EXPOSED-145 Quoted table name breaks create sequence in Oracle 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. --- .../kotlin/org/jetbrains/exposed/sql/Table.kt | 4 +++- .../sql/tests/shared/ddl/CreateTableTests.kt | 18 ++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Table.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Table.kt index 003592b164..214121170f 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Table.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Table.kt @@ -1115,7 +1115,9 @@ open class Table(name: String = "") : ColumnSet(), DdlAware { private fun Column.cloneWithAutoInc(idSeqName: String?): Column = 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") diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/CreateTableTests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/CreateTableTests.kt index 93bf9e2341..a5de737aca 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/CreateTableTests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/CreateTableTests.kt @@ -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) } }