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

Conversation

bog-walk
Copy link
Member

@bog-walk bog-walk commented Jul 28, 2023

The following test fails when run locally with Oracle:

CreateDatabaseTest/'create database test'()

The first failure ORA-01501: CREATE DATABASE failed, ORA-01100: database already mounted occurs because the create statement is executed while a database already exists. This occurs because the dropDatabase() statement executed in the try block fails as the syntax is not correct.

Once the syntax is fixed, the test still fails with error ORA-65040: operation not allowed from within a pluggable database because certain operations, including dropping the DB, need to be performed only at the root container level.

Attempting to fix this with exec("ALTER SESSION SET CONTAINER=CDB\$ROOT") then fails with error ORA-01031: insufficient privileges. This is in spite of the test container connection being setup using sys as sysdba and granting all privileges to user.

The documentation confirms that dropping a database requires certain conditions:

You must have the SYSDBA system privilege to issue this statement. The database must be mounted in exclusive and restricted mode, and it must be closed.

Attempting to execute variants of the following statements doesn't work either (most likely because they are SQL*PLUS CLI commands):

exec("""SHUTDOWN IMMEDIATE""")
exec("""STARTUP RESTRICT MOUNT""")

Oracle has been excluded from this test.

Failing test shows that the override for dropDatabase() in OracleDialect is wrong,
so this has been replaced with the correct statement.

Failing test would then require privileges to drop the pluggable database from
the root container level, which are not accessible, so it has been excluded.
Change test names casing and exception name
@bog-walk bog-walk requested review from e5l and joc-a July 30, 2023 21:51
@@ -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)

@e5l e5l self-requested a review July 31, 2023 12:42
@bog-walk bog-walk merged commit 86a2405 into main Jul 31, 2023
3 checks passed
@bog-walk bog-walk deleted the bog-walk/fix-oracle-drop-db branch July 31, 2023 20:34
saral pushed a commit to saral/Exposed that referenced this pull request Oct 3, 2023
* fix: Inaccurate drop database statement in Oracle

Failing test shows that the override for dropDatabase() in OracleDialect is wrong,
so this has been replaced with the correct statement.

Failing test would then require privileges to drop the pluggable database from
the root container level, which are not accessible, so it has been excluded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants