[Tutor] odbc exception handling
David Ascher
da@ski.org
Wed, 5 May 1999 20:13:26 -0700 (Pacific Daylight Time)
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