Read-only query over the local Zotero database
zotLocalQuery.RdOpens the local zotero.sqlite database in read-only mode. Local records
can lag the Web API until the desktop client synchronizes, and WAL mode can
make recent local changes temporarily unavailable to another reader.
Usage
zotLocalQuery(
sql,
params = list(),
path = file.path(Sys.getenv("HOME"), "Zotero", "zotero.sqlite")
)Details
The database connection is opened with SQLite's read-only flag, without
issuing any PRAGMA, and closed when the query finishes. zotLocalQuery()
does not copy or modify the desktop database. The caller remains
responsible for supplying a read-only SQL statement. The default path is
~/Zotero/zotero.sqlite; pass path explicitly for a portable
installation or a custom Zotero data directory.
While Zotero is writing, it locks the database. A read waits for the write
to finish for up to LOCALWAIT, a package constant of 10000 milliseconds
(10 s). If the database is still locked after that wait, the query fails
with a zotLocalError naming the wait and the original SQLite error; any
other SQLite error propagates unchanged.
Examples
Path <- tempfile(fileext = ".sqlite")
Connection <- DBI::dbConnect(RSQLite::SQLite(), Path)
DBI::dbWriteTable(Connection, "items", data.frame(key = c("A", "B")))
DBI::dbDisconnect(Connection)
zotLocalQuery("SELECT key FROM items ORDER BY key", path = Path)
#> key
#> <char>
#> 1: A
#> 2: B
unlink(Path)