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-145 Quoted table name breaks CREATE SEQUENCE in Oracle #1836

Merged
merged 1 commit into from
Aug 17, 2023

Conversation

bog-walk
Copy link
Member

When a table with an auto-increment column is created in Oracle, a sequence must be created first.
If the provided table name has escaped double quotes, this CREATE SEQUENCE statement throws a syntax error:

object Parent : LongIdTable("\"Parent\"") {}

// java.sql.SQLSyntaxErrorException: ORA-01741: illegal zero-length identifier
// Statement(s): CREATE SEQUENCE ""Parent"_id_seq" START WITH 1 MINVALUE 1 MAXVALUE 9223372036854775807

In the case of all the IdTable subclasses, this happens because autoincrement() on the id column is not being provided a custom name, so the fallbackSeqName string is being used. This string now removes double quotes from a table name.

Note:
Oracle (and H2 Oracle) are the only DB that rely on fallbackSeqName as they are the only supported DB that have needsSequenceToAutoInc == true:

/** Returns the name of the sequence used to generate new values for this auto-increment column. */
val autoincSeq: String?
    get() = _autoincSeq.takeIf { currentDialect.supportsCreateSequence }
        ?: fallbackSeqName.takeIf { currentDialect.needsSequenceToAutoInc }

If a table with an autoincrement column is created and provided a table name that
has escaped double quotes, the CREATE SEQUENCE statement throws a syntax error
because of the double quotes.

java.sql.SQLSyntaxErrorException: ORA-01741: illegal zero-length identifier
Statement(s): CREATE SEQUENCE ""Parent"_id_seq" START WITH 1 MINVALUE 1 MAXVALUE 9223372036854775807

Oracle is the only dialect that uses the fallback sequence name, so this has all
double quotes now replaced, as is done for foreign key constraint names.
@bog-walk bog-walk requested review from e5l and joc-a August 16, 2023 23:37
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 8fe5c1c into main Aug 17, 2023
5 checks passed
@bog-walk bog-walk deleted the bog-walk/fix-oracle-sequence branch August 17, 2023 12:34
saral pushed a commit to saral/Exposed that referenced this pull request Oct 3, 2023
…etBrains#1836)

If a table with an autoincrement column is created and provided a table name that
has escaped double quotes, the CREATE SEQUENCE statement throws a syntax error
because of the double quotes.

java.sql.SQLSyntaxErrorException: ORA-01741: illegal zero-length identifier
Statement(s): CREATE SEQUENCE ""Parent"_id_seq" START WITH 1 MINVALUE 1 MAXVALUE 9223372036854775807

Oracle is the only dialect that uses the fallback sequence name, so this has all
double quotes now replaced, as is done for foreign key constraint names.
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.

3 participants