Ticket #10566: 10566-2.diff

File 10566-2.diff, 4.3 KB (added by Erin Kelly, 16 years ago)

This revised patch avoids a bug where calling setinputsizes with an NCLOB argument results in an error under cx_Oracle 5.0.1 with unicode.

  • django/db/backends/oracle/base.py

     
    3535IntegrityError = Database.IntegrityError
    3636
    3737
     38# Check whether cx_Oracle was compiled with the WITH_UNICODE option.  This will
     39# also be True in Python 3.0.
     40if int(Database.version.split('.', 1)[0]) >= 5 and not hasattr(Database, 'UNICODE'):
     41    convert_unicode = force_unicode
     42else:
     43    convert_unicode = smart_str
     44
     45
    3846class DatabaseFeatures(BaseDatabaseFeatures):
    3947    empty_fetchmany_value = ()
    4048    needs_datetime_string_cast = False
     
    169177        return "RETURNING %s INTO %%s", (InsertIdVar(),)
    170178
    171179    def savepoint_create_sql(self, sid):
    172         return "SAVEPOINT " + self.quote_name(sid)
     180        return convert_unicode("SAVEPOINT " + self.quote_name(sid))
    173181
    174182    def savepoint_rollback_sql(self, sid):
    175         return "ROLLBACK TO SAVEPOINT " + self.quote_name(sid)
     183        return convert_unicode("ROLLBACK TO SAVEPOINT " + self.quote_name(sid))
    176184
    177185    def sql_flush(self, style, tables, sequences):
    178186        # Return a list of 'TRUNCATE x;', 'TRUNCATE y;',
     
    302310    def _cursor(self):
    303311        cursor = None
    304312        if not self._valid_connection():
    305             conn_string = self._connect_string()
     313            conn_string = convert_unicode(self._connect_string())
    306314            self.connection = Database.connect(conn_string, **self.settings_dict['DATABASE_OPTIONS'])
    307315            cursor = FormatStylePlaceholderCursor(self.connection)
    308316            # Set oracle date to ansi date format.  This only needs to execute
     
    352360        if hasattr(param, 'bind_parameter'):
    353361            self.smart_str = param.bind_parameter(cursor)
    354362        else:
    355             self.smart_str = smart_str(param, cursor.charset, strings_only)
     363            self.smart_str = convert_unicode(param, cursor.charset,
     364                                             strings_only)
    356365        if hasattr(param, 'input_size'):
    357366            # If parameter has `input_size` attribute, use that.
    358367            self.input_size = param.input_size
    359368        elif isinstance(param, basestring) and len(param) > 4000:
    360             # Mark any string param greater than 4000 characters as an NCLOB.
    361             self.input_size = Database.NCLOB
     369            # Mark any string param greater than 4000 characters as a CLOB.
     370            self.input_size = Database.CLOB
    362371        else:
    363372            self.input_size = None
    364373
     
    420429        # is being passed to SQL*Plus.
    421430        if query.endswith(';') or query.endswith('/'):
    422431            query = query[:-1]
    423         query = smart_str(query, self.charset) % tuple(args)
     432        query = convert_unicode(query % tuple(args), self.charset)
    424433        self._guess_input_sizes([params])
    425434        try:
    426435            return self.cursor.execute(query, self._param_generator(params))
     
    442451        # is being passed to SQL*Plus.
    443452        if query.endswith(';') or query.endswith('/'):
    444453            query = query[:-1]
    445         query = smart_str(query, self.charset) % tuple(args)
     454        query = convert_unicode(query % tuple(args), self.charset)
    446455        formatted = [self._format_params(i) for i in params]
    447456        self._guess_input_sizes(formatted)
    448457        try:
  • tests/regressiontests/backends/tests.py

     
    44
    55import unittest
    66
    7 from django.db import connection
     7from django.db import backend, connection
    88from django.conf import settings
    99
    1010
     
    1414        # If the backend is Oracle, test that we can call a standard
    1515        # stored procedure through our cursor wrapper.
    1616        if settings.DATABASE_ENGINE == 'oracle':
     17            convert_unicode = backend.convert_unicode
    1718            cursor = connection.cursor()
    18             cursor.callproc('DBMS_SESSION.SET_IDENTIFIER',
    19                             ['_django_testing!',])
     19            cursor.callproc(convert_unicode('DBMS_SESSION.SET_IDENTIFIER'),
     20                            [convert_unicode('_django_testing!'),])
    2021            return True
    2122        else:
    2223            return True
Back to Top