Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #10566: Added support for cx_Oracle compiled with the WITH_UNIC…

…ODE flag.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit dcf3be7a621f011a918453527406216a738acf68 1 parent e263cc0
Ian Kelly authored August 24, 2009
21  django/db/backends/oracle/base.py
@@ -36,6 +36,14 @@
36 36
 IntegrityError = Database.IntegrityError
37 37
 
38 38
 
  39
+# Check whether cx_Oracle was compiled with the WITH_UNICODE option.  This will
  40
+# also be True in Python 3.0.
  41
+if int(Database.version.split('.', 1)[0]) >= 5 and not hasattr(Database, 'UNICODE'):
  42
+    convert_unicode = force_unicode
  43
+else:
  44
+    convert_unicode = smart_str
  45
+
  46
+
39 47
 class DatabaseFeatures(BaseDatabaseFeatures):
40 48
     empty_fetchmany_value = ()
41 49
     needs_datetime_string_cast = False
@@ -170,10 +178,10 @@ def return_insert_id(self):
170 178
         return "RETURNING %s INTO %%s", (InsertIdVar(),)
171 179
 
172 180
     def savepoint_create_sql(self, sid):
173  
-        return "SAVEPOINT " + self.quote_name(sid)
  181
+        return convert_unicode("SAVEPOINT " + self.quote_name(sid))
174 182
 
175 183
     def savepoint_rollback_sql(self, sid):
176  
-        return "ROLLBACK TO SAVEPOINT " + self.quote_name(sid)
  184
+        return convert_unicode("ROLLBACK TO SAVEPOINT " + self.quote_name(sid))
177 185
 
178 186
     def sql_flush(self, style, tables, sequences):
179 187
         # Return a list of 'TRUNCATE x;', 'TRUNCATE y;',
@@ -304,7 +312,7 @@ def _connect_string(self):
304 312
     def _cursor(self):
305 313
         cursor = None
306 314
         if not self._valid_connection():
307  
-            conn_string = self._connect_string()
  315
+            conn_string = convert_unicode(self._connect_string())
308 316
             self.connection = Database.connect(conn_string, **self.settings_dict['DATABASE_OPTIONS'])
309 317
             cursor = FormatStylePlaceholderCursor(self.connection)
310 318
             # Set oracle date to ansi date format.  This only needs to execute
@@ -355,7 +363,8 @@ def __init__(self, param, cursor, strings_only=False):
355 363
         if hasattr(param, 'bind_parameter'):
356 364
             self.smart_str = param.bind_parameter(cursor)
357 365
         else:
358  
-            self.smart_str = smart_str(param, cursor.charset, strings_only)
  366
+            self.smart_str = convert_unicode(param, cursor.charset,
  367
+                                             strings_only)
359 368
         if hasattr(param, 'input_size'):
360 369
             # If parameter has `input_size` attribute, use that.
361 370
             self.input_size = param.input_size
@@ -423,7 +432,7 @@ def execute(self, query, params=None):
423 432
         # is being passed to SQL*Plus.
424 433
         if query.endswith(';') or query.endswith('/'):
425 434
             query = query[:-1]
426  
-        query = smart_str(query, self.charset) % tuple(args)
  435
+        query = convert_unicode(query % tuple(args), self.charset)
427 436
         self._guess_input_sizes([params])
428 437
         try:
429 438
             return self.cursor.execute(query, self._param_generator(params))
@@ -445,7 +454,7 @@ def executemany(self, query, params=None):
445 454
         # is being passed to SQL*Plus.
446 455
         if query.endswith(';') or query.endswith('/'):
447 456
             query = query[:-1]
448  
-        query = smart_str(query, self.charset) % tuple(args)
  457
+        query = convert_unicode(query % tuple(args), self.charset)
449 458
         formatted = [self._format_params(i) for i in params]
450 459
         self._guess_input_sizes(formatted)
451 460
         try:
4  docs/ref/databases.txt
@@ -476,6 +476,10 @@ version of the driver should **not** be used with Django;
476 476
 ``cx_Oracle`` 5.0.1 resolved this issue, so if you'd like to use a
477 477
 more recent ``cx_Oracle``, use version 5.0.1.
478 478
 
  479
+``cx_Oracle`` 5.0.1 or greater can optionally be compiled with the
  480
+``WITH_UNICODE`` environment variable.  This is recommended but not
  481
+required.
  482
+
479 483
 .. _`Oracle Database Server`: http://www.oracle.com/
480 484
 .. _`cx_Oracle`: http://cx-oracle.sourceforge.net/
481 485
 
7  tests/regressiontests/backends/tests.py
... ...
@@ -1,7 +1,7 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 # Unit and doctests for specific database backends.
3 3
 import unittest
4  
-from django.db import connection
  4
+from django.db import backend, connection
5 5
 from django.db.backends.signals import connection_created
6 6
 from django.conf import settings
7 7
 
@@ -11,9 +11,10 @@ def test_dbms_session(self):
11 11
         # If the backend is Oracle, test that we can call a standard
12 12
         # stored procedure through our cursor wrapper.
13 13
         if settings.DATABASE_ENGINE == 'oracle':
  14
+            convert_unicode = backend.convert_unicode
14 15
             cursor = connection.cursor()
15  
-            cursor.callproc('DBMS_SESSION.SET_IDENTIFIER',
16  
-                            ['_django_testing!',])
  16
+            cursor.callproc(convert_unicode('DBMS_SESSION.SET_IDENTIFIER'),
  17
+                            [convert_unicode('_django_testing!'),])
17 18
             return True
18 19
         else:
19 20
             return True

0 notes on commit dcf3be7

Please sign in to comment.
Something went wrong with that request. Please try again.