Skip to content Skip to sidebar Skip to footer

Best Practice For Composite Key In Web2py

The question of composite keys in web2py was answered pretty well by Anthony here, but I'm looking for an answer to a caveat he included in his answer. His answer suggested using p

Solution 1:

Is there a single (or a few) place(s) where I can catch the exception the db layer will throw when I try to INSERT a record (with a duplicate key)?

I don't think so, but you could write a custom function to wrap such inserts in a try...except (or otherwise check for duplicate keys).

Also, if I have two users trying to insert such duplicates, is there an easy way in SQLFORM for me to catch the exception that will get thrown?

When using SQLFORM, the validator should catch the duplicate submission attempt and return an error on the form (for the second user).


Post a Comment for "Best Practice For Composite Key In Web2py"