-
Notifications
You must be signed in to change notification settings - Fork 55
Quote Entities with Double Quotes #39
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
|
Thanks for the pull request :) Can you fix the linting errors? Then I can merge and issue a release sometime in the next day or so. |
|
I actually specifically did not add double quotes because of the documentation in sqlite https://sqlite.org/quirks.html#double_quoted_string_literals_are_accepted
It is also recommended to have DQS disabled, but I did not choose to do that out right because people may have fragments that use double quotes. https://sqlite.org/compile.html#dqs |
|
This PR won't hurt anything and I do think that sqlite will support it forever due to trying to maintain some backwards compatibility with mysql. |
|
@warmwaffles Thanks for providing some context! If you feel like we shouldn't quote enties because of the mentioned drawbacks that's also understandable for me. Maybe as an alternative we could documented that this adapter does not quote the entities and therefore only allows keywords as names in the places where sqlite supports it out of the box. Let me know which way you prefer. |
This patch ensures that we actually quote entities (prefix, table name, column name, alias) with double quotes(`"`). This is important since it allows to use otherwise reserved keywords like `order` to be used. The tests have been adapted to reflect this change. Closes elixir-sqlite#38
|
One solution is to have some special cases that we double quote because in sqlite's documentation they suggest using double quotes for reserved keywords. So we'd need to have a couple matching methods like this defp quote_entity("from"), do: [~Q("from")]
defp quote_entity("with"), do: [~Q("with")]
defp quote_entity("order"), do: [~Q("order")]
# ... etc ...
defp quote_entity(val), do: [val]But this makes me just say to quote everything. @kevinlang do you have any opinions on this? |
|
I think my interpretation of that document is different. It looks to be specifically referring to double-quoting literals as being incorrect (and via a compile time flag, opt-out), since double quoting is reserved for identifiers. I see that the Postgres adapter double quotes all identifiers by default. As such, I don't see any disadvantage, and only an advantage, to double quoting identifiers. Am I missing something? I would go so far as to say that having double quoted literal be disabled by default via |
|
To confirm my understanding, I loaded up the With that done, double quoting entities still works: It just raises an error when double quoting the literal: But everything else works as expected: And sure enough, if I reload the CLI without disabling those options, we can see the behavior of the misfeature: |
|
Excellent, so let's merge this fix then. I misunderstood the misfeature. |
I think the only potential downside (the one I was thinking of when writting my previous comment) would be that it would treat wrongly spelled identifiers as literals since would always just quote them.
I think that would actually be the best option if we feel like sqlite users don't rely on this missfeature to much. |
|
Thanks for the work on this. |
This patch ensures that we actually quote entities (prefix, table name, column name, alias) with double quotes(
").This is important since it allows to use otherwise reserved keywords like
orderto be used.The tests have been adapted to reflect this change.
Closes #38