Django

Code

Changeset 6963

Show
Ignore:
Timestamp:
12/20/07 17:06:30 (9 months ago)
Author:
mboersma
Message:

Rearranged an Oracle ALTER statement so it is run only once per new connection, not on every cursor creation. Thanks, Ian Kelly.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/backends/oracle/base.py

    r6905 r6963  
    414414 
    415415    def _cursor(self, settings): 
     416        cursor = None 
    416417        if not self._valid_connection(): 
    417418            if len(settings.DATABASE_HOST.strip()) == 0: 
     
    423424                conn_string = "%s/%s@%s" % (settings.DATABASE_USER, settings.DATABASE_PASSWORD, settings.DATABASE_NAME) 
    424425                self.connection = Database.connect(conn_string, **self.options) 
     426            cursor = FormatStylePlaceholderCursor(self.connection) 
     427            # Set oracle date to ansi date format.  This only needs to execute 
     428            # once when we create a new connection. 
     429            cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD' " 
     430                           "NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'") 
    425431            try: 
    426432                self.oracle_version = int(self.connection.version.split('.')[0]) 
    427433            except ValueError: 
    428434                pass 
    429         cursor = FormatStylePlaceholderCursor(self.connection) 
     435        if not cursor: 
     436            cursor = FormatStylePlaceholderCursor(self.connection) 
    430437        # Default arraysize of 1 is highly sub-optimal. 
    431438        cursor.arraysize = 100 
    432         # Set oracle date to ansi date format. 
    433         cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD'") 
    434         cursor.execute("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'") 
    435439        return cursor 
    436440