Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Rearranged an Oracle ALTER statement so it is run only once per new c…

…onnection, not on every cursor creation. Thanks, Ian Kelly.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6963 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 72d279a29fdbbbab905072336c4d54a64b25195d 1 parent d1b5a0b
Matt Boersma authored December 20, 2007

Showing 1 changed file with 8 additions and 4 deletions. Show diff stats Hide diff stats

  1. 12  django/db/backends/oracle/base.py
12  django/db/backends/oracle/base.py
@@ -413,6 +413,7 @@ def _valid_connection(self):
413 413
         return self.connection is not None
414 414
 
415 415
     def _cursor(self, settings):
  416
+        cursor = None
416 417
         if not self._valid_connection():
417 418
             if len(settings.DATABASE_HOST.strip()) == 0:
418 419
                 settings.DATABASE_HOST = 'localhost'
@@ -422,16 +423,19 @@ def _cursor(self, settings):
422 423
             else:
423 424
                 conn_string = "%s/%s@%s" % (settings.DATABASE_USER, settings.DATABASE_PASSWORD, settings.DATABASE_NAME)
424 425
                 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'")
425 431
             try:
426 432
                 self.oracle_version = int(self.connection.version.split('.')[0])
427 433
             except ValueError:
428 434
                 pass
429  
-        cursor = FormatStylePlaceholderCursor(self.connection)
  435
+        if not cursor:
  436
+            cursor = FormatStylePlaceholderCursor(self.connection)
430 437
         # Default arraysize of 1 is highly sub-optimal.
431 438
         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'")
435 439
         return cursor
436 440
 
437 441
 class FormatStylePlaceholderCursor(Database.Cursor):

0 notes on commit 72d279a

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