my apologies as this email was caught in the spam filter for a few 
days (along with seven others...).  i dont know turbogears but your 
code looks fine to me, a try/except around the flush() should catch 
any issues within.

On Jan 26, 5:07 pm, "ken.riel" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I have a problem catching a sqlalchemy error in a try and expect.
>
> You see in the model that my user_name must be unique. So if the is a
> user_name like "Ken" and i fill in my form the name "Ken" for user_name
> i will get an error like this:
>
> SQLError: (IntegrityError) column user_name is not unique
>
> So i like to catch the SQLError in the expect.
>
> Model code:
> users_table = Table ('users', metadata,
>     Column('user_id', Integer, primary_key=True),
>     Column('user_name', Unicode(16), unique=True),
>     Column('user_lastname', Unicode(255)),
>     Column('user_zipcode', Unicode(6)),
>     Column('display_name', Unicode(255),),
>     Column('password', Unicode(40)),
>     Column('created', Date, default=date.today)
> )
>
> class Users(object):
>     pass
>
> assign_mapper(session.context, Users, users_table)
>
> Controller code:
> @expose()
> def drop_user(self, user_id=None, name="", last_name="", zipcode="",
> password="", msg=""):
>     try:
>         user = Users()
>         user.user_name = 'Ken'
>
>         session.save(user)
>         session.flush()
>     except Exception, e:
>         turbogears.flash(e)
>     return dict()
>
> It's not working so can anyone tel me what to do.
>
> Greets,
> Ken van Riel


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to