Skip to content
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: Inaccurate drop database statement in Oracle #1807

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ open class OracleDialect : VendorDialect(dialectName, OracleDataTypeProvider, Or

override fun createDatabase(name: String): String = "CREATE DATABASE ${name.inProperCase()}"

override fun dropDatabase(name: String): String = "DROP DATABASE ${name.inProperCase()}"
override fun dropDatabase(name: String): String = "DROP DATABASE"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you tell me why don't we need the name in drop statement?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@e5l Documentation shows that syntax should not have the database name in the drop statement.

This can be confirmed in the test if SchemaUtils.dropDatabase(dbName) is pulled out of the try block (or if the cause.cause is logged in the catch block) as it fails with this exception:

java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended.
Statement(s): DROP DATABASE JETBRAINS

Removing the name resolves this exception (but then leads to the next exception - ORA-65040: operation not allowed from within a pluggable database)


override fun setSchema(schema: Schema): String = "ALTER SESSION SET CURRENT_SCHEMA = ${schema.identifier}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@ import java.sql.SQLException
class CreateDatabaseTest : DatabaseTestsBase() {

@Test
fun `create database test`() {
// PostgreSQL will be tested in the next test function
withDb(excludeSettings = listOf(TestDB.POSTGRESQL, TestDB.POSTGRESQLNG)) {
fun testCreateAndDropDatabase() {
withDb(excludeSettings = listOf(TestDB.POSTGRESQL, TestDB.POSTGRESQLNG, TestDB.ORACLE)) {
val dbName = "jetbrains"
try {
SchemaUtils.dropDatabase(dbName)
} catch (e: SQLException) {
//ignore
} catch (cause: SQLException) {
// ignore
}
SchemaUtils.createDatabase(dbName)
SchemaUtils.dropDatabase(dbName)
}
}

@Test
fun `create database test in postgreSQL`() {
fun testCreateAndDropDatabaseInPostgresql() {
// PostgreSQL needs auto commit to be "ON" to allow create database statement
withDb(listOf(TestDB.POSTGRESQL, TestDB.POSTGRESQLNG)) {
connection.autoCommit = true
Expand Down
Loading