[Zope] catching exceptions thrown by gadfly db
Andy Todd
andy47@halfcooked.com
Sun, 03 Nov 2002 16:22:08 +0000
> Hi all,
>
> I am trying to catch and handle an exception thrown by the gadfly db.
> My code is as follows:
> <dtml-try>
> <dtml-call =
> expr=3D"sql_add_software(p_custName=3DcustName,swName=3DswName)">
> <dtml-except>
> An error occurred.
> Error type: <dtml-var error_type>
> Error value: <dtml-var error_value>
> </dtml-try>
>
> The error is thrown and caught (violation of a unique constraint), but
> it still inserts the row in the DB.
>
> When I try to delete the identical rows, I get the following error:
>
> Error, exceptions.ValueError: list.remove(x): x not in list
>
> Any ideas?
>
> TIA,
>
> Miche=E1l Healy
Michael,
You have stumbled across a little feature in Gadfly. In essence,
although an exception is raised the data still gets written to the
database. What you need to do is capture the exception
gadfly.store.StorageError and when it occurs issue a rollback. e.g. in
Python;
>>> db = gadfly.gadfly('myDb', 'myDbDir')
>>> cursor = db.cursor()
>>> try:
... cursor.execute("INSERT INTO table (col1, col2, col3) values (?,
?, ?)", val1, val2, val3)
... except gadfly.store.StorageError:
... db.rollback()
I'm a bit new to Zope so hopefully some kind soul will help translate
this to the appropriate DTML or other appropriate form. This has been
logged as a bug with gadfly (see
http://sourceforge.net/tracker/?func=detail&atid=100662&aid=632247&group_id=662
for details).
Regards,
Andy
--
----------------------------------------------------------------------
From the desk of Andrew J Todd esq - http://www.halfcooked.com