query_funcs: Wrappers for sending queries and fetching results

Query functionsR Documentation

Wrappers for sending queries and fetching results

Description

These functions send a query to the given database, and are the access point for all tcpl functions that query or update the tcpl database.

Usage

tcplQuery(
  query,
  db = getOption("TCPL_DB"),
  drvr = getOption("TCPL_DRVR"),
  tbl = NULL
)

tcplQueryAPI(resource = "data", fld = NULL, val = NULL, return_flds = NULL)

tcplSendQuery(
  query,
  db = getOption("TCPL_DB"),
  drvr = getOption("TCPL_DRVR"),
  tbl = NULL,
  delete = F
)

Arguments

query

Character of length 1, the query string

db

Character of length 1, the name of the tcpl database

drvr

Character of length 1, which database driver to use

tbl

Tables to be read queried

delete

Logical of length 1, execute delete on queried table

Details

Currently, the tcpl package supports the "MySQL", "tcplLite", and "API" database drivers.

tcplQuery returns a data.table object with the query results. tcplSendQuery sends a query, but does not fetch any results, and returns 'TRUE' or the error message given by the database. tcplQueryAPI returns a data.table object with the query results when connected using "API" as driver.

Examples


## Store the current config settings, so they can be reloaded at the end 
## of the examples
conf_store <- tcplConfList()
TCPLlite <- file.path(system.file(package = "tcpl"), "example")
tcplConf(db = TCPLlite, user = NA, host = NA, drvr = "tcplLite")

tcplQuery("SELECT 'Hello World';")

## When using tcplLite, name of table must be passed into tcplQuery
if (conf_store$TCPL_DRVR == 'MySQL') {
  tcplQuery("SELECT * FROM assay;")
} else {
  tcplQuery("SELECT * FROM assay;", tbl='assay')
}
 
## Reset configuration
options(conf_store)


USEPA/CompTox-ToxCast-tcpl documentation built on April 22, 2024, 12:37 p.m.