'Returns the SQL WHERE clause for use in Oracle spatial SQL construction.'

def spatial_lookup_sql(self, lvalue, lookup_type, value, field, qn):

    (alias, col, db_type) = lvalue
    geo_col = ('%s.%s' % (qn(alias), qn(col)))
    lookup_info = self.geometry_functions.get(lookup_type, False)
    if lookup_info:
        if isinstance(lookup_info, tuple):
            (sdo_op, arg_type) = lookup_info
            geom = value[0]
            if (not isinstance(value, tuple)):
                raise ValueError(('Tuple    required    for    `%s`    lookup    type.' % lookup_type))
            if (len(value) != 2):
                raise ValueError(('2-element    tuple    required    for    %s    lookup    type.' % lookup_type))
            if (not isinstance(value[1], arg_type)):
                raise ValueError(('Argument    type    should    be    %s,    got    %s    instead.' % (arg_type, type(value[1]))))
            if (lookup_type == 'relate'):
                return sdo_op(value[1]).as_sql(geo_col, self.get_geom_placeholder(field, geom))
            else:
                return sdo_op.as_sql(geo_col, self.get_geom_placeholder(field, geom))
        else:
            return lookup_info.as_sql(geo_col, self.get_geom_placeholder(field, value))
    elif (lookup_type == 'isnull'):
        return (('%s    IS    %sNULL' % (geo_col, ('' if value else 'NOT    '))), [])
    raise TypeError(('Got    invalid    lookup_type:    %s' % repr(lookup_type)))
