Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@ikelly ikelly authored
Showing with 25 additions and 6 deletions.
  1. +25 −6 django/db/backends/oracle/base.py
View
31 django/db/backends/oracle/base.py
@@ -6,16 +6,35 @@
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
Please sign in to comment.
Something went wrong with that request. Please try again.