[R-sig-DB] default driver and connection
Gabor Grothendieck
ggrothend|eck @end|ng |rom gm@||@com
Wed Jul 18 21:35:34 CEST 2007
Thanks. Is there any way to discover whether SQLite or MySQL
was loaded so that I can do something like this:
On 7/18/07, Seth Falcon <sfalcon using fhcrc.org> wrote:
> 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.
Thanks. Is there also a way to discover whether SQLite or MySQL or
neither has been loaded. Note that they could be loaded but not have
an open connection.
Thus, I would like to do this or similar processing:
If only one of MySQL or SQLite is loaded then use that one.
If neither is loaded use SQLite.
Thanks.
More information about the R-sig-DB
mailing list