Rearranged an Oracle ALTER statement so it is run only once per new connection, not on every cursor creation. Thanks, Ian Kelly.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6963 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
d1b5a0bde5
commit
72d279a29f
|
@ -413,6 +413,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
return self.connection is not None
|
return self.connection is not None
|
||||||
|
|
||||||
def _cursor(self, settings):
|
def _cursor(self, settings):
|
||||||
|
cursor = None
|
||||||
if not self._valid_connection():
|
if not self._valid_connection():
|
||||||
if len(settings.DATABASE_HOST.strip()) == 0:
|
if len(settings.DATABASE_HOST.strip()) == 0:
|
||||||
settings.DATABASE_HOST = 'localhost'
|
settings.DATABASE_HOST = 'localhost'
|
||||||
|
@ -422,16 +423,19 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
else:
|
else:
|
||||||
conn_string = "%s/%s@%s" % (settings.DATABASE_USER, settings.DATABASE_PASSWORD, settings.DATABASE_NAME)
|
conn_string = "%s/%s@%s" % (settings.DATABASE_USER, settings.DATABASE_PASSWORD, settings.DATABASE_NAME)
|
||||||
self.connection = Database.connect(conn_string, **self.options)
|
self.connection = Database.connect(conn_string, **self.options)
|
||||||
|
cursor = FormatStylePlaceholderCursor(self.connection)
|
||||||
|
# Set oracle date to ansi date format. This only needs to execute
|
||||||
|
# once when we create a new connection.
|
||||||
|
cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD' "
|
||||||
|
"NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'")
|
||||||
try:
|
try:
|
||||||
self.oracle_version = int(self.connection.version.split('.')[0])
|
self.oracle_version = int(self.connection.version.split('.')[0])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
if not cursor:
|
||||||
cursor = FormatStylePlaceholderCursor(self.connection)
|
cursor = FormatStylePlaceholderCursor(self.connection)
|
||||||
# Default arraysize of 1 is highly sub-optimal.
|
# Default arraysize of 1 is highly sub-optimal.
|
||||||
cursor.arraysize = 100
|
cursor.arraysize = 100
|
||||||
# Set oracle date to ansi date format.
|
|
||||||
cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD'")
|
|
||||||
cursor.execute("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'")
|
|
||||||
return cursor
|
return cursor
|
||||||
|
|
||||||
class FormatStylePlaceholderCursor(Database.Cursor):
|
class FormatStylePlaceholderCursor(Database.Cursor):
|
||||||
|
|
Loading…
Reference in New Issue