Ticket #9307: oracle-pickle.diff

File oracle-pickle.diff, 1.6 KB (added by Malcolm Tredinnick, 16 years ago)

Pickling support for Oracle

  • django/db/backends/oracle/query.py

    diff --git a/django/db/backends/oracle/query.py b/django/db/backends/oracle/query.py
    index 85e2f68..c049004 100644
    a b def query_class(QueryClass, Database):  
    2525        pass
    2626
    2727    class OracleQuery(QueryClass):
     28        def __reduce__(self):
     29            """
     30            Enable pickling for this class (normal pickling handling doesn't
     31            work as Python can only pickle module-level classes by default).
     32            """
     33            if hasattr(QueryClass, '__getstate__'):
     34                assert hasattr(QueryClass, '__setstate__')
     35                data = self.__getstate__()
     36            else:
     37                data = self.__dict__
     38            return (unpickle_query_class, (QueryClass,), data)
     39
    2840        def resolve_columns(self, row, fields=()):
    2941            index_start = len(self.extra_select.keys())
    3042            values = [self.convert_values(v, None) for v in row[:index_start]]
    def query_class(QueryClass, Database):  
    143155
    144156    _classes[QueryClass] = OracleQuery
    145157    return OracleQuery
     158
     159def unpickle_query_class(QueryClass):
     160    """
     161    Utility function for handling unpickling of Oracle Query subclasses. This
     162    is called by Python's unpickling functions.
     163    """
     164    # FIXME: Would be nice to not have any dependency on cx_Oracle here. Since
     165    # modules can't be pickled, we need a way to know to load the right module.
     166    import cx_Oracle
     167
     168    klass = query_class(QueryClass, cx_Oracle)
     169    return klass.__new__(klass)
     170unpickle_query_class.__safe_for_unpickling__ = True
     171
Back to Top