Skip to content

Commit

Permalink
test: Fix failing exposed-tests in Oracle
Browse files Browse the repository at this point in the history
FunctionsTests/testLocate03()
- Oracle substring search is also case sensitive.

DDLTests/createTableWithForeignKeyToAnotherSchema()
- SQL statement used in exec() is terminated with a semi-colon and also does not
provide the required privileges to reference tables across schema.

CreateTableTests/createTableWithQuotes()
- Oracle has been excluded because it does not tolerate a quoted table identifier
in a sequence name: CREATE SEQUENCE ""Parent"_id_seq" START WITH

CreateTableTests/createTableWithSingleQuotes()
- Oracle produces 2 DDL statements, , as a sequence must be created first for
the auto-increment PK.
  • Loading branch information
bog-walk committed Jul 27, 2023
1 parent a3830ed commit a4ebab9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ class DDLTests : DatabaseTestsBase() {
withSchemas(two, one) {
SchemaUtils.create(TableFromSchemeOne)
if (currentDialectTest is OracleDialect) {
exec("GRANT SELECT ON ${TableFromSchemeOne.tableName} to TWO;")
exec("GRANT REFERENCES ON ${TableFromSchemeOne.tableName} to TWO")
}
SchemaUtils.create(TableFromSchemeTwo)
val idFromOne = TableFromSchemeOne.insertAndGetId { }
Expand Down Expand Up @@ -1114,8 +1114,6 @@ class DDLTests : DatabaseTestsBase() {
if (currentDialectTest is SQLServerDialect) {
SchemaUtils.drop(tableA, tableB)
}

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ class CreateTableTests : DatabaseTestsBase() {
onDelete = ReferenceOption.NO_ACTION,
)
}
withTables(excludeSettings = listOf(TestDB.H2_ORACLE), parent, child) {
// Different dialects use different mix of lowercase/uppercase in their names
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) }}," +
Expand All @@ -360,17 +359,14 @@ class CreateTableTests : DatabaseTestsBase() {
onDelete = ReferenceOption.NO_ACTION,
)
}
withTables(excludeSettings = listOf(TestDB.H2_ORACLE), parent, child) {
// Different dialects use different mix of lowercase/uppercase in their names
val expected = listOf(
"CREATE TABLE " + addIfNotExistsIfSupported() + "${this.identity(child)} (" +
"${child.columns.joinToString { it.descriptionDdl(false) }}," +
" CONSTRAINT ${"fk_Child2_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_Child2_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
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ import org.jetbrains.exposed.sql.tests.shared.assertEqualCollections
import org.jetbrains.exposed.sql.tests.shared.assertEquals
import org.jetbrains.exposed.sql.tests.shared.dml.DMLTestsData
import org.jetbrains.exposed.sql.tests.shared.dml.withCitiesAndUsers
import org.jetbrains.exposed.sql.vendors.H2Dialect
import org.jetbrains.exposed.sql.vendors.OracleDialect
import org.jetbrains.exposed.sql.vendors.PostgreSQLDialect
import org.jetbrains.exposed.sql.vendors.SQLServerDialect
import org.jetbrains.exposed.sql.vendors.SQLiteDialect
import org.jetbrains.exposed.sql.vendors.h2Mode
import org.jetbrains.exposed.sql.vendors.*
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
Expand Down Expand Up @@ -356,16 +351,14 @@ class FunctionsTests : DatabaseTestsBase() {
@Test
fun testLocate03() {
withCitiesAndUsers { cities, _, _ ->
val isCaseSensitiveDialect = currentDialectTest is SQLiteDialect ||
currentDialectTest is PostgreSQLDialect ||
currentDialectTest is H2Dialect
val isNotCaseSensitiveDialect = currentDialectTest is MysqlDialect || currentDialectTest is SQLServerDialect

val locate = cities.name.locate("p")
val results = cities.slice(locate).selectAll().toList()

assertEquals(if (isCaseSensitiveDialect) 0 else 5, results[0][locate]) // St. Petersburg
assertEquals(if (isNotCaseSensitiveDialect) 5 else 0, results[0][locate]) // St. Petersburg
assertEquals(0, results[1][locate]) // Munich
assertEquals(if (isCaseSensitiveDialect) 0 else 1, results[2][locate]) // Prague
assertEquals(if (isNotCaseSensitiveDialect) 1 else 0, results[2][locate]) // Prague
}
}

Expand Down

0 comments on commit a4ebab9

Please sign in to comment.