Kaydet (Commit) b3e0b59d authored tarafından Malcolm Tredinnick's avatar Malcolm Tredinnick

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
üst e23ababb
......@@ -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>
......
......@@ -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.
......
......@@ -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
......
......@@ -15,6 +15,9 @@ def complain(*args, **kwargs):
class DatabaseError(Exception):
pass
class IntegrityError(DatabaseError):
pass
class DatabaseWrapper:
cursor = complain
_commit = complain
......
......@@ -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
......
......@@ -16,6 +16,7 @@ import types
import re
DatabaseError = Database.DatabaseError
IntegrityError = Database.IntegrityError
django_conversions = conversions.copy()
django_conversions.update({
......
......@@ -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+
......
......@@ -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+
......
......@@ -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+
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment