[R-sig-DB] default driver and connection

Gabor Grothendieck ggrothend|eck @end|ng |rom gm@||@com
Wed Jul 18 18:13:24 CEST 2007


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?  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")
}

# test
f()




More information about the R-sig-DB mailing list