From:
[email protected]
Package: python2.3-pgsql
Version: 2.4.0-5
Installed version of postgresql is 7.4.3-3
pyPgSQL is raising OperationalError rather than IntegrityError for
referential integrity violations.
The pyPgSQL / PosgtreSQL combination in woody (python2.1-pgsql 2.0-3.2
/ postgresql 7.2.1-2woody5) raised IntegrityError as expected.
dbapi 2.0 says:
IntegrityError
Exception raised when the relational integrity of the
database is affected, e.g. a foreign key check fails. It
must be a subclass of DatabaseError.
OperationalError
Exception raised for errors that are related to the
database's operation and not necessarily under the control
of the programmer, e.g. an unexpected disconnect occurs,
the data source name is not found, a transaction could not
be processed, a memory allocation error occurred during
processing, etc. It must be a subclass of DatabaseError.
Test script:
DBNAME = "test"
DBUSER = "test"
from pyPgSQL import PgSQL
dbapi = PgSQL
conn = dbapi.connect(database=DBNAME, user=DBUSER)
curs = conn.cursor()
curs.execute("""
CREATE TABLE main (
id INTEGER,
PRIMARY KEY (id)
);
CREATE TABLE sub (
id INTEGER REFERENCES main,
name VARCHAR(32)
);
""")
curs.execute("INSERT INTO main VALUES (%s)", (1,))
try:
curs.execute("INSERT INTO sub VALUES (%s, %s)", (2, "test"))
except dbapi.IntegrityError:
pass
except Exception, e:
print "Raised wrong exception:\n%r\n%s" % (e, e)
else:
print "Failed to raise exception"
curs.close()
--
To UNSUBSCRIBE, email to
[email protected]
with a subject of "unsubscribe". Trouble? Contact
[email protected]
--- SoupGate-Win32 v1.05
* Origin: you cannot sedate... all the things you hate (1:229/2)