[R-sig-DB] DBI package

Paul Gilbert pg||bert902 @end|ng |rom gm@||@com
Thu Oct 17 20:55:03 CEST 2013


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:
>>> I'm sure you have a list of things you would like to do. Just in case
>>> you are not aware, let me mention one recent problem I am having with
>>> DBI trying to use the new more strictly enforced modern approach to
>>> Imports/Depends. The DBI function call dbDriver("MySQL") fails in my
>>> package TSMySQL if I list RMySQL in Imports rather than Depends. It
>>> cannot find the function MySQL in RMySQL.
>>
>> I agree - I solved it by adding RSQLite to the Depends section, but it
>> is only a workaround.
>
> Good point - I added a couple of notes on the issue at
> https://github.com/r-dbi/DBI/issues/1
>
> Hadley
>




More information about the R-sig-DB mailing list