db_locks | R Documentation |
This set of function adds a simple locking system to database tables.
lock_table()
adds a record in the schema.locks table with the current time and R-session process id.
unlock_table()
removes records in the schema.locks table with the target table and the R-session process id.
When locking a table, the function will check for existing locks on the table and produce an error a lock is held by a process which no longer exists. In this case, the lock needs to be removed manually by removing the record from the lock table. In addition, the error implies that a table may have partial updates that needs to be manually rolled back.
lock_table(conn, db_table, schema = NULL)
unlock_table(conn, db_table, schema = NULL, pid = Sys.getpid())
conn |
( |
db_table |
( |
schema |
( |
pid |
( |
lock_table()
returns the TRUE
(FALSE
) if the lock was (un)successfully added.
If a lock exists for a non-active process, an error is thrown.
unlock_table()
returns NULL
(called for side effects).
conn <- DBI::dbConnect(RSQLite::SQLite())
lock_table(conn, "test_table") # TRUE
unlock_table(conn, "test_table")
DBI::dbDisconnect(conn)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.