Using Zope DB connection from a Python class
Greetings, For the past few days, I've been unsuccessfully trying to use a Zope ODBC connection from within a Python class. I have the following situation: 1. A Python class, Order, which has this method: def create (self, cust_id, connection_id = None, itemcode = None, quantity = 0): while self is not None: if hasattr(self, 'objectValues'): for o in self.objectValues(): if hasattr(o, 'id'): if o.id == connection_id: self.connection = o self.cust_id = cust_id self.itemcode = itemcode self.quantity = quantity query = 'insert into orders (cust_id, itemcode, quantity) values (%s, \'%s\', %s)' % (self.cust_id, self.itemcode, self.quantity) if self.connection != None: self.connection._begin() result = self.connection.query (query) print result self.connection._finish() 2. A Zope class, TestOrder, which subclasses Order. Its constructor tries to invokes 'create', however upon executing the SQL query, Zope either dies and is restarted, or just sits there, doing nothing, until the HTTP connection times out. In either case, the new record is not written in the database. 3. Zope 2.1.7 Z ODBC DA 3.0.3 Solid dev kit 2.3 RedHat Linux 6.1 on i386 Please help. Thanks, Ivan Raikov
+----[ Tino Wildenhain ]--------------------------------------------- | Hi Ivan, | | > 3. Zope 2.1.7 | > Z ODBC DA 3.0.3 | > Solid dev kit 2.3 | > RedHat Linux 6.1 on i386 | | How to use Z ODBC DA on Linux? I only found a windows binary. You need to do a few things: First the ZODBCDA comes with src for the python ODBC wrapper. You can alter this src to use your ODBC library rebuild it and move the .so file up a directory. For UNIX ODBC libraries you have some choices:- OpenSource ---------- iODBC -- works OK unixODBC -- I had problems with this, but, it's not a very mature product, I didn't really stick with it at the time either (time constraints). Commercial ---------- Openlink Multi-Tier ODBC libraries -- Commercial, but, they have a 10 connection demo license. This works well, and I have succesfully used this to talk to MS-SQL v7 from FreeBSD. Then there's the ODBC-ODBC bridge software I haven't really tried to get this to work, although I briefly looked at it. -- Totally Holistic Enterprises Internet| P:+61 7 3870 0066 | Andrew Milton The Internet (Aust) Pty Ltd | F:+61 7 3870 4477 | ACN: 082 081 472 | M:+61 416 022 411 | Carpe Daemon PO Box 837 Indooroopilly QLD 4068 |akm@theinternet.com.au|
Hi, is there anybody who did alter the ZOBCDA to work under Linux using one of the free open source adapters? I would like to share (get ;-) the code. Tnanks! Andrew Kenneth Milton wrote:
+----[ Tino Wildenhain ]--------------------------------------------- | Hi Ivan, | | > 3. Zope 2.1.7 | > Z ODBC DA 3.0.3 | > Solid dev kit 2.3 | > RedHat Linux 6.1 on i386 | | How to use Z ODBC DA on Linux? I only found a windows binary.
You need to do a few things:
First the ZODBCDA comes with src for the python ODBC wrapper. You can alter this src to use your ODBC library rebuild it and move the .so file up a directory.
For UNIX ODBC libraries you have some choices:-
OpenSource ---------- iODBC -- works OK unixODBC -- I had problems with this, but, it's not a very mature product, I didn't really stick with it at the time either (time constraints).
-- connection reset by Peer _______________________________________________________________________ Dr. Peer Griebel Tel. +49 7581 4831 23 Geschäftsführer Fax. +49 7581 4831 11 Knoll Informationssysteme GmbH http://www.knoll-is.de Dreiköniggasse 17 mailto:peer@knoll-is.de 88348 Saulgau privat: mailto:peer.griebel@gmx.de
I was also trying to accomplish this a while back. I managed to add the new class with a database connection and execute sql statements. My class had some stuff like this: def __init__(self,id,title,dbconn): self.id=id self.title=title self.dbconn=dbconn self.times={} def getProducts(self): stmt = 'select prdt_id as id, product as name from products' dummy, components = self.exec_sql(stmt) return components def exec_sql(self, stmt): "Execute a piece of SQL code -- Need to convert to some sort of ZSQL Method" db = getattr(self, self.dbconn) col_names, raw_results = db().query(stmt) col_names = map(lambda x: x['name'],col_names) return col_names, raw_results Now it worked... but here's my problem/question... These methods, while executing SQL, are not ZSQL Methods, which means I'm not getting any of the good caching and other bollocks. I was categorically unsuccessful adding ZSQL Methods to the class. Does anyone have any tips to how I could turn exec_sql into a ZSQL Method? Monty Ivan Raikov wrote:
Greetings,
For the past few days, I've been unsuccessfully trying to use a Zope ODBC connection from within a Python class.
I have the following situation:
1. A Python class, Order, which has this method:
def create (self, cust_id, connection_id = None, itemcode = None, quantity = 0):
while self is not None: if hasattr(self, 'objectValues'): for o in self.objectValues(): if hasattr(o, 'id'): if o.id == connection_id: self.connection = o
self.cust_id = cust_id self.itemcode = itemcode self.quantity = quantity query = 'insert into orders (cust_id, itemcode, quantity) values (%s, \'%s\', %s)' % (self.cust_id, self.itemcode, self.quantity)
if self.connection != None: self.connection._begin() result = self.connection.query (query) print result self.connection._finish()
2. A Zope class, TestOrder, which subclasses Order. Its constructor tries to invokes 'create', however upon executing the SQL query, Zope either dies and is restarted, or just sits there, doing nothing, until the HTTP connection times out. In either case, the new record is not written in the database.
3. Zope 2.1.7 Z ODBC DA 3.0.3 Solid dev kit 2.3 RedHat Linux 6.1 on i386
Please help.
Thanks, Ivan Raikov
_______________________________________________ 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 (5)
-
Andrew Kenneth Milton -
Dr. Peer Griebel -
Ivan Raikov -
Monty Taylor -
Tino Wildenhain