RSQLite icon indicating copy to clipboard operation
RSQLite copied to clipboard

Add Id method to `dbExistsTable` to address issue #498

Open kjellpk opened this issue 1 year ago • 2 comments

Add an Id method to dbExistsTable. When a schema is present in the Id, check that schema is the name of an ATTACHed database and return FALSE if not.

I also made some tests but wasn't sure where to put them.

test_that("dbExistsTable works with compound Id", {
  expect_no_error(
    conn <- dbConnect(RSQLite::SQLite(), ":memory:")
  )

  expect_type(
    dbExistsTable(conn, Id(schema = "INFORMATION_SCHEMA",
                           table = "TABLES")),
    "logical"
  )

  expect_no_error(
    dbWriteTable(conn, "Iris", iris)
  )

  expect_true(
    dbExistsTable(conn, Id(schema = "main", table = "Iris"))
  )

  expect_true(
    dbExistsTable(conn, Id(able = "Iris"))
  )

  expect_false(
    dbExistsTable(conn, Id(schema = "mian", table = "Iris"))
  )

  expect_no_error(
    dbCreateTable(conn, "IrisTemp", iris, temporary = TRUE)
  )

  expect_false(
    dbExistsTable(conn, Id(schema = "temp", table = "Iris"))
  )

  expect_true(
    dbExistsTable(conn, Id(schema = "temp", table = "IrisTemp"))
  )

  expect_true(
    dbExistsTable(conn, Id(table = "IrisTemp"))
  )

  expect_no_error(
    dbDisconnect(conn)
  )
})

kjellpk avatar Mar 06 '24 03:03 kjellpk