mirror of
https://github.com/django/django.git
synced 2025-09-07 11:10:43 +00:00
Fixed #12702 -- Introduced a common implementation of DatabaseError and IntegrityError, so that database backends can (re)raise common error classes. Thanks for Waldemar Kornewald for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12352 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
47acb1d659
commit
11ee9746a0
7 changed files with 113 additions and 22 deletions
|
@ -4,6 +4,9 @@ PostgreSQL database backend for Django.
|
|||
Requires psycopg 1: http://initd.org/projects/psycopg1
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
from django.db import utils
|
||||
from django.db.backends import *
|
||||
from django.db.backends.signals import connection_created
|
||||
from django.db.backends.postgresql.client import DatabaseClient
|
||||
|
@ -50,11 +53,21 @@ class UnicodeCursorWrapper(object):
|
|||
return tuple([smart_str(p, self.charset, True) for p in params])
|
||||
|
||||
def execute(self, sql, params=()):
|
||||
return self.cursor.execute(smart_str(sql, self.charset), self.format_params(params))
|
||||
try:
|
||||
return self.cursor.execute(query, args)
|
||||
except Database.IntegrityError, e:
|
||||
raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
|
||||
except Database.DatabaseError, e:
|
||||
raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
|
||||
|
||||
def executemany(self, sql, param_list):
|
||||
new_param_list = [self.format_params(params) for params in param_list]
|
||||
return self.cursor.executemany(sql, new_param_list)
|
||||
try:
|
||||
new_param_list = [self.format_params(params) for params in param_list]
|
||||
return self.cursor.executemany(sql, new_param_list)
|
||||
except Database.IntegrityError, e:
|
||||
raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
|
||||
except Database.DatabaseError, e:
|
||||
raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
|
||||
|
||||
def __getattr__(self, attr):
|
||||
if attr in self.__dict__:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue