Skip to content
Prev 1316 / 1559 Next

DBI package

On the githib link below, Seth comments:

 >I'm not all that clear of the value of dbDriver as a generic. The
 >arguments needed to connect to a particular backend are at the crux of
 >the "what is different". Each package already (I think) has a function
 >like SQLite(). I wonder if we should move to have that be the way to
 >get a driver.

In several of my packages using DBI the user would do something like
   con1 <- TSconnect("MySQL", dbname="test")
   con2 <- TSconnect("SQLite", dbname="test")

(The packages are:TSfame, TSjson, TSOracle, TSzip, TSgetSymbol,
  TSMySQL, TSPostgreSQL, TSSQLite, TShistQuote, TSodbc, TSsdmx,
  TSxls.  See http://tsdbi.r-forge.r-project.org/)

The TSconnect call uses a generic:
setGeneric("TSconnect", def= function(drv, dbname, ...) 
standardGeneric("TSconnect"))

and method:
setMethod("TSconnect",   signature(drv="character", dbname="character"),
    definition=function(drv, dbname, ...)
              TSconnect(dbDriver(drv), dbname=dbname, ...))

and there are methods when the drv has a class like "SQLiteDriver" as 
returned by the dbDriver() call.

I think Seth's proposal would mean that users would need to change the 
TSconnect calls to something like
   con1 <- TSconnect(MySQL(), dbname="test")
   con2 <- TSconnect(SQLite(), dbname="test")

I don't object to making changes if they fix a problem, but I don't 
think this actually fixes the problem that I pointed out. The user 
session still needs to find the function MySQL() or SQLite(), which 
means my package need to indicate RMySQL or RSQLite as Depends rather 
than Imports.

It also makes handling several driver possiblities more difficult. 
Currently this can be done with a vector of strings, but the change 
would require using functions, some of which may not be attached.

Paul
On 13-10-17 10:44 AM, Hadley Wickham wrote: