-
-
Notifications
You must be signed in to change notification settings - Fork 154
Identifier case transform #175
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
Conversation
val shouldQuote = database.alwaysQuoteIdentifiers | ||
|| !this.isIdentifier | ||
|| this.toUpperCase() in database.keywords | ||
|| this.isMixedCase && !database.supportsMixedCaseIdentifiers && database.supportsMixedCaseQuotedIdentifiers |
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.
@lyndsysimon We will quote an identifier when it meet any of these conditions:
- The
alwaysQuoteIdentifiers
param is set totrue
. - The identifier is not valid.
- The identifier is a SQL keyword.
- The identifier is mixed case and the database doesn't support mixed case for unquoted identifiers but supports quoted ones.
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.
My apologies for being late to see this - it looks great!
My only thought is that there are a lot of flags on Database
, and that they can be set in conflicting ways. My instinct would be to use an Enum instead of a series of flags - or more specifically, in this case, two Enums - one for how the DB stores mixed case identifiers and another for how the DB handles unquoted identifiers.
That said, given that a developer should not typically need to implement their own database subclasses I think this implementation is fine the way it is.
@@ -143,8 +161,65 @@ class Database( | |||
*/ | |||
lateinit var extraNameCharacters: String private set | |||
|
|||
/** | |||
* Whether this database threats mixed case unquoted SQL identifiers as case sensitive and as a result | |||
* stores them in mixed case. |
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.
Typo: s/threats/treats
@lyndsysimon Can you help review the code?
I just found that issue #166 is a very common case that also exists in other databases and I came up with a solution to handle it. I think this might be a better way.
I use
DatabaseMetaData
to detect whether the current database supports mixed case for quoted or unquoted SQL identifiers:If mixed case is not supported for unquoted identifiers but supported for quoted ones (e.g. PostgreSQL), I will quote the mixed case identifiers to fix #166
I also add some additional logic for the case that mixed case is not supported (no matter quoted or not). In this case, I will auto transform the idenfiers to the correct case that the database prefers. The perfered case can be known by these methods: