Ticket #9307: oracle-pickle-v2.diff

File oracle-pickle-v2.diff, 2.3 KB (added by jbronn, 16 years ago)
  • django/db/models/sql/query.py

     
    2727except NameError:
    2828    from sets import Set as set     # Python 2.3 fallback
    2929
    30 __all__ = ['Query']
     30__all__ = ['Query', 'BaseQuery']
    3131
    32 class Query(object):
     32class BaseQuery(object):
    3333    """
    3434    A single SQL query.
    3535    """
     
    17471747# Use the backend's custom Query class if it defines one. Otherwise, use the
    17481748# default.
    17491749if connection.features.uses_custom_query_class:
    1750     Query = connection.ops.query_class(Query)
     1750    Query = connection.ops.query_class(BaseQuery)
     1751else:
     1752    Query = BaseQuery
    17511753
    17521754def get_order_dir(field, default='ASC'):
    17531755    """
  • django/db/backends/oracle/query.py

     
    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]]
     
    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