]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- add an impl for Enum to Oracle which has subclassing requirements
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 4 Feb 2016 18:36:45 +0000 (13:36 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 4 Feb 2016 18:36:45 +0000 (13:36 -0500)
on unicode.   Enum would be better as a TypeDecorator
at this point but then that becomes awkward with native enum
types (Interval works that way, but we don't need the bind_processor for
native interval...)

lib/sqlalchemy/dialects/oracle/cx_oracle.py

index cfbb87e7bff7b2b936fff69cca77badd01589cb1..73ea65c66364f1ae5cf52a20af7ff1d1f35a1b0e 100644 (file)
@@ -415,6 +415,18 @@ class _OracleLong(oracle.LONG):
 class _OracleString(_NativeUnicodeMixin, sqltypes.String):
     pass
 
+class _OracleEnum(_NativeUnicodeMixin, sqltypes.Enum):
+    def bind_processor(self, dialect):
+        enum_proc = sqltypes.Enum.bind_processor(self, dialect)
+        unicode_proc = _NativeUnicodeMixin.bind_processor(self, dialect)
+
+        def process(value):
+            raw_str = enum_proc(value)
+            if unicode_proc:
+                raw_str = unicode_proc(raw_str)
+            return raw_str
+        return process
+
 
 class _OracleUnicodeText(
         _LOBMixin, _NativeUnicodeMixin, sqltypes.UnicodeText):
@@ -651,6 +663,7 @@ class OracleDialect_cx_oracle(OracleDialect):
         sqltypes.String: _OracleString,
         sqltypes.UnicodeText: _OracleUnicodeText,
         sqltypes.CHAR: _OracleChar,
+        sqltypes.Enum: _OracleEnum,
 
         # a raw LONG is a text type, but does *not*
         # get the LobMixin with cx_oracle.