Skip to content
Prev 695 / 1559 Next

problem with ROracle calls from a package

When I did this I defined the connection inside the function.

That is,

myfun <- function( dbc, ...) {
   ## dbc is a list with username, password, etc to the database

   dbm <- Oracle()
   con <- dbConnect(dbm, user = dbc$user, dbname = dbc$db, password = dbc$pass)

   ## build the query, then
   res <- dbGetQuery(con, sql)
  ....
}

And it works.

I also found it helpful to have something like this after defining 
dbm and before defining con

     tmp <- dbListConnections(dbm)
     if (length(tmp) > 5)
         for (ic in tmp) dbDisconnect(ic)


I also put this in there somewhere:

     on.exit({
         dbDisconnect(con)
         dbUnloadDriver(dbm)
     })

-Don
At 9:59 PM -0400 8/3/09, Rajarshi Guha wrote: