dm icon indicating copy to clipboard operation
dm copied to clipboard

Learning from SQL Server

Open krlmlr opened this issue 4 months ago • 0 comments

Gives a weird dm?

CC @TSchiefer.

suppressPackageStartupMessages(library(dm))

packageVersion("dm")
#> [1] '1.0.10.9005'
packageVersion("DBI")
#> [1] '1.2.2'
packageVersion("dbplyr")
#> [1] '2.4.0.9000'

# connection to any SQL SERVER DB, please create one that works for you
con <- DBI::dbConnect(
  odbc::odbc(),
  # driver = "ODBC Driver 18 for SQL Server",
  driver = "SQL Server Driver",
  server = Sys.getenv("DM_TEST_DOCKER_HOST"),
  uid = "SA",
  pwd = "YourStrong!Passw0rd",
  port = 1433,
  TrustServerCertificate = "yes"
)

db_schema_create(con, "test")
#> Schema `test` created.
DBI::dbWriteTable(con, DBI::Id(schema = "test", table = "mtcars"), mtcars)

remote_dm <- dm_from_con(con, schema = "test")
#> Keys queried successfully.
#> ℹ Use `learn_keys = TRUE` to mute this message.
remote_dm
#> ── Table source ────────────────────────────────────────────────────────────────
#> src:  Microsoft SQL Server 15.00.2000[@c15a9261a545/master]
#> ── Metadata ────────────────────────────────────────────────────────────────────
#> Tables: `mtcars`
#> Columns: 12
#> Primary keys: 0
#> Foreign keys: 0

# here is the problem: the remote name is `NA`
remote_dm$mtcars %>% dbplyr::sql_render()
#> <SQL> SELECT *
#> FROM NA

DBI::dbExecute(con, "DROP TABLE test.mtcars")
#> [1] 0
db_schema_drop(con, "test")
#> Dropped schema `test`.

krlmlr avatar Apr 13 '24 06:04 krlmlr