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 147ac221b0..0412226068 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 @@ -1192,8 +1192,10 @@ open class Table(name: String = "") : ColumnSet(), DdlAware { private fun Column.cloneWithAutoInc(idSeqName: String?): Column = when (columnType) { is AutoIncColumnType -> this is ColumnType -> { + val q = if (tableName.contains('.')) "\"" else "" + val fallbackSeqName = "$q${tableName.replace("\"", "")}_${name}_seq$q" this.withColumnType( - AutoIncColumnType(columnType, idSeqName, "${tableName?.replace("\"", "")}_${name}_seq") + AutoIncColumnType(columnType, idSeqName, fallbackSeqName) ) } diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/api/IdentifierManagerApi.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/api/IdentifierManagerApi.kt index a2b9c7391e..c200e26c3e 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/api/IdentifierManagerApi.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/api/IdentifierManagerApi.kt @@ -97,7 +97,7 @@ abstract class IdentifierManagerApi { } fun quoteIfNecessary(identity: String): String { - return if (identity.contains('.')) { + return if (identity.contains('.') && !identity.isAlreadyQuoted()) { identity.split('.').joinToString(".") { quoteTokenIfNecessary(it) } } else { quoteTokenIfNecessary(identity) 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 8e9c0efa98..873259c34b 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 @@ -4,6 +4,7 @@ import org.jetbrains.exposed.dao.id.IdTable import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.dao.id.LongIdTable import org.jetbrains.exposed.sql.* +import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.tests.DatabaseTestsBase import org.jetbrains.exposed.sql.tests.TestDB import org.jetbrains.exposed.sql.tests.currentDialectTest @@ -629,4 +630,26 @@ class CreateTableTests : DatabaseTestsBase() { } } } + + @Test + fun `create table with dot in name without creating schema beforehand`() { + withDb(excludeSettings = listOf(TestDB.ORACLE)) { + val q = db.identifierManager.quoteString + val tableName = "${q}SomeNamespace.SomeTable$q" + + val tester = object : IntIdTable(tableName) { + val text_col = text("text_col") + } + + try { + SchemaUtils.create(tester) + + val id = tester.insertAndGetId { it[text_col] = "Inserted text" } + tester.update({ tester.id eq id }) { it[text_col] = "Updated text" } + tester.deleteWhere { tester.id eq id } + } finally { + SchemaUtils.drop(tester) + } + } + } }