Mark
    That's sweet, and good to learn.
    I am having difficulty even finding what version of SQLObject is 
installed along with TG 1.0.2.2 on my Mac...  interestingly, "tg-admin 
info" doesn't say what version (it says "1.0.2.2" :-).  I may just try 
easy_install update, but not certain that TG will pick up and use the 
new version automagically; haven't yet found docs that indicate how to 
upgrade components like SQLObject for TG.

Paul


W-Mark Kubacki wrote:
> Paul Howell wrote:
>>     The same problem exists for other databases (SQLite, etc).  When I 
>> ran into this problem earlier, I grepped code until I found that 
>> SQLObject (not SQLAlchemy, but probably a similar situation) ONLY 
>> returns an SQLObjectNotFound error... that's just about the only DB 
>> error it traps, if no object is found by the query.  Otherwise it just 
>> passes the native RDBMS error message thru.
>>    Each RDBMS behind these ORMs returns different errors, therefore it 
>> is difficult to trap them all in a try:except pattern... [...]
> 
> With >=SQLObject-0.10.x (or even with 0.9, but I am not quite sure about this)
> this is not longer true. You can write something like this utilizing the new
> exceptions (here DuplicateEntryError):
> 
>     @tg.expose(...)
>     @tg.validate(...)
>     def add(self, contact_id, language, tg_errors=None):
>         if tg_errors:
>             ...
>         try:
>             c = Contact.get(contact_id)
>             l = Language(contact=c, language=language)
>             return dict(success=True,
>                         lang_id=l.id,
>                         ...)
>         except SQLObjectNotFound:
>             return dict(success=False,
>                         error=_("The given contact does not exist anymore."))
>         except DuplicateEntryError:                          # here!
>             return dict(success=False,
>                         error=_("That language has already been added."))
>         except ...
> 
> -- Mark


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to