[Zope-Perl] ZOPE DBI adapter - feedback and patch (please review)
Joseph Wayne Norton
norton@alum.mit.edu
Wed, 30 Aug 2000 23:47:26 +0900 (JST)
Gisle -
I have finally been able to do a little work with the zope DBI
adapter. Good stuff!
1) FYI - I'm able to connect to oracle with the following connection
string:
<user>:<pass>@dbi:Oracle:host=<host>;sid=<sid>
where <> is replaced with the actual values. I had to look at your
code to see how the user and pass variables are being passed.
2) Please see the following URL:
http://www.zope.org/Members/Roug/select_with_multiple
The construct <dtml-var sql_delimiter> is intended to allow for
multiple queries in one SQL_method.
I made a patch (see end of file) to your dbi.py code to support
this feature. I *nearly* mimiced the behavior of the postgres
adapator -- but removed the restriction of not allowing selects in
a multi-query SQL method -- it seems too restrictive to me.
**WARNING** I'm not an expert on the behavior of the ZOPE database
adapter and SQL methods -- Please review.
3) It would be convienent to also install the dbi.py into the python
site library during the setup.py execution. I think it is
currently left out.
regards,
- joe n
Gisle Aas writes:
> Joseph Wayne Norton <norton@alum.mit.edu> writes:
>
> > 4) I tried the following for the Zope DBI database adapter ...
> >
> > dbi:Oracle:host=namaste.tokyo.att.ne.jp;sid=namaste
> >
> > but it returned invalid connection string. Is there any specific
> > format?
>
> Did you ever get this to work?
>
> --Gisle
>
>
--
--
Joseph Norton
norton@alum.mit.edu
+81-3-3822-6936
2-10-7 Tabata, Kita-ku, Tokyo 114-0014, Japan ($B")(B114-0014 $BEl5~ETKL6hEDC<#2CzL\(B10-7)
*** db.py.orig Wed Aug 30 22:19:57 2000
--- db.py Wed Aug 30 23:34:59 2000
***************
*** 103,109 ****
"""Db connection implementation"""
__version__='$Revision: 1.1 $'[11:-2]
! from string import find, split
def make_item(n,t,p):
if 1 <= t <= 12:
--- 103,109 ----
"""Db connection implementation"""
__version__='$Revision: 1.1 $'[11:-2]
! from string import find, split, strip
def make_item(n,t,p):
if 1 <= t <= 12:
***************
*** 128,139 ****
self.db = dbi.connect(connection, user, auth,
RaiseError = 1,
PrintError = 0,
! AutoCommit = 1,
)
def query(self,query_string, max_rows=9999999):
dbh=self.db
! sth = dbh.prepare(query_string)
! rows = sth.execute()
! return map(make_item, sth["NAME"], sth["TYPE"], sth["PRECISION"]), \
! sth.fetchall_arrayref()
--- 128,151 ----
self.db = dbi.connect(connection, user, auth,
RaiseError = 1,
PrintError = 0,
! AutoCommit = 0, # JWN see below
)
def query(self,query_string, max_rows=9999999):
dbh=self.db
! try:
! # JWN - hard-coded <dtml-var sql_delimiter>
! queries=filter(None, map(strip,split(query_string, '\0')))
! sth=None
! rows=None
! for qs in queries:
! sth = dbh.prepare(qs)
! rows = sth.execute()
! except:
! dbh.rollback()
! raise
! else:
! dbh.commit()
! # JWN - only return the results of the last query
! return map(make_item, sth["NAME"], sth["TYPE"], sth["PRECISION"]), \
! sth.fetchall_arrayref()