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

feat: dbUnquoteIdentifier() creates Id() objects without component names #422

Merged
merged 4 commits into from Dec 20, 2023

Conversation

hadley
Copy link
Member

@hadley hadley commented Nov 10, 2023

Fixes #421

@hadley hadley requested a review from krlmlr November 10, 2023 16:19
Copy link
Contributor

aviator-app bot commented Nov 10, 2023

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This PR was merged manually (without Aviator). Merging manually can negatively impact the performance of the queue. Consider using Aviator next time.


See the real-time status of this PR on the Aviator webapp.

Use the Aviator Chrome Extension to see the status of your PR within GitHub.

@krlmlr
Copy link
Member

krlmlr commented Nov 10, 2023

So, we're losing the names in the output of dbUnquoteIdentifier() ? I'll check how this and the current state of DBI is compatible with DBItest, perhaps we need to adapt there, or there are reasons why the behavior is the way it is now.

Could be that we lose (or have already lost) dbListObjects() functionality. We don't want to lose it because the IDE depends on it: https://github.com/rstudio/rstudio/blob/6b9436f529581d79c43abbea8cb08a0f6a3cdd60/src/cpp/session/modules/sql/SessionSql.R#L351.

@hadley
Copy link
Member Author

hadley commented Nov 11, 2023

Hmmmm, lets explicitly test for that, and maybe see if we can repair in dbListObjects() if needed.

@hadley
Copy link
Member Author

hadley commented Nov 13, 2023

Hmmm, it appears this only affects autocomplete (and I'm not sure in what context) so it might be ok to break temporarily. The cran github org seems to be down right now, but it looks like maybe only RMariaDB is the only dbListObjects() method to call dbiUnquoteIdentifier(). RPostgres assumes that prefix is an Id and RSQLite doesn't have a dbListObjects() method.

So all-in-all I think this is likely to be a low risk change.

@hadley
Copy link
Member Author

hadley commented Nov 14, 2023

But overall I think this is unlikely to cause problems for folks.

Copy link
Member

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

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

Thanks. Do we still need this right now, if the user has a way to create Id objects without naming the components? Why is it important that dbUnquoteIdentifier() returns unnamed Id objects?

How do you feel about making this opt-in, with a new named argument to dbUnquoteIdentifier() ? That would give me a little more peace of mind.

if (is(x, "SQL")) {
id_rx <- '(?:"((?:[^"]|"")+)"|([^". ]+))'
# Determine quoting character
quote_char <- substr(dbQuoteIdentifier(conn, ""), 1, 1)
Copy link
Member

Choose a reason for hiding this comment

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

Should we handle the case of brackets [] used for quoting?

if (is(x, "SQL") || is.character(x)) {
x <- lapply(x, unquote, quote_char = quote_char)
lapply(x, Id)
} else if (is(x, "Id")) {
Copy link
Member

Choose a reason for hiding this comment

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

That would be "UnnamedId" after #429.

@krlmlr krlmlr changed the title A more general strategy for unquoting feat: dbUnquoteIdentifier() creates Id() objects without component names Dec 20, 2023
@krlmlr krlmlr merged commit 69f3ae3 into main Dec 20, 2023
@krlmlr krlmlr deleted the unquote branch December 20, 2023 14:58
@krlmlr
Copy link
Member

krlmlr commented Dec 20, 2023

Thanks!

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.

Update dbUnquoteIdentifier
2 participants