Python+Apache+Oracle+???Persistent database connection???

Philip Payne pnpayne at swissonline.ch
Mon Aug 23 06:58:00 EDT 1999


In case anyone is interested, the following solution was sent to me by
e-mail by Andrew Csillag:

Actually, there sorta is.  With PyApache 4.14 and up, there is something
that gets put into the builtin namespace, it's called __persistdict__,
which is a persistant dictionary in that it doesn't get wiped between
requests.  A point to note tho is that you really can only put in C
objects, cause python objects won't work (mostly because the module the
object came from was since destroyed).  I've done this with excellent
results with oracledb, with DCOracle it gets a bit trickier.  You wind
up having to do something like this (caveat programmer: I haven't
actually tried it, but I've worked with other objects that worked
similarly) to use the connection:

   to save the connection:
      #you might be able to get away without using __dict__ and perhaps
could
      #just use conn._d, but there's a setattr hook and I didn't really 
      #look at it to see what it did, so the below should work for sure
      __persistdict__['my_oracle_connection'] = conn.__dict__['_d']

   to use the saved connection:
      import DCOracle.ocidb
      class dummy: pass
      conn = dummy()
      conn._d = __persistdict__['my_oracle_connection'] 
      conn.__class__ = DCOracle.ocidb.ocidb

It it a bit ugly?  Yup, but it should work more or less.  While oracledb
isn't quite as nice in general, you can just stick it into the dict
(although, there is some mucking around with the dbi module to make IT
work).




More information about the Python-list mailing list