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

Escape quotes inside identifiers when quoting strings #1707

Closed
wants to merge 1 commit into from

Conversation

barnettben
Copy link
Collaborator

The utility extension quotedDatabaseIdentifier wraps a string in double quotes, but doesn't do anything with double quotes already inside the string. This commit escapes existing quotes by repeating them:

- identifier
+ "identifier"

- ident_"with"_quotes
+ "ident_""with""_quotes"

It also adds a couple of simple tests.

  • CONTRIBUTING: You have read https://github.com/groue/GRDB.swift/blob/master/CONTRIBUTING.md
  • BRANCH: This pull request is submitted against the development branch.
  • DOCUMENTATION: Inline documentation has been updated.
  • DOCUMENTATION: README.md or another dedicated guide has been updated.
  • TESTS: Changes are tested.
  • TESTS: The make smokeTest terminal command runs without failure.

@barnettben barnettben added the bug label Jan 26, 2025
@groue
Copy link
Owner

groue commented Jan 26, 2025

Thank you @barnettben. Do you have a motivating use case?

@groue
Copy link
Owner

groue commented Jan 26, 2025

Note that there exists a previous issue, which was tagged as "Won't fix": #1325

@barnettben
Copy link
Collaborator Author

Hi @groue. I'm sorry, I'd missed that other issue.

This is such an edge case that I'm not keen on pushing for it. I don't think it's a good practice and agree with your assessment in the linked issue that GRDB should not support it.

I made this PR because I'd come across a database that had quotes in a table name and thought it was a quick job to fix. Cheerfully withdrawn!

Oh, I also learned that this is valid 😅:
CREATE TABLE ""("" "");

@barnettben barnettben closed this Jan 26, 2025
@groue
Copy link
Owner

groue commented Jan 26, 2025

Thanks for taking previous arguments in consideration :-)

@barnettben barnettben deleted the escape-quotes branch January 26, 2025 18:11
@groue groue added wontfix Impossible to fix, or bad idea and removed bug labels Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix Impossible to fix, or bad idea
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants