opm_dbput: Database I/O for 'opm'

Description Usage Arguments Details Value See Also Examples

Description

Methods for inserting, querying and deleting OPMX objects into or from (SQL-based) relational databases using RODBC.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
  ## S4 method for signature 'integer,RODBC'
opm_dbclear(object, conn, map.tables = NULL, klass = "OPM_DB")

  ## S4 method for signature 'character,RODBC'
opm_dbfind(object, conn, map.tables = NULL, klass = "OPM_DB")

  ## S4 method for signature 'integer,RODBC'
opm_dbget(object, conn,
    map.tables = NULL, include = 2L, klass = c(opm_dbclass(include), "MOPMX")) 

  ## S4 method for signature 'DBTABLES,RODBC'
opm_dbnext(object, conn, map.tables = NULL)

  ## S4 method for signature 'DBTABLES,RODBC'
opm_dbput(object, conn,
    map.tables = NULL, start = opm_dbnext(object, conn, map.tables)) 

Arguments

object

OPMX, MOPMX or OPM_DB object, integer vector containing real or potential primary keys of a database table, or character scalar containing a partial SQL query (the part after the ‘WHERE’ keyword).

conn

Database connection object. RODBC objects as created by the RODBC package are supported.

map.tables

Passed as do_map argument to by from the pkgutils package. Necessary if table names that deviate from the defaults are to be used.

klass

Character vector indicating one or several class names. For PM data this argument should not be changed.

include

Integer scalar indicating whether aggregated data (1) or aggregated and discretised data (2) or neither (0) should be added to the result. The numeric method of opm_dbnext needs the same kind of object argument.

start

Integer vector determining the minimum primary keys to which those in object should be coerced. Necessary for appending to a database table without overwriting previously inserted data.

...

Optional arguments passed between the methods.

Details

The RODBC methods use a simple quoting scheme for table and column names.

Note that the deletion mechanism is based on ON DELETE CASCADE. To enable this in SQLite, PRAGMA foreign_keys = ON; has to be called each time a database is opened. See the according demo entry.

Value

The main functions are those for create, search, read and delete operations:

Regarding the helper functions, opm_dbnext returns an integer scalar that is suitable as start argument of opm_dbput, whereas opm_dbclass returns a character scalar with the name of the intermediary class (derived from OPM_DB) to be created for database I/O. These need not normally be called by an opm user.

For checking whether a database (connection) is correctly set up, opm_dbcheck is available in the opm package, which returns a character vector whose elements are either ok or a description of the error that has occurred at that step of the checking process.

See Also

DBI::make.db.names pkgutils::by opm::opm_dbcheck

Other res: cor.test

Examples

1
2
3
4
5
6
7
8
9
# The SQL files for generating the expected database tables. Tables can
# be renamed, but then an according 'map.tables' argument must be used.
library(opm)
opm_files("sql")

# Usage examples are given in these demos. An according database must be
# made accessible beforehand.
if (interactive())
  demo(package = "opmextra")

opmextra documentation built on May 2, 2019, 5:49 p.m.

Related to opm_dbput in opmextra...