-
Notifications
You must be signed in to change notification settings - Fork 695
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: Incorrect SQL statements when creating a table with a dot in its name #1871
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
joc-a
force-pushed
the
joc/fix-error-dot-table-name
branch
5 times, most recently
from
September 28, 2023 15:20
284e9a7
to
587510a
Compare
joc-a
force-pushed
the
joc/fix-error-dot-table-name
branch
from
September 29, 2023 15:49
8d84140
to
c955b7c
Compare
bog-walk
approved these changes
Oct 3, 2023
exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/CreateTableTests.kt
Show resolved
Hide resolved
e5l
approved these changes
Oct 4, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/CreateTableTests.kt
Show resolved
Hide resolved
The test failed because fallbackSeqName = null_id_seq. The reason tableName was null is that its declaration in the test was missing get().
joc-a
force-pushed
the
joc/fix-error-dot-table-name
branch
from
October 9, 2023 21:11
c955b7c
to
70e7548
Compare
tester.exists() was returning false because of issues with processing the quoted table name that led to a mismatch
joc-a
force-pushed
the
joc/fix-error-dot-table-name
branch
from
October 9, 2023 21:42
70e7548
to
4227ddf
Compare
In `String.metadataMatchesTable`, we should not use `table.tableNameWithoutSchemeSanitized` because "sanitization" in this case should be dialect-aware (aka we should be removing only what is considered a valid quote string in MySQL, which is the backtick). This means that if a table has double quotes (") in MySQL, they should not be removed when we compare it with the table name returned from the metadata, because the metadata (DatabaseMetaData.getTables method) returns it WITH the double quotes. If a name is quoted with backticks (`) instead, the metadata returns it WITHOUT backticks. For example: For table name "\"IdentifierTable\"", metadata returns -> "testdb."IdentifierTable"" For table name "`SomeNamespace.SomeTable`", metadata returns -> "testdb.SomeNamespace.SomeTable"
joc-a
commented
Oct 10, 2023
@@ -444,7 +445,7 @@ class CreateTableTests : DatabaseTestsBase() { | |||
fun createTableWithExplicitForeignKeyName4() { | |||
val fkName = "MyForeignKey4" | |||
val parent = object : LongIdTable() { | |||
override val tableName = "parent4" | |||
override val tableName get() = "parent4" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tableName was "null" before adding get()
e5l
approved these changes
Oct 11, 2023
exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Table.kt
Outdated
Show resolved
Hide resolved
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When providing a table with a dot in its name, it's necessary to quote it so that the part before the dot is not treated as a schema name. If it is treated like a schema name, it fails to find that schema and throws an error. Adding quotes previously caused the name to be broken apart. The fix is to only break the name apart if is NOT already quoted.
Old behaviour:
Provided table name = "SomeNamespace.SomeTable"
Name in SQL statements = "SomeNamespace"."SomeTable"
New behaviour:
Provided table name = "SomeNamespace.SomeTable"
Name in SQL statements = "SomeNamespace.SomeTable"
Oracle is excluded from this fix because it throws this error:
A problem with casing for table names is suspected with INSERT statements. Needs further investigation.
Post-investigation:
Oracle names are not case-sensitive. They can be made case-sensitive by using quotes around them. The Oracle JDBC driver converts the entire SQL INSERT statement to upper case before extracting the table name from it. This happens regardless of whether there is a dot in the name. Even when a name is quoted, the driver converts it to upper case. Therefore, the INSERT statement fails when it contains a quoted table name because it attempts to insert into a table that does not exist (“SOMENAMESPACE.SOMETABLE” is not found) . It does not fail when the table name is not quoted because the case would not matter in that scenario.
Created an issue to further investigate case sensitivity in the Oracle driver.