mirror of https://github.com/django/django.git
Fixed #7464 -- Fixed the psycopg2 backend to handle SafeString values as
parameters. Based on a patch from Digitalxero@gmail.com. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8532 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
62b39322f3
commit
29d2160213
|
@ -10,8 +10,8 @@ from django.db.backends.postgresql.client import DatabaseClient
|
||||||
from django.db.backends.postgresql.creation import DatabaseCreation
|
from django.db.backends.postgresql.creation import DatabaseCreation
|
||||||
from django.db.backends.postgresql.version import get_version
|
from django.db.backends.postgresql.version import get_version
|
||||||
from django.db.backends.postgresql_psycopg2.introspection import DatabaseIntrospection
|
from django.db.backends.postgresql_psycopg2.introspection import DatabaseIntrospection
|
||||||
|
from django.utils.safestring import SafeUnicode, SafeString
|
||||||
|
|
||||||
from django.utils.safestring import SafeUnicode
|
|
||||||
try:
|
try:
|
||||||
import psycopg2 as Database
|
import psycopg2 as Database
|
||||||
import psycopg2.extensions
|
import psycopg2.extensions
|
||||||
|
@ -23,6 +23,7 @@ DatabaseError = Database.DatabaseError
|
||||||
IntegrityError = Database.IntegrityError
|
IntegrityError = Database.IntegrityError
|
||||||
|
|
||||||
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
|
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
|
||||||
|
psycopg2.extensions.register_adapter(SafeString, psycopg2.extensions.QuotedString)
|
||||||
psycopg2.extensions.register_adapter(SafeUnicode, psycopg2.extensions.QuotedString)
|
psycopg2.extensions.register_adapter(SafeUnicode, psycopg2.extensions.QuotedString)
|
||||||
|
|
||||||
class DatabaseFeatures(BaseDatabaseFeatures):
|
class DatabaseFeatures(BaseDatabaseFeatures):
|
||||||
|
|
|
@ -49,8 +49,10 @@ u'Default headline'
|
||||||
>>> d.seconds < 5
|
>>> d.seconds < 5
|
||||||
True
|
True
|
||||||
|
|
||||||
# make sure that SafeUnicode fields work
|
# make sure that SafeString/SafeUnicode fields work
|
||||||
>>> from django.utils.safestring import SafeUnicode
|
>>> from django.utils.safestring import SafeUnicode, SafeString
|
||||||
>>> a.headline = SafeUnicode(u'SafeUnicode Headline')
|
>>> a.headline = SafeUnicode(u'SafeUnicode Headline')
|
||||||
>>> a.save()
|
>>> a.save()
|
||||||
|
>>> a.headline = SafeString(u'SafeString Headline')
|
||||||
|
>>> a.save()
|
||||||
"""}
|
"""}
|
||||||
|
|
Loading…
Reference in New Issue