[Tutor] odbc exception handling

Chris Reay Chris.Reay@pareto-partners.com.au
Fri, 7 May 1999 01:29:10 +0100


Thanks for help from David and geek+.

The advice I received was:

(a) explicitly import dbi
(b) try: except dbi.error:

Unfortunately they don't help; here's the walkback ...

Traceback (innermost last):
  File "<interactive input>", line 0, in ?
  File "FcScripts.py", line 73, in loadWeeklySentimentBrokerForecasts
    sm.add(eachFc)
  File "S:\chrisr\PyPrograms\BrokerForecastMgr.py", line 76, in add
    except dbi.error:
AttributeError: error

Am I mssing something here?

Thanks again

Chris

> -----Original Message-----
> From:	David Ascher [SMTP:da@ski.org]
> Sent:	Thursday, 6 May 1999 13:13
> To:	Chris Reay
> Cc:	'tutor@python.org'
> Subject:	Re: [Tutor] odbc exception handling
> 
> On Thu, 6 May 1999, Chris Reay wrote:
> 
> > dbi.integrity-error: [Microsoft][ODBC Microsoft Access 97 Driver] The
> > changes you requested to the table were not successful because they
> would
> > create duplicate values in the index, primary key, or relationship.
> Change
> > the data in the field or fields that contain duplicate data, remove the
> > index, or redefine the index to permit duplicate entries and try again.
> in
> > EXEC
> 
> 
> > I can't seem to trap the exception. I try (unintended pun)
> > 
> >     def add(self, aSentFc):
> >         tup = aSentFc.asTuple()
> >         sqlStr = self.insertStr % (tup[0], tup[1], tup[2], tup[3])
> >         try:
> >             self.cursor.execute(sqlStr)
> >             self.dbc.commit()
> >         except dbi.integrity-error:
> >             print "Integrity error"
> 
> try (intended pun):
> 
>    except dbi.error:
> 
> 'integrity-error' can't be an exception name, since it's got a - in it --
> it must be the string version of an error.  Looking at the Database topic
> guide, I'm guessing that 'error' will match all DBI errors.
> 
> --david ascher
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor