dbDriver

0th

Percentile

Database Interface (DBI) Classes and drivers

These virtual classes and their methods define the interface to database management systems (DBMS). They are extended by packages or drivers that implement the methods in the context of specific DBMS (e.g., Berkeley DB, MySQL, Oracle, ODBC, PostgreSQL, SQLite).

Keywords
interface, database
Usage
dbDriver(drvName, ...)
  dbUnloadDriver(drv, ...)     ## free up all resources
Arguments
drvName
character name of the driver to instantiate.
drv
an object that inherits from DBIDriver as created by dbDriver.
...
any other arguments are passed to the driver drvName.
Details

The virtual class DBIDriver defines the operations for creating connections and defining data type mappings. Actual driver classes, for instance RPgSQL, RMySQL, etc. implement these operations in a DBMS-specific manner.

More generally, the DBI defines a very small set of classes and methods that allows users and applications access DBMS with a common interface. The virtual classes are DBIDriver that individual drivers extend, DBIConnection that represent instances of DBMS connections, and DBIResult that represent the result of a DBMS statement. These three classes extend the basic class of DBIObject, which serves as the root or parent of the class hierarchy.

Value

  • In the case of dbDriver, an driver object whose class extends DBIDriver. This object may be used to create connections to the actual DBMS engine. In the case of dbUnloadDriver, a logical indicating whether the operation succeeded or not.

Side Effects

The client part of the database communication is initialized (typically dynamically loading C code, etc.) but note that connecting to the database engine itself needs to be done through calls to dbConnect.

References

See the Database Interface definition document DBI.pdf in the base directory of this package or http://developer.r-project.org/db.

See Also

dbConnect, dbSendQuery, dbGetQuery, fetch, dbCommit, dbGetInfo, dbListTables, dbReadTable.

Aliases
  • dbDriver
  • dbDriver,character-method
  • dbUnloadDriver
Examples
# create a MySQL instance for capacity of up to 25 simultaneous
# connections.
m <- dbDriver("MySQL", max.con = 25)
p <- dbDriver("PgSQL")

# open the connection using user, password, etc., as
con <- dbConnect(m, user="ip", password = "traffic", dbname="iptraffic")
rs <- dbSubmitQuery(con, 
         "select * from HTTP_ACCESS where IP_ADDRESS = '127.0.0.1'")
df <- fetch(rs, n = 50)
df2 <- fetch(rs, n = -1)
dbClearResult(rs)

pcon <- dbConnect(p, "user", "password", "dbname")
dbListTables(pcon)
Documentation reproduced from package DBI, version 0.1-11, License: GPL (version 2 or later)

Community examples

lorna1661maria@gmail.com at Aug 15, 2018 DBI v0.5-1

``` Library( RPostrgeSQL) # Create a RPostrgesql Driver as pg pg = dbDriver("PostgreSQL") #Pass the database driver as pg in the connection function con = dbConnect(pg, user="Kalm", password="", host="localhost", port=5000, dbname="test_db") ```