Well. Is it possible to just catch the MySQLdb.DuplicateKeyError (maybe misspelled) exception in the code by importing MysqlDB package. I know for sure that I'll stick to mysql so I don't care for the code to be generic for all possible dbs?
Thanks. On Jun 19, 9:42 pm, Todd Martin <[EMAIL PROTECTED]> wrote: > I've been struggling with duplicate key exception handling myself. > I'm able to catch the SQLAlchemy exception with an exception handler, > but I'd rather just handle this inside my function. > > @exception_handler(someFunctionName) > > I've only tested the following code for a few minutes, but it seems to > work and I avoid the exception handler. It's similar in theory to > Paul's method. The sample code is for a RSS reader that only adds a > new feed if it doesn't already exist. unique=True is set for the link > column in the mysql database. > > f = Feed.get_by(link=link) > if not f: > # create the feed entry if it is new > f = Feed(name=name, link=link, description=description) > f.users.append(identity.current.user) > else: > # the feed exists so test for a new user > new_user = 1 > for usr in f.users: > if ( usr == identity.current.user ) : > # Don't need to add user to the feed > new_user = 0 > break > > if ( new_user == 1 ) : > f.users.append(identity.current.user) > > Regards, > > Todd --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~---

