Hello Massimo!

Thank you for your reply.

To clarify....

SQL Server is properly detecting a duplicate value when it is
entered.  It's Web2py's behavior when this
error is detected that I'm trying to change.

If you look at my original post again, I'm getting the error
"NameError: global name 'IntegrityError' is not defined" when
Web2py hits the exception code in my "try:" block.    In my exception
block I'm explicitly trying to catch
the integrity error by stating:  "except IntegrityError:"

If I simply remove the string 'IntegrityError' from that line of code,
the flash message works.  But.... I don't want to display my custom
error on all detected SQL Server errors... just the "integrity"
related ones.   I want your ticket system to take over flagging other
SQL errors if they occur.

Does that help clarify things a bit more?


I did notice that someone using Django (see:
http://groups.google.com/group/django-users/msg/33b8f9b46ff76f05 ) had
a similar problem in one of their code blocks, and the reply was:

    First, you're getting "global name 'IntegrityError' is not
defined"
    because IntegrityError isn't in the local namespace when you're
    catching it. You'll need to import it -- probably from psycopg:

    Ex:   from psycopg import IntegrityError


Is there a similar import needed by Web2py from PYODBC, to allow
explicit checking for the 'IntegrityError'?


Grazie!

Todd B.






On Jan 29, 2:11 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> According to this:http://code.google.com/p/pyodbc/wiki/Errors
> it should not do so.
>
> Can you provide an example of an error that raises IntegrityError but
> should not?
>
> Massimo
>
> On Jan 29, 10:23 am, NetHead <tbnethe...@yahoo.com> wrote:
>
>
>
> > Greetings everyone!
>
> > This is my first post on this forum.   My appreciation (in advance)
> > for any help any of you can lend me.
>
> > SYNOPSIS:  My app uses Web2py along with MS Sql Server.   I placed a
> > unique constraint on a column in my SQL table, and if a user attempts
> > to enter a duplicate value in this column (and thus firing the SQL
> > UNIQUE constraint error), I want Web2py to gracefully flash a custom
> > error to the user.
>
> > If MS SQL throws any other kind of non integrity-related errors, then
> > I would still like the Web2py ticket system to kick in and provide the
> > more informative message to the user.
>
> > Here's the code I tried:
>
> >     try:
> >         if items_form.accepts(request.vars,session,keepvalues=True) :
> >             response.flash='Record was saved'
> >         elif items_form.errors:
> >             response.flash='Form has errors'
> >     except IntegrityError:
> >             response.flash='Possible Duplicate Item ID - Please try
> > again!'
>
> > Which then generated this error ticket info:
>
> > Traceback (most recent call last):
> >   File "E:\Python\web2py_src\web2py\gluon\restricted.py", line 62, in
> > restricted
> >     exec ccode in environment
> >   File "E:\Python\web2py_src\web2py\applications\BossWalk/controllers/
> > items.py", line 282, in <module>
> >   File "E:\Python\web2py_src\web2py\gluon\globals.py", line 55, in
> > <lambda>
> >     self._caller=lambda f: f()
> >   File "E:\Python\web2py_src\web2py\applications\BossWalk/controllers/
> > items.py", line 269, in items_upsert
> >     except IntegrityError:
> > NameError: global name 'IntegrityError' is not defined
>
> > NOTE: If I take the 'IntegrityError' string out  of the 'Except' line,
> > the process does use 'flash' to show the custom error message when the
> > MS SQL unique constraint is violated.
>
> > But..... I'm surmising that it will also show that *same* message if
> > ANY type of MS SQL exception gets thrown... not just the unique
> > constraint / integrity error.
>
> > To summarize:   I would like to flash the custom error when an SQL
> > integrity error is thrown, and fall back on the ticketing system if MS
> > SQL throws any other kind of error.
>
> > Is this possible?
>
> > Thanks!!!
>
> > Todd B.- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to