This doesn't appear to be documented, and I'm not sure it's intended to be
part of the public API, but you can do:
try:
db.mytable.insert(...)
except db._adapter.integrity_error():
[do something]
There is also db._adapter.operational_error(). Not sure these work with all
adapters.
More generally, I suppose you could do:
try:
db.mytable.insert(...)
except Exception as e:
if type(e).__name__ == 'IntegrityError':
[do something]
else:
raise e
Perhaps there is a better way.
Anthony
On Saturday, June 19, 2010 2:25:11 AM UTC-4, Narendran wrote:
>
> Hello,
> I am using MySQL as my backend store. I have declared a field like
> this in one of my tables:
> Field("OFFER_TITLE", "string", length=255, notnull=True, default=None,
> unique=True)
>
> Now, I have written a cron job which will do DB insertions using DAL.
> The problem now is that when I insert a row that violates the unique
> constraint of OFFER_TITLE, it returns
> _mysql_exceptions.IntegrityError, which is a DB specific error. I was
> expecting DAL to wrap such low-level DB exceptions for me. The idea is
> that I want to handle integrity exceptions in my code. Now I don't
> want to write mySQL specific code in my cron module.
> Can someone please let me know anyone faced a similar situation, and
> got a solution for this?
>
> --
> Thanks
> Narendran
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.