Fixed #3450 -- Exposed IntegrityError in a backend-neutral fashion. This is a

useful error to be able to catch explicitly. Thanks, enlight.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@5076 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-04-25 10:18:56 +00:00
parent e23ababb52
commit b3e0b59def
10 changed files with 13 additions and 1 deletions

View File

@ -85,6 +85,7 @@ answer newbie questions, and generally made Django that much better:
Jeremy Dunck <http://dunck.us/>
Andy Dustman <farcepest@gmail.com>
Clint Ecker
enlight
Enrico <rico.bl@gmail.com>
Ludvig Ericson <ludvig.ericson@gmail.com>
Dirk Eschler <dirk.eschler@gmx.net>

View File

@ -2,7 +2,7 @@ from django.conf import settings
from django.core import signals
from django.dispatch import dispatcher
__all__ = ('backend', 'connection', 'DatabaseError')
__all__ = ('backend', 'connection', 'DatabaseError', 'IntegrityError')
if not settings.DATABASE_ENGINE:
settings.DATABASE_ENGINE = 'dummy'
@ -29,6 +29,7 @@ runshell = lambda: __import__('django.db.backends.%s.client' % settings.DATABASE
connection = backend.DatabaseWrapper(**settings.DATABASE_OPTIONS)
DatabaseError = backend.DatabaseError
IntegrityError = backend.IntegrityError
# Register an event that closes the database connection
# when a Django request is finished.

View File

@ -17,6 +17,7 @@ except ImportError:
mx = None
DatabaseError = Database.DatabaseError
IntegrityError = Database.IntegrityError
# We need to use a special Cursor class because adodbapi expects question-mark
# param style, but Django expects "%s". This cursor converts question marks to

View File

@ -15,6 +15,9 @@ def complain(*args, **kwargs):
class DatabaseError(Exception):
pass
class IntegrityError(DatabaseError):
pass
class DatabaseWrapper:
cursor = complain
_commit = complain

View File

@ -25,6 +25,7 @@ import types
import re
DatabaseError = Database.DatabaseError
IntegrityError = Database.IntegrityError
# MySQLdb-1.2.1 supports the Python boolean type, and only uses datetime
# module for time-related columns; older versions could have used mx.DateTime

View File

@ -16,6 +16,7 @@ import types
import re
DatabaseError = Database.DatabaseError
IntegrityError = Database.IntegrityError
django_conversions = conversions.copy()
django_conversions.update({

View File

@ -12,6 +12,7 @@ except ImportError, e:
raise ImproperlyConfigured, "Error loading cx_Oracle module: %s" % e
DatabaseError = Database.Error
IntegrityError = Database.IntegrityError
try:
# Only exists in Python 2.4+

View File

@ -12,6 +12,7 @@ except ImportError, e:
raise ImproperlyConfigured, "Error loading psycopg module: %s" % e
DatabaseError = Database.DatabaseError
IntegrityError = Database.IntegrityError
try:
# Only exists in Python 2.4+

View File

@ -12,6 +12,7 @@ except ImportError, e:
raise ImproperlyConfigured, "Error loading psycopg2 module: %s" % e
DatabaseError = Database.DatabaseError
IntegrityError = Database.IntegrityError
try:
# Only exists in Python 2.4+

View File

@ -18,6 +18,7 @@ except ImportError, e:
raise ImproperlyConfigured, "Error loading %s module: %s" % (module, e)
DatabaseError = Database.DatabaseError
IntegrityError = Database.IntegrityError
Database.register_converter("bool", lambda s: str(s) == '1')
Database.register_converter("time", util.typecast_time)