[Zope] SQLmethods in a product...

John Earl jwe21@hermes.cam.ac.uk
09 Apr 2000 17:47:24 +0100


"John Sutherland" <JSutherland@tickets.com> writes:
> I'm trying to create a python based product, where in the __init__ for the
> class, I write some data to a SQL DB (in this case MySQL..)... Using the
> code from SQLSession's as an example, I followed his method of making SQL
> statements in a class.. My problem comes in when I try to create an instance
> of the class, it tells me that the database adapter that I chose couldn't be
> found.. I've tried creating the database adapter in the same folder that I'm
> trying to create the instance, and all the folders up to the root one,
> without success... Could this be because I'm trying to access it in the
> __init__ function??

I don't know if I was going about calling things in the same way - I
stole my code from the SQL methods stuff distributed with Zope - but I
had exactly the same trouble. I couldn't get hold of the database
connection because in __init__ it seems like the object isn't yet in
the acquisition tree (or whatever, I'm not too well-versed on the
python jargon). I ended up just hanging onto the ID and keeping a flag
saying I hadn't finished initing yet - and the first time the user
tries to do anything with the object (after it's been instantiated)
getting a reference to the actual connection and doing the necessary
init.

If anyone knows how to get access to acquisition during __init__ I'd
like to hear about it

John
-- 
O5 Whewell's Ct, Trinity Coll., Cambridge CB21TQ (UK); T. 01223 355382