Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@vincentlauvlwj
Copy link
Member

@vincentlauvlwj vincentlauvlwj commented Jul 19, 2020

@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:

Comment on lines +77 to +80
val shouldQuote = database.alwaysQuoteIdentifiers
|| !this.isIdentifier
|| this.toUpperCase() in database.keywords
|| this.isMixedCase && !database.supportsMixedCaseIdentifiers && database.supportsMixedCaseQuotedIdentifiers
Copy link
Member Author

@vincentlauvlwj vincentlauvlwj Jul 19, 2020

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 to true.
  • 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.

@vincentlauvlwj vincentlauvlwj merged commit 657cd53 into v3.1.x Jul 25, 2020
Copy link
Contributor

@lyndsysimon lyndsysimon left a 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.


/**
* Whether this database threats mixed case unquoted SQL identifiers as case sensitive and as a result
* stores them in mixed case.
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: s/threats/treats

@vincentlauvlwj vincentlauvlwj deleted the feature/identifier-case-transform branch September 9, 2020 16:07
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