Learn R Programming

RSQLite (version 0.2-1)

SQLite: Instantiate the SQLite engine from the current R/S session.

Description

This function creates and initializes the SQLite engine. It returns an object that allows you to connect to the SQLite embedded engine.

Usage

SQLite(max.con = 10, fetch.default.rec = 500, force.reload = F)

Arguments

max.con
maximum number of connections that we intended to have open. This can be up to 100, a limit defined at compilation time.
fetch.default.rec
number of records to fetch at one time from the database. (The fetch method uses this number as a default.)
force.reload
should we reload (reinitialize) the package code? Setting this to TRUE allows you to change default settings. Notice that all connections should be closed before re-loading.

Value

  • An object SQLiteManager that extends dbManager and dbObjectId. This object is required to create connections to the embedded SQLite database. There can be many SQLite database instances running simultaneously.

Side Effects

The R/S client part of the database communication is initialized, but note that connecting to database instances needs to be done through calls to dbConnect.

User authentication

SQLite is a single-user database engine, so it has no concept of user.

References

See the Omega Project for Statistical Computing at http://www.omegahat.org for more details on the R/S database interface.

See the Adobe PDF file RS-DBI.pdf under the doc subdirectory of this package, i.e., .path.package("RSQLite")/doc/RS-DBI.pdf.

See the documentation at the SQLite Web site http://www.hwaci/com/sw/sqlite/index.html for details.

Details

This object is a singleton, that is, on subsequent invocations it returns the same initialized object.

This implementation allows the R/S embedded SQLite engine to work with multiple database instances through multiple connections simultaneously.

SQLite keeps each database instance in one single file. The name of the database is the file name, thus database names should be legal file names in the running platform.

See Also

On database managers:

dbManager SQLite load unload

On connections, SQL statements and resultSets:

dbExecStatement dbExec fetch quickSQL

On transaction management:

commit rollback

On meta-data:

describe getVersion getDatabases getTables getFields getCurrentDatabase getTableIndices getException getStatement hasCompleted getRowCount getAffectedRows getNullOk getInfo

Examples

Run this code
# create a SQLite instance and create one connection.
   m <- dbManager("SQLite")
   
   # initialize a new database "base.dbms" in the current directory
   # and copy some data.frame from the base package into it
   
   con <- dbConnect(m, dbname = "base.dbms")
   data(USArrests)
   assignTable(con, "USArrests", USArrests, overwrite = T)
   
   # query
   rs <- dbExecStatement(con, "select * from USArrests")
   d1 <- fetch(rs, n = 10)      # extract data in chunks of 10 rows
   hasCompleted(rs)
   d2 <- fetch(rs, n = -1)      # extract all remaining data
   hasCompleted(rs)
   close(rs)
   getTables(con)

Run the code above in your browser using DataLab