Add support for Oracle XMLTYPE

Issue #3433 closed
Pavel Chernikov created an issue

No description provided.

Comments (2)

  1. Pavel Chernikov reporter

    I realized that this might be a tall order since cx_Oracle doesn't support this data type.

  2. Sky Leach

    relatively easy work-around:

    from sqlalchemy.sql.functions import GenericFunction
    class XMLTypeFunc(GenericFunction):
        type=CLOB
        name='XMLType'
        identifier='XMLTypeFunc'
    
    
    from sqlalchemy.types import TypeDecorator
    from lxml import etree
    class XMLType(TypeDecorator):
    
        impl = CLOB
        type = 'XMLTYPE' #etree.Element
    
        def get_col_spec(self):
            return 'XMLTYPE'
    
        def bind_processor(self, dialect):
            def process(value):
                if value is not None:
                    return etree.tostring(value, encoding='UTF-8', pretty_print='True')
                    #return etree.dump(value)
                else:
                    return None
            return process
    
        def process_result_value(self, value, dialect):
            if value is not None:
                value = etree.fromstring(value)
            return value
    
        def bind_expression(self, bindvalue):
            return XMLTypeFunc(bindvalue)
    
  3. Log in to comment