Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed the Oracle environment variables not getting set correctly unde…

…r Cygwin.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14781 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit cbf9d6e0bbc323a81449250f139944e4c0b23b2c 1 parent bb10a5b
Ian Kelly authored December 03, 2010

Showing 1 changed file with 25 additions and 6 deletions. Show diff stats Hide diff stats

  1. 31  django/db/backends/oracle/base.py
31  django/db/backends/oracle/base.py
@@ -6,16 +6,35 @@
6 6
 
7 7
 
8 8
 import datetime
9  
-import os
10 9
 import sys
11 10
 import time
12 11
 from decimal import Decimal
13 12
 
14  
-# Oracle takes client-side character set encoding from the environment.
15  
-os.environ['NLS_LANG'] = '.UTF8'
16  
-# This prevents unicode from getting mangled by getting encoded into the
17  
-# potentially non-unicode database character set.
18  
-os.environ['ORA_NCHAR_LITERAL_REPLACE'] = 'TRUE'
  13
+
  14
+def _setup_environment(environ):
  15
+    import platform
  16
+    # Cygwin requires some special voodoo to set the environment variables
  17
+    # properly so that Oracle will see them.
  18
+    if platform.system().upper().startswith('CYGWIN'):
  19
+        try:
  20
+            import ctypes
  21
+        except ImportError:
  22
+            raise ImportError("ctypes not found. The Oracle backend requires ctypes to operate correctly under Cygwin.")
  23
+        kernel32 = ctypes.CDLL('kernel32')
  24
+        for name, value in environ:
  25
+            kernel32.SetEnvironmentVariableA(name, value)
  26
+    else:
  27
+        import os
  28
+        os.environ.update(environ)
  29
+
  30
+_setup_environment([
  31
+    # Oracle takes client-side character set encoding from the environment.
  32
+    ('NLS_LANG', '.UTF8'),
  33
+    # This prevents unicode from getting mangled by getting encoded into the
  34
+    # potentially non-unicode database character set.
  35
+    ('ORA_NCHAR_LITERAL_REPLACE', 'TRUE'),
  36
+])
  37
+
19 38
 
20 39
 try:
21 40
     import cx_Oracle as Database

0 notes on commit cbf9d6e

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