[DB-SIG] General DB Error Handling

Robert Theiss rtheiss@yahoo.com
Mon, 22 Jul 2002 11:38:08 -0700 (PDT)


Andy,
Thanks for the prompt reply.  With your suggestions,
and a few others, I finally got what I was looking
for.  My code now looks like this:

# Connect to DB
try:
  db = informixdb.informixdb(dbInstance, dbUser,
dbPasswd)
except db.error:
  exc_type, exc_value = sys.exc_info()[:2]
  ExceptionHandler(exc_type, exc_value, DataFile,
LogFile, db)

The ExceptionHandler is a homegrown routine I wrote to
handle exceptions, logging and to determine
criticality of the error so either a warning email or
a page will be generated.

Bob  
  
--- Andy Dustman <andy@dustman.net> wrote:
> On Wed, 2002-06-26 at 11:37, Robert Theiss wrote:
> 
> > What I would like to do is trap any error returned
> > from the database, so I can exit the program
> > gracefully.  A sample output is  shown below, when
> I
> > intentionally generate an SQL error.  
> 
> Problem #1: Your module is compiled against the
> wrong version of Python.
> It looks like it's compiled for 1.5.2 but you are
> using a 2.x version.
>  
> > InformixdbError: Error -522 performing PREPARE:
> Table
> > (part) not selected in query.
> > [bobt@monza:/service/bobt] > 
> > 
> > The python code that generated this output is
> shown
> > below:
> ... 
> > try:
> >   returncode =
> apply(db.execute(SqlSelectStatement),
> > args)
> > except:
> >   print "return code is %s : " %  args
> 
> You want:
> 
> c = db.cursor()
> try:
>     c.execute(SqlSelectStatement, args) # return
> value undefined
>     rows = c.fetchall()
> except InformixdbError, e:
>     print "return code is %s : " % e
> 
> -- 
> Andy Dustman         PGP: 0x930B8AB6
>     @       .net     http://dustman.net/andy
> "Cogito, ergo sum." -- Rene Descartes
> "I yam what I yam and that's all what I yam." --
> Popeye
> 
> 
> _______________________________________________
> DB-SIG maillist  -  DB-SIG@python.org
> http://mail.python.org/mailman/listinfo/db-sig


__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com