[Zope] Using persistent DBI handle in PerlExternalMethod

Robin Smidsrød robin@smidsrod.no
Sat, 13 Apr 2002 16:15:39 +0200


This is a multi-part message in MIME format.

------=_NextPart_000_00C6_01C1E306.739FDC90
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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=3D$Zope::DBH{'dbi_database_connection'};

my $sth=3D$dbh->prepare('select * from table');
$sth->execute;

my @row=3D$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.

------=_NextPart_000_00C6_01C1E306.739FDC90
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2715.400" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>If I create a normal Z DBI database connection, is there a way to =
use=20
this<BR>handle to directly get the corresponding DBI $dbh for that=20
connection?<BR><BR>I would like to use the persistence of Zope to get =
rid<BR>of=20
connection-penalty, but I need to use the DBI API to be able to<BR>make =
advanced=20
scripts which calls multiple SQL-statements without the need<BR>to make =
Z SQL=20
Methods for each one...<BR><BR>I've looked over Zope.pm (zoperl), and =
taken a=20
small look at the<BR>relevant ZDBI_DA files, but the solution isn't=20
obvious.<BR><BR>Can I use it something like =
this?<BR><BR>----------------- cut=20
here ----------------------<BR>package =
ZopeExt::return_something;<BR><BR>use=20
Zope;<BR><BR># dbi_database_connection is defined in the Zope object =
tree<BR>#=20
DBH is the field described in the Zope.pm BEGIN sub.<BR># Is this =
correct?<BR>my=20
$dbh=3D$Zope::DBH{'dbi_database_connection'};<BR><BR>my=20
$sth=3D$dbh-&gt;prepare('select * from =
table');<BR>$sth-&gt;execute;<BR><BR>my=20
@row=3D$sth-&gt;fetchrow;<BR><BR>return =
@row;<BR><BR>1;<BR><BR>----------------=20
cut here -----------------------<BR><BR><BR><BR><FONT face=3DArial =
size=3D2>BTW: I=20
sent this to the zope-perl mailinglist, but it doesn't look like there =
is much=20
activity on that list.</FONT></DIV></BODY></HTML>

------=_NextPart_000_00C6_01C1E306.739FDC90--