RMariaDB
RMariaDB copied to clipboard
allow columns in dbQuoteIdentifier()
This allows quoting columns with Id()
and dbQuoteIdentifier()
and fixes the quoting of a schema, closes #254.
I've added tests for dbQuoteIdentifier()
and dbUnquoteIdentifier()
from RPostgres, too.
library(RMariaDB)
con <- mariadbDefault()
# quote column
column_id <- Id(schema = "myschema", table = "mytable", column = "mycolumn")
dbQuoteIdentifier(con, column_id)
#> <SQL> `myschema`.`mytable`.`mycolumn`
# quote schema without dot
(schema_id <- dbQuoteIdentifier(con, Id(schema = "myschema")))
#> <SQL> `myschema`
# glue_sql() example: https://glue.tidyverse.org/reference/glue_sql.html
library(glue)
iris2 <- iris
colnames(iris2) <- gsub("[.]", "_", tolower(colnames(iris)))
DBI::dbWriteTable(con, "iris", iris2)
iris_db <- "iris"
nicknames_db <- "nicknames"
nicknames <- data.frame(
species = c("setosa", "versicolor", "virginica"),
nickname = c("Beachhead Iris", "Harlequin Blueflag", "Virginia Iris"),
stringsAsFactors = FALSE
)
DBI::dbWriteTable(con, nicknames_db, nicknames)
cols <- list(
DBI::Id(table = iris_db, column = "sepal_length"),
DBI::Id(table = iris_db, column = "sepal_width"),
DBI::Id(table = nicknames_db, column = "nickname")
)
iris_species <- DBI::Id(table = iris_db, column = "species")
nicknames_species <- DBI::Id(table = nicknames_db, column = "species")
query <- glue_sql("
SELECT {`cols`*}
FROM {`iris_db`}
JOIN {`nicknames_db`}
ON {`iris_species`}={`nicknames_species`}",
.con = con
)
query
#> <SQL> SELECT `iris`.`sepal_length`, `iris`.`sepal_width`, `nicknames`.`nickname`
#> FROM `iris`
#> JOIN `nicknames`
#> ON `iris`.`species`=`nicknames`.`species`
DBI::dbGetQuery(con, query, n = 5)
#> sepal_length sepal_width nickname
#> 1 5.1 3.5 Beachhead Iris
#> 2 4.9 3.0 Beachhead Iris
#> 3 4.7 3.2 Beachhead Iris
#> 4 4.6 3.1 Beachhead Iris
#> 5 5.0 3.6 Beachhead Iris
dbExecute(con, glue_sql("DROP TABLE {`nicknames_db`}, iris", .con = con))
#> [1] 0
dbDisconnect(con)
I noticed that a table t1
was left behind in the database, so I added temporary = TRUE
to two dbWriteTable()
tests.
Let's make https://github.com/r-dbi/RPostgres/pull/372 work first.
Note that the list_objects_features
test (in DBItest) is skipped in RMariaDB, which is why tests are passing here. I.e. I think we should not skip it here, but we might have to modify it, so that it tests better what we want it to test.
https://github.com/r-dbi/RMariaDB/blob/0e17617446acf4b66faf19448a12665c7bf3be82/tests/testthat/helper-DBItest.R#L20-L21
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 using Aviator.
Again, implemented independently, but the tests are fine. Thanks!
This pull request failed to merge: PR cannot be automatically rebased, please rebase manually to continue. Once the issues are resolved, remove the blocked
label and re-queue the pull request. Note that the pull request will be automatically re-queued if it has the mergequeue
label.
Additional debug info: Failed to rebase this PR onto the latest changes from the base branch. You will probably need to rebase this PR manually and resolve conflicts).
This pull request failed to merge: PR cannot be automatically rebased, please rebase manually to continue. Once the issues are resolved, remove the blocked
label and re-queue the pull request. Note that the pull request will be automatically re-queued if it has the mergequeue
label.
Additional debug info: Failed to rebase this PR onto the latest changes from the base branch. You will probably need to rebase this PR manually and resolve conflicts).
This pull request failed to merge: some CI status(es) failed. Once the issues are resolved, remove the blocked
label and re-queue the pull request. Note that the pull request will be automatically re-queued if it has the mergequeue
label.
Failed CI(s): Smoke test: stock R