Re: [Zope] SQLmethods in a product...
"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
John Earl wrote:
"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.
Argh.. I'd rather avoid having to do something like that (attempting to keep things as effiecent as possible, speed and memory/drive space..).. But if I have to, I will.. Any other ideas???
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
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (2)
-
Garion -
John Earl