Skip to content
Prev 42905 / 63424 Next

RC / methods package

John

Here is the definition of the TSMySQLConnection class, and a few other 
things. This is a simplified example that produces the message, but 
unfortunately will not work unless you have a MySQL database to connect 
to. (I do get the same problem with PostgreSQL, and may with SQLLite, 
but I have not tested the last yet.)

require("methods")
require("DBI")
require("RMySQL")

setClassUnion("OptionalPOSIXct",   c("POSIXct",   "logical"))
setClass("conType", representation( drv="character"), "VIRTUAL" )

setClass("TSdb", representation( dbname="character",
     hasVintages="logical", hasPanels="logical"), "VIRTUAL" )


setClass("TSMySQLConnection", contains=c("MySQLConnection", "conType", 
"TSdb"))


setGeneric("TSconnect", def= function(drv, dbname, ...) 
standardGeneric("TSconnect"))


setMethod("TSconnect",   signature(drv="MySQLDriver", dbname="character"),
    definition=function(drv, dbname, ...) {
         con <- dbConnect(drv, dbname=dbname, ...)
	new("TSMySQLConnection" , con, drv="MySQL", dbname=dbname,
   	       hasVintages=dbExistsTable(con, "vintageAlias"),
   	       hasPanels  =dbExistsTable(con, "panels"))
	})

con <- TSconnect(dbDriver("MySQL"), "test")

dbGetQuery(con, "show tables")
Note: Method with signature "MySQLConnection#integer" chosen for 
function "coerce",
  target signature "TSMySQLConnection#integer".
  "dbObjectId#integer" would also be valid
    Tables_in_test
1               A
2               B
 >

The message also seems to go away, even quitting R and restarting to 
clear the cache, if I change the TSconnect method as follow

setMethod("TSconnect",   signature(drv="MySQLDriver", dbname="character"),
    definition=function(drv, dbname, ...) {
         con <- dbConnect(drv, dbname=dbname, ...)
	new("TSMySQLConnection" , con, drv="MySQL", dbname=dbname,
   	       hasVintages=FALSE,
   	       hasPanels  =FALSE)
	})

Why this would happen makes absolutely no sense to me. In the first 
version is  dbExistsTable(con, "vintageAlias") left unevaluated in the 
result from new?

As you can tell, I'm struggling a bit with interpreting the information 
from the note. Also, if it were a warning I could set it to stop, and 
then traceback to what was causing the problem. As it is, it took me a 
fairly long time just to get the fact that the call to dbGetQuery() was 
generating the message. And caching the methods may be good for 
performance, but when things change the second time you call them it 
sure makes debugging difficult.

Best,
Paul
On 12-03-25 03:24 PM, John Chambers wrote: