If I create a normal Z DBI database connection, is there a way to use this handle to directly get the corresponding DBI $dbh for that connection? I would like to use the persistence of Zope to get rid of connection-penalty, but I need to use the DBI API to be able to make advanced scripts which calls multiple SQL-statements without the need to make Z SQL Methods for each one... I've looked over Zope.pm (zoperl), and taken a small look at the relevant ZDBI_DA files, but the solution isn't obvious. Can I use it something like this? ----------------- cut here ---------------------- package ZopeExt::return_something; use Zope; # dbi_database_connection is defined in the Zope object tree # DBH is the field described in the Zope.pm BEGIN sub. # Is this correct? my $dbh=$Zope::DBH{'dbi_database_connection'}; my $sth=$dbh->prepare('select * from table'); $sth->execute; my @row=$sth->fetchrow; return @row; 1; ---------------- cut here ----------------------- BTW: I sent this to the zope-perl mailinglist, but it doesn't look like there is much activity on that list.
I would guess (without knowing) that the dbi_database_connection object is to the Zope Object Database; not an RDBMS interface. What you would need to do is access the actual database connection object inside the ZODB and invoke it to get a Python connection object, then do whatever magic you need to to invoke its execute() method from Perl, followed by invoking its fetch{one|many|all}method. I dont know how to do that myself. Robin Smidsrød wrote:
If I create a normal Z DBI database connection, is there a way to use this handle to directly get the corresponding DBI $dbh for that connection?
I would like to use the persistence of Zope to get rid of connection-penalty, but I need to use the DBI API to be able to make advanced scripts which calls multiple SQL-statements without the need to make Z SQL Methods for each one...
I've looked over Zope.pm (zoperl), and taken a small look at the relevant ZDBI_DA files, but the solution isn't obvious.
Can I use it something like this?
----------------- cut here ---------------------- package ZopeExt::return_something;
use Zope;
# dbi_database_connection is defined in the Zope object tree # DBH is the field described in the Zope.pm BEGIN sub. # Is this correct? my $dbh=$Zope::DBH{'dbi_database_connection'};
my $sth=$dbh->prepare('select * from table'); $sth->execute;
my @row=$sth->fetchrow;
return @row;
1;
---------------- cut here -----------------------
BTW: I sent this to the zope-perl mailinglist, but it doesn't look like there is much activity on that list.
-- Matt Kromer Zope Corporation http://www.zope.com/
participants (2)
-
Matthew T. Kromer -
Robin Smidsrød