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

dbExistsTable(conn, Id(schema = "INFORMATION_SCHEMA", table = "TABLES")) throws error (should return FALSE?) #498

Closed
kjellpk opened this issue Feb 29, 2024 · 2 comments · Fixed by #499

Comments

@kjellpk
Copy link
Contributor

kjellpk commented Feb 29, 2024

dbExistsTable borks when conn is a SQLiteConnection and name is an Id with schema = "INFORMATION_SCHEMA" and table = "TABLES". I was expecting it to return FALSE.

library(DBI)
conn <- dbConnect(RSQLite::SQLite(), ":memory:")
dbExistsTable(conn, Id(schema = "INFORMATION_SCHEMA", table = "TABLES"))
# Error: no such table: INFORMATION_SCHEMA.sqlite_master
dbDisconnect(conn)
@krlmlr krlmlr added the bug label Mar 3, 2024
@krlmlr
Copy link
Member

krlmlr commented Mar 3, 2024

Thanks, good catch. I suspect we want to check if the schema exists first. Would you like to contribute?

@kjellpk
Copy link
Contributor Author

kjellpk commented Mar 4, 2024

Happy to help.

After a bit of Googling, my understanding is that schemas in SQLite (here I am using the word schema to mean the part before the . in schema.table) are the names of the ATTACHed databases. It seems like the only way there could ever be a schema other than "main" would be if ATTACH is used in a SQL statement.

The following code returns a character vector of the attached databases:

dbGetQuery(conn, "SELECT name FROM pragma_database_list;")$name

I'll see if I can find a good place to put a check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants