r-dbi/DBI

`dbQuoteIdentifier()` ignores names given to `Id()`, uses arguments in order

pnacht opened this issue · 3 comments

See the reprex below. dbQuoteIdentifier() is called twice with the same table data. All that changes is the order in which the Id() arguments were given. Conceptually, this should be irrelevant and return the same identifier, but it's changed. Clearly dbQuoteIdentifier() is ignoring the names given to Id() and simply using the order in which they are defined.

packageVersion("DBI")
#> [1] ‘1.1.2’

packageVersion("odbc")
#> [1] ‘1.3.3’

conn <- DBI::dbConnect(
  # an odbc connection to SQL Server
)

name <- DBI::Id(catalog = "db", schema = "schema", table = "tbl")
DBI::dbQuoteIdentifier(conn, name)
#> <SQL> "db"."schema"."tbl"

# same name, but switching order of arguments
name <- DBI::Id(schema = "schema", catalog = "db", table = "tbl")
DBI::dbQuoteIdentifier(conn, name)
#> <SQL> "schema"."db"."tbl"

DBI::dbDisconnect(conn)

Created on 2022-03-03 by the reprex package (v2.0.1)

This is especially odd given that Id() demands that all its arguments be named. Given that Id() is likely only ever used as an argument to dbQuoteIdentifier() (even if via other functions which eventually call it), it seems odd that the user is forced to define names which aren't actually used.

And names mean nothing

packageVersion("DBI")
#> [1] '1.1.3'
name <- DBI::Id(blah = "element_1", another_blah = "element_2", final_blah = "element_3")
DBI::dbQuoteIdentifier(DBI::ANSI(), name)
#> <SQL> "element_1"."element_2"."element_3"

Created on 2022-11-18 with reprex v2.0.2

Huh, missed that. This is clearly wrong, thanks for reporting.

Fixed in dev.