safeSQL: Return a function that safely performs sql queries on a...

Description Usage Arguments Value Note Author(s)

Description

This uses the 'params' parameter for DBI::dbGetQuery and DBI::dbExecute (for RSQLite and ":" parameters) or dbQuoteStrings (for MySQL or RSQLite " prevent e.g. SQL injection attacks.

Usage

1
safeSQL(con, busyTimeout = 300)

Arguments

con

RSQLite connection to database, as returned by dbConnect(SQLite(), ...), or character scalar giving path to SQLite database, or MySQLConnection, or dplyr::src

busyTimeout

how many total seconds to wait while retrying a locked database. Default: 300 (5 minutes). Uses pragma busy_timeout to allow for inter-process DB locking. Only implemented for SQLite connections, as it appears unnecessary for MySQL connections.

Value

a function, S with class "safeSQL" taking two or more parameters:

For RSQLite, these items are passed to data.frame, along with the parameter stringsAsFactors=FALSE.

Note

for convenience, access is provided to some safeSQL internals, via the "$" method for class safeSQL

For MySQL, only one line of an insert can be provided per call; i.e. there is no SendPreparedQuery method to allow binding a data.frame's data to a prepared query. Moreover, character parameters are quoted using dbQuoteString unless the parameter is wrapped in DBI::SQL, or if you specify .QUOTE=FALSE

safeSQL is meant for multi-process access of a DB with small, fast queries; this is the case for the server.sqlite database that holds job information. The longer accesses required by e.g. the tag finder are handled by locking the receiver DB via lockSymbol().

For both MySQL and SQLite connections, queries that fail due to deadlock-prevention by the database are retried after a random wait of 0 to 10 seconds.

Author(s)

John Brzustowski jbrzusto@REMOVE_THIS_PART_fastmail.fm


jbrzusto/motusClient documentation built on May 30, 2019, 4:33 p.m.