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:
parent
e23ababb52
commit
b3e0b59def
1
AUTHORS
1
AUTHORS
|
@ -85,6 +85,7 @@ answer newbie questions, and generally made Django that much better:
|
||||||
Jeremy Dunck <http://dunck.us/>
|
Jeremy Dunck <http://dunck.us/>
|
||||||
Andy Dustman <farcepest@gmail.com>
|
Andy Dustman <farcepest@gmail.com>
|
||||||
Clint Ecker
|
Clint Ecker
|
||||||
|
enlight
|
||||||
Enrico <rico.bl@gmail.com>
|
Enrico <rico.bl@gmail.com>
|
||||||
Ludvig Ericson <ludvig.ericson@gmail.com>
|
Ludvig Ericson <ludvig.ericson@gmail.com>
|
||||||
Dirk Eschler <dirk.eschler@gmx.net>
|
Dirk Eschler <dirk.eschler@gmx.net>
|
||||||
|
|
|
@ -2,7 +2,7 @@ from django.conf import settings
|
||||||
from django.core import signals
|
from django.core import signals
|
||||||
from django.dispatch import dispatcher
|
from django.dispatch import dispatcher
|
||||||
|
|
||||||
__all__ = ('backend', 'connection', 'DatabaseError')
|
__all__ = ('backend', 'connection', 'DatabaseError', 'IntegrityError')
|
||||||
|
|
||||||
if not settings.DATABASE_ENGINE:
|
if not settings.DATABASE_ENGINE:
|
||||||
settings.DATABASE_ENGINE = 'dummy'
|
settings.DATABASE_ENGINE = 'dummy'
|
||||||
|
@ -29,6 +29,7 @@ runshell = lambda: __import__('django.db.backends.%s.client' % settings.DATABASE
|
||||||
|
|
||||||
connection = backend.DatabaseWrapper(**settings.DATABASE_OPTIONS)
|
connection = backend.DatabaseWrapper(**settings.DATABASE_OPTIONS)
|
||||||
DatabaseError = backend.DatabaseError
|
DatabaseError = backend.DatabaseError
|
||||||
|
IntegrityError = backend.IntegrityError
|
||||||
|
|
||||||
# Register an event that closes the database connection
|
# Register an event that closes the database connection
|
||||||
# when a Django request is finished.
|
# when a Django request is finished.
|
||||||
|
|
|
@ -17,6 +17,7 @@ except ImportError:
|
||||||
mx = None
|
mx = None
|
||||||
|
|
||||||
DatabaseError = Database.DatabaseError
|
DatabaseError = Database.DatabaseError
|
||||||
|
IntegrityError = Database.IntegrityError
|
||||||
|
|
||||||
# We need to use a special Cursor class because adodbapi expects question-mark
|
# 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
|
# param style, but Django expects "%s". This cursor converts question marks to
|
||||||
|
|
|
@ -15,6 +15,9 @@ def complain(*args, **kwargs):
|
||||||
class DatabaseError(Exception):
|
class DatabaseError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class IntegrityError(DatabaseError):
|
||||||
|
pass
|
||||||
|
|
||||||
class DatabaseWrapper:
|
class DatabaseWrapper:
|
||||||
cursor = complain
|
cursor = complain
|
||||||
_commit = complain
|
_commit = complain
|
||||||
|
|
|
@ -25,6 +25,7 @@ import types
|
||||||
import re
|
import re
|
||||||
|
|
||||||
DatabaseError = Database.DatabaseError
|
DatabaseError = Database.DatabaseError
|
||||||
|
IntegrityError = Database.IntegrityError
|
||||||
|
|
||||||
# MySQLdb-1.2.1 supports the Python boolean type, and only uses datetime
|
# 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
|
# module for time-related columns; older versions could have used mx.DateTime
|
||||||
|
|
|
@ -16,6 +16,7 @@ import types
|
||||||
import re
|
import re
|
||||||
|
|
||||||
DatabaseError = Database.DatabaseError
|
DatabaseError = Database.DatabaseError
|
||||||
|
IntegrityError = Database.IntegrityError
|
||||||
|
|
||||||
django_conversions = conversions.copy()
|
django_conversions = conversions.copy()
|
||||||
django_conversions.update({
|
django_conversions.update({
|
||||||
|
|
|
@ -12,6 +12,7 @@ except ImportError, e:
|
||||||
raise ImproperlyConfigured, "Error loading cx_Oracle module: %s" % e
|
raise ImproperlyConfigured, "Error loading cx_Oracle module: %s" % e
|
||||||
|
|
||||||
DatabaseError = Database.Error
|
DatabaseError = Database.Error
|
||||||
|
IntegrityError = Database.IntegrityError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Only exists in Python 2.4+
|
# Only exists in Python 2.4+
|
||||||
|
|
|
@ -12,6 +12,7 @@ except ImportError, e:
|
||||||
raise ImproperlyConfigured, "Error loading psycopg module: %s" % e
|
raise ImproperlyConfigured, "Error loading psycopg module: %s" % e
|
||||||
|
|
||||||
DatabaseError = Database.DatabaseError
|
DatabaseError = Database.DatabaseError
|
||||||
|
IntegrityError = Database.IntegrityError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Only exists in Python 2.4+
|
# Only exists in Python 2.4+
|
||||||
|
|
|
@ -12,6 +12,7 @@ except ImportError, e:
|
||||||
raise ImproperlyConfigured, "Error loading psycopg2 module: %s" % e
|
raise ImproperlyConfigured, "Error loading psycopg2 module: %s" % e
|
||||||
|
|
||||||
DatabaseError = Database.DatabaseError
|
DatabaseError = Database.DatabaseError
|
||||||
|
IntegrityError = Database.IntegrityError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Only exists in Python 2.4+
|
# Only exists in Python 2.4+
|
||||||
|
|
|
@ -18,6 +18,7 @@ except ImportError, e:
|
||||||
raise ImproperlyConfigured, "Error loading %s module: %s" % (module, e)
|
raise ImproperlyConfigured, "Error loading %s module: %s" % (module, e)
|
||||||
|
|
||||||
DatabaseError = Database.DatabaseError
|
DatabaseError = Database.DatabaseError
|
||||||
|
IntegrityError = Database.IntegrityError
|
||||||
|
|
||||||
Database.register_converter("bool", lambda s: str(s) == '1')
|
Database.register_converter("bool", lambda s: str(s) == '1')
|
||||||
Database.register_converter("time", util.typecast_time)
|
Database.register_converter("time", util.typecast_time)
|
||||||
|
|
Loading…
Reference in New Issue