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: EXPOSED-135 Oracle does not use setSchema value as currentScheme #1828

Merged
merged 1 commit into from
Aug 9, 2023

Conversation

bog-walk
Copy link
Member

@bog-walk bog-walk commented Aug 9, 2023

The following test fails when run on Oracle:

CreateIndexTests/'test possibility to create indexes when table exists in different schemas'()

Fails with:

ORA-01430: column being added already exists in table
Statement: ALTER TABLE TEST_TABLE ADD ID NUMBER(12) NOT NULL

This happens because metadata incorrectly returns an empty map of existing table columns when columns() is invoked in JdbcDatabaseMetadataImpl:

override fun columns(vararg tables: Table): Map<Table, List<ColumnMetadata>> {
        val rs = metadata.getColumns(databaseName, currentScheme, "%", "%")
        val result = rs.extractColumns(tables) { // .. }
}

metadata.getColumns() relies on the property currentScheme, which is invariably set to databaseName in Oracle; that means, it is set to the default user created at connection, EXPOSEDTEST.

So, even though this correct SQL is executed (which correctly changes the schema internally in the DB):

ALTER SESSION SET CURRENT_SCHEMA = Schema1

Exposed continues to use the default schema, EXPOSEDTEST, as the argument when querying metadata.

Commit 920428b shows a similar change, but only done local to a single function.

The following test fails when run on Oracle:

CreateIndexTests/'test possibility to create indexes when table exists in different schemas'()

Fails with 'ORA-01430: column being added already exists in table' due to this
statement being incorrectly generated:
ALTER TABLE TEST_TABLE ADD ID NUMBER(12) NOT NULL

This happens because metadata returns an empty map of existing table ColumnMetadata
when columns() is invoked in JdbcDatabaseMetadataImpl. getColumns() relies on the
value of currentScheme which is invariably set to return databaseName in Oracle;
that is, the default user set up at connection, EXPOSEDTEST.

So, even though a correct statement is executed, which changes schema in the DB,
Exposed is using the default schema to query metadata.

currentScheme now attempts to get a connection schema first before using databaseName.
@bog-walk bog-walk requested review from e5l and joc-a August 9, 2023 02:01
Copy link
Member

@e5l e5l left a comment

Choose a reason for hiding this comment

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

lgtm

@bog-walk bog-walk merged commit 8fabb12 into main Aug 9, 2023
3 checks passed
@bog-walk bog-walk deleted the bog-walk/fix-oracle-scheme branch August 9, 2023 16:58
saral pushed a commit to saral/Exposed that referenced this pull request Oct 3, 2023
…JetBrains#1828)

The following test fails when run on Oracle:

CreateIndexTests/'test possibility to create indexes when table exists in different schemas'()

Fails with 'ORA-01430: column being added already exists in table' due to this
statement being incorrectly generated:
ALTER TABLE TEST_TABLE ADD ID NUMBER(12) NOT NULL

This happens because metadata returns an empty map of existing table ColumnMetadata
when columns() is invoked in JdbcDatabaseMetadataImpl. getColumns() relies on the
value of currentScheme which is invariably set to return databaseName in Oracle;
that is, the default user set up at connection, EXPOSEDTEST.

So, even though a correct statement is executed, which changes schema in the DB,
Exposed is using the default schema to query metadata.

currentScheme now attempts to get a connection schema first before using databaseName.
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