summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Kelly <ian.g.kelly@gmail.com>2010-12-03 00:58:56 +0000
committerIan Kelly <ian.g.kelly@gmail.com>2010-12-03 00:58:56 +0000
commit57e5ccbc1ad6cdbb52c738e74db242539e6f3a56 (patch)
tree6f61661d385d10d8d86d69383fa7b9e119462945
parentf8d014504f9ff003fe3ec28ccc9dcb129974ff09 (diff)
[1.2.X] Fixed the Oracle environment variables not getting set correctly under Cygwin.
Backport of r14781 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14782 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/db/backends/oracle/base.py31
1 files changed, 25 insertions, 6 deletions
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index 5ccaded474..d6c679a284 100644
--- a/django/db/backends/oracle/base.py
+++ b/django/db/backends/oracle/base.py
@@ -6,16 +6,35 @@ Requires cx_Oracle: http://cx-oracle.sourceforge.net/
import datetime
-import os
import sys
import time
from decimal import Decimal
-# Oracle takes client-side character set encoding from the environment.
-os.environ['NLS_LANG'] = '.UTF8'
-# This prevents unicode from getting mangled by getting encoded into the
-# potentially non-unicode database character set.
-os.environ['ORA_NCHAR_LITERAL_REPLACE'] = 'TRUE'
+
+def _setup_environment(environ):
+ import platform
+ # Cygwin requires some special voodoo to set the environment variables
+ # properly so that Oracle will see them.
+ if platform.system().upper().startswith('CYGWIN'):
+ try:
+ import ctypes
+ except ImportError:
+ raise ImportError("ctypes not found. The Oracle backend requires ctypes to operate correctly under Cygwin.")
+ kernel32 = ctypes.CDLL('kernel32')
+ for name, value in environ:
+ kernel32.SetEnvironmentVariableA(name, value)
+ else:
+ import os
+ os.environ.update(environ)
+
+_setup_environment([
+ # Oracle takes client-side character set encoding from the environment.
+ ('NLS_LANG', '.UTF8'),
+ # This prevents unicode from getting mangled by getting encoded into the
+ # potentially non-unicode database character set.
+ ('ORA_NCHAR_LITERAL_REPLACE', 'TRUE'),
+])
+
try:
import cx_Oracle as Database