[R-sig-DB] default driver and connection

Seth Falcon @|@|con @end|ng |rom |hcrc@org
Wed Jul 18 20:52:17 CEST 2007


Hi,

[The following comments hold for RSQLite.  I'm pretty sure they hold
for all DBI, but haven't gone and looked to verify the code.]

"Gabor Grothendieck" <ggrothendieck using gmail.com> writes:
> Is there a way of finding out if the driver is loaded and if there
> are any open connections in RSQLite or other database and what
> they are?

The driver is implemented as a singleton so there is no need to worry
about multiple calls to dbDriver("SQLite") or more simply SQLite().
The driver gets loaded on first invocation of SQLite() and subsequent
calls simply return the existing instance.

> Even better would be if the code below could work regardless
> of whether an SQLite or MySQL connection was open.  I have written pseudocode
> in the places where I don't know how to access the functionality.
> If all this exists is there an example?  Thanks.
>
> # returns first three rows of iris
> # loading any driver and opening any connection if need be
> f <- function(m, con, dbname = ":memory:") {
>        if (missing(m) {
>                m <- if (no.data.base.drivers.loaded)
>                        dbDriver("SQLite")
>                else loaded.driver
>        }
>        if (missing(con)) {
>                con <- if (no.connections.open)
>                        dbConnect(m, dbname)
>                active.connection
>        }
>        dbWriteTable(con, "iris", iris)
>        dbGetQuery(con, "select * from iris limit 3")
> }

dbListConnections(SQLite()) will tell you about open connections to
the SQLite driver.

+ seth

-- 
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
http://bioconductor.org




More information about the R-sig-DB mailing list