[R-sig-DB] Re: RS-DBI using embedded Perl DBI

Duncan Temple Lang dunc@n @end|ng |rom re@e@rch@be||-|@b@@com
Sat May 5 01:24:05 CEST 2001


On Fri, May 04, 2001 at 06:32:18PM -0400, T Jake Luciani wrote:
> All,
> 
> I've attached my implementation of David James RS-DBI interface using Perl DBI  (R Package).  I've found it to be quite quick.  The nice thing is you can connect to any database perl can.
> 
> The only big difference in S code is, you now have to specify the type of database your connecting to as well as host and port if applicable.  
> 

Great. Saikat, David and I did the same sort of thing with JDBC.  It
is a good idea to leverage the existing code for the various
databases.  In S-JDBC interface, we were using the SJava package to
actually make the connection to Java. You appear to be using direct C
code to connect to Perl rather than the RSPerl package which provides
a way for embedding Perl in R. I do recognize some of the code that
seems to be taken from that package, so perhaps you are using it but I
don't thing directly, if it all.  You might find that using that
package simplifies the code a bit and makes it easier for others to
experiment with.

> I've only tested this with Oracle. An example is:
> 
> library(RSPerlDBI)
> ora <- dbManager("PerlDBI")
> con <- dbConnect(ora, user = "query", password = "query", dbname = "rduxu",dbtype = "Oracle")
> result <- quickSQL(con, "select * from ALL_TABLES")   
> 
> Unfortunetly if theres any Perl DBI errors it kills R.  Any ideas Duncan?
> 

Yep. The problem is that some errors in Perl jumps straight to exit()
and _exit() rather than signalling an exception and returning control
to the caller, in this case the C code invoked from R.  The RSPerl
package has the same difficulty and I haven't found time to fix it
yet. A simple solution is to provide an alternative implementation of
Perl's fatal error handler routine. Then, when one links against the
Perl library to create RSPerlDBI.so, the routine in your C code will
be linked and used. This can be a bit tricky at times depending on
linkers, how Perl was compiled, etc. But, if your routine is called,
then it should throw and S error and the execution stack will return.
That's the basic approach I use in embedding unless I have more
specific needs.


BTW, I am on the r-sig-db mailing list, so there's no need mail me
separately.

> Feel free to make suggestions, etc...
> 
> Thanks,
> 
> Jake
> 
> -------------------------
> T Jake Luciani
> Software Developer
> Optoelectronics Unit
> Agere Systems
> jake using agere.com
> 
> 



-- 
_______________________________________________________________

Duncan Temple Lang                duncan using research.bell-labs.com
Bell Labs, Lucent Technologies    office: (908)582-3217
700 Mountain Avenue, Room 2C-259  fax:    (908)582-3340
Murray Hill, NJ  07974-2070       
         http://cm.bell-labs.com/stat/duncan



More information about the R-sig-DB mailing list