[orm-devel] Duplicate Keys (question by Mike Watkins)
Sat, 16 Nov 2002 18:25:17 +0100
This question is from an eMail Mike sent a day or so ago, before I
fexed the mailinglist;
Question for you - where do you tend to test for duplicate keys or
unique columns for inserts and updates? Maybe this is in the new
code (will get around to trying it out this weekend) - but the
insert method for object could benefit from raising errors such as
DuplicateKey or ?
This quetion addresses a problem I have given some tought: handling
RDBMS errors. psycopg and MySQL-Python raise different exceptions
under different circumstances.
In the case Mike describes above, psycopg will raise a
as on any other problem reported by the backend (as opposed to
problems talking to the backend etc). As Mike seems to suggest, orm
would have to catch these exceptions, and raise an appropriate
orm.errors.something exception. This would have one clear advantage:
we'd have the same exceptions no matter what adapter (i.e. RDBMS) is
in use. Also our except blocks could tell the exceptions apart.
The problem I see with it, is, that the only way orm can tell one
psycopg.ProgrammingError from another is postgres's error
message. However, these might be subject to change by the RDBMS'
developers in the future and in the case of PostgreSQL are even
depending on the backend's locale setting.
Up untill now I have decided against introducing this kind of
mechanism. For my programs it dosn't make a difference it I get a
spescific exception or not, the exception's semantic content is the
same: "duplicate key!".
Any suggestion or comment is welcome!
_..._ Diedrich Vorberg
/ _ _ \ http://www.tux4web.de
| (o)_(o) | email@example.com
\( ) / .---.
//'._.'\ \ / \ Internet Dienstleistungen
// . \ \ \.@-@./ und 'Consulting'.
|| . \ \ /`\_/`\
|\ : / | // _ \\ Linux Rules!
\ `) ' (` /_ | \ )|_
_)``".____,.'"` (_ /`\_`> <_/ \
) )'--'( ( \__/'---'\__/