diff options
| author | Josh Smeaton <josh.smeaton@gmail.com> | 2012-06-12 20:30:52 +1000 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2012-06-26 19:39:14 +0300 |
| commit | fa182e8ae82f33764d5e1f70bcd45899e1bf17e6 (patch) | |
| tree | 7fc3cafe26dd5396dce8fe5ec341115ed9b27c25 /django/db/backends/oracle/base.py | |
| parent | 05d333ba3bb16af024c11966d2072de38fe9f82f (diff) | |
| download | django-fa182e8ae82f33764d5e1f70bcd45899e1bf17e6.tar.gz | |
Fixed #18465 -- Set date formats correctly on Oracle
Correctly configure NLS_SESSION_PARAMETERS to format Date and DateTime
on Oracle backend.
Thanks to Josh Smeaton for report & patch.
Diffstat (limited to 'django/db/backends/oracle/base.py')
| -rw-r--r-- | django/db/backends/oracle/base.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 64e038e1a6..b90f6ea155 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -479,13 +479,19 @@ class DatabaseWrapper(BaseDatabaseWrapper): del conn_params['use_returning_into'] self.connection = Database.connect(conn_string, **conn_params) cursor = FormatStylePlaceholderCursor(self.connection) + # Set the territory first. The territory overrides NLS_DATE_FORMAT + # and NLS_TIMESTAMP_FORMAT to the territory default. When all of + # these are set in single statement it isn't clear what is supposed + # to happen. + cursor.execute("ALTER SESSION SET NLS_TERRITORY = 'AMERICA'") # Set oracle date to ansi date format. This only needs to execute # once when we create a new connection. We also set the Territory - # to 'AMERICA' which forces Sunday to evaluate to a '1' in TO_CHAR(). - cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'" - " NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'" - " NLS_TERRITORY = 'AMERICA'" - + (" TIME_ZONE = 'UTC'" if settings.USE_TZ else '')) + # to 'AMERICA' which forces Sunday to evaluate to a '1' in + # TO_CHAR(). + cursor.execute( + "ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'" + " NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'" + + (" TIME_ZONE = 'UTC'" if settings.USE_TZ else '')) if 'operators' not in self.__dict__: # Ticket #14149: Check whether our LIKE implementation will |
