Fixed #10566: Added support for cx_Oracle compiled with the WITH_UNICODE flag.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
e263cc0dc5
commit
dcf3be7a62
|
@ -36,6 +36,14 @@ DatabaseError = Database.DatabaseError
|
||||||
IntegrityError = Database.IntegrityError
|
IntegrityError = Database.IntegrityError
|
||||||
|
|
||||||
|
|
||||||
|
# Check whether cx_Oracle was compiled with the WITH_UNICODE option. This will
|
||||||
|
# also be True in Python 3.0.
|
||||||
|
if int(Database.version.split('.', 1)[0]) >= 5 and not hasattr(Database, 'UNICODE'):
|
||||||
|
convert_unicode = force_unicode
|
||||||
|
else:
|
||||||
|
convert_unicode = smart_str
|
||||||
|
|
||||||
|
|
||||||
class DatabaseFeatures(BaseDatabaseFeatures):
|
class DatabaseFeatures(BaseDatabaseFeatures):
|
||||||
empty_fetchmany_value = ()
|
empty_fetchmany_value = ()
|
||||||
needs_datetime_string_cast = False
|
needs_datetime_string_cast = False
|
||||||
|
@ -170,10 +178,10 @@ WHEN (new.%(col_name)s IS NULL)
|
||||||
return "RETURNING %s INTO %%s", (InsertIdVar(),)
|
return "RETURNING %s INTO %%s", (InsertIdVar(),)
|
||||||
|
|
||||||
def savepoint_create_sql(self, sid):
|
def savepoint_create_sql(self, sid):
|
||||||
return "SAVEPOINT " + self.quote_name(sid)
|
return convert_unicode("SAVEPOINT " + self.quote_name(sid))
|
||||||
|
|
||||||
def savepoint_rollback_sql(self, sid):
|
def savepoint_rollback_sql(self, sid):
|
||||||
return "ROLLBACK TO SAVEPOINT " + self.quote_name(sid)
|
return convert_unicode("ROLLBACK TO SAVEPOINT " + self.quote_name(sid))
|
||||||
|
|
||||||
def sql_flush(self, style, tables, sequences):
|
def sql_flush(self, style, tables, sequences):
|
||||||
# Return a list of 'TRUNCATE x;', 'TRUNCATE y;',
|
# Return a list of 'TRUNCATE x;', 'TRUNCATE y;',
|
||||||
|
@ -304,7 +312,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
def _cursor(self):
|
def _cursor(self):
|
||||||
cursor = None
|
cursor = None
|
||||||
if not self._valid_connection():
|
if not self._valid_connection():
|
||||||
conn_string = self._connect_string()
|
conn_string = convert_unicode(self._connect_string())
|
||||||
self.connection = Database.connect(conn_string, **self.settings_dict['DATABASE_OPTIONS'])
|
self.connection = Database.connect(conn_string, **self.settings_dict['DATABASE_OPTIONS'])
|
||||||
cursor = FormatStylePlaceholderCursor(self.connection)
|
cursor = FormatStylePlaceholderCursor(self.connection)
|
||||||
# Set oracle date to ansi date format. This only needs to execute
|
# Set oracle date to ansi date format. This only needs to execute
|
||||||
|
@ -355,7 +363,8 @@ class OracleParam(object):
|
||||||
if hasattr(param, 'bind_parameter'):
|
if hasattr(param, 'bind_parameter'):
|
||||||
self.smart_str = param.bind_parameter(cursor)
|
self.smart_str = param.bind_parameter(cursor)
|
||||||
else:
|
else:
|
||||||
self.smart_str = smart_str(param, cursor.charset, strings_only)
|
self.smart_str = convert_unicode(param, cursor.charset,
|
||||||
|
strings_only)
|
||||||
if hasattr(param, 'input_size'):
|
if hasattr(param, 'input_size'):
|
||||||
# If parameter has `input_size` attribute, use that.
|
# If parameter has `input_size` attribute, use that.
|
||||||
self.input_size = param.input_size
|
self.input_size = param.input_size
|
||||||
|
@ -423,7 +432,7 @@ class FormatStylePlaceholderCursor(object):
|
||||||
# is being passed to SQL*Plus.
|
# is being passed to SQL*Plus.
|
||||||
if query.endswith(';') or query.endswith('/'):
|
if query.endswith(';') or query.endswith('/'):
|
||||||
query = query[:-1]
|
query = query[:-1]
|
||||||
query = smart_str(query, self.charset) % tuple(args)
|
query = convert_unicode(query % tuple(args), self.charset)
|
||||||
self._guess_input_sizes([params])
|
self._guess_input_sizes([params])
|
||||||
try:
|
try:
|
||||||
return self.cursor.execute(query, self._param_generator(params))
|
return self.cursor.execute(query, self._param_generator(params))
|
||||||
|
@ -445,7 +454,7 @@ class FormatStylePlaceholderCursor(object):
|
||||||
# is being passed to SQL*Plus.
|
# is being passed to SQL*Plus.
|
||||||
if query.endswith(';') or query.endswith('/'):
|
if query.endswith(';') or query.endswith('/'):
|
||||||
query = query[:-1]
|
query = query[:-1]
|
||||||
query = smart_str(query, self.charset) % tuple(args)
|
query = convert_unicode(query % tuple(args), self.charset)
|
||||||
formatted = [self._format_params(i) for i in params]
|
formatted = [self._format_params(i) for i in params]
|
||||||
self._guess_input_sizes(formatted)
|
self._guess_input_sizes(formatted)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -476,6 +476,10 @@ version of the driver should **not** be used with Django;
|
||||||
``cx_Oracle`` 5.0.1 resolved this issue, so if you'd like to use a
|
``cx_Oracle`` 5.0.1 resolved this issue, so if you'd like to use a
|
||||||
more recent ``cx_Oracle``, use version 5.0.1.
|
more recent ``cx_Oracle``, use version 5.0.1.
|
||||||
|
|
||||||
|
``cx_Oracle`` 5.0.1 or greater can optionally be compiled with the
|
||||||
|
``WITH_UNICODE`` environment variable. This is recommended but not
|
||||||
|
required.
|
||||||
|
|
||||||
.. _`Oracle Database Server`: http://www.oracle.com/
|
.. _`Oracle Database Server`: http://www.oracle.com/
|
||||||
.. _`cx_Oracle`: http://cx-oracle.sourceforge.net/
|
.. _`cx_Oracle`: http://cx-oracle.sourceforge.net/
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Unit and doctests for specific database backends.
|
# Unit and doctests for specific database backends.
|
||||||
import unittest
|
import unittest
|
||||||
from django.db import connection
|
from django.db import backend, connection
|
||||||
from django.db.backends.signals import connection_created
|
from django.db.backends.signals import connection_created
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
@ -11,9 +11,10 @@ class Callproc(unittest.TestCase):
|
||||||
# If the backend is Oracle, test that we can call a standard
|
# If the backend is Oracle, test that we can call a standard
|
||||||
# stored procedure through our cursor wrapper.
|
# stored procedure through our cursor wrapper.
|
||||||
if settings.DATABASE_ENGINE == 'oracle':
|
if settings.DATABASE_ENGINE == 'oracle':
|
||||||
|
convert_unicode = backend.convert_unicode
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
cursor.callproc('DBMS_SESSION.SET_IDENTIFIER',
|
cursor.callproc(convert_unicode('DBMS_SESSION.SET_IDENTIFIER'),
|
||||||
['_django_testing!',])
|
[convert_unicode('_django_testing!'),])
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in New Issue