[Zope-DB] Can't get DCOracle2 to work with Python in Zope

Jim Abramson jabramson at wgen.net
Wed Nov 5 09:05:12 EST 2003

Not too long ago I found myself needing to use DCOracle2 features in zope's py scripts,
bypassing the constraints of the standard zope database adapter. There is a very very 
simple way to do it, with external methods:

from Products.DCOracle2 import DCOracle2

def useDco2(dco2conn):
    db = getattr(zdbc,'_v_database_connection')
    cur = getattr(db,'cursor')

    # do whatever you want with the db/cur
    cur.execute('select 999 from dual')
    rs = db.fetchall()
    return rs

when you call this external method, pass a reference to a zope DCOracle2 connection 
object as the dco2conn argument. You will be able to do whatever you like directly with
the dco2 api, while remaining within the zope transaction framework.

note: i'm not sure if the call to register() is needed, but i don't think it hurts.

I actually blew this approach out, into a slightly more complex Product, so I could
add classes/methods facilitating the particular types of operations I needed access
to (while keeping most of the user action in zope py scripts). Despite that I'm no zope
hacker, it really wasn't very difficult to do. With a little help with the good folks
on this list of course.


More information about the Zope-DB mailing list