Commit 474ce51f authored by Justin Bronn's avatar Justin Bronn
Browse files

Fixed #12690 -- Fixed SQL template used for Oracle's with `SDO_RELATE`...

Fixed #12690 -- Fixed SQL template used for Oracle's with `SDO_RELATE` function, added `truncate_params` attribute to spatial backend, and re-enabled the `relate` lookup tests.  Thanks, jtiai, for the bug report.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@12300 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent a260980f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ class BaseSpatialOperations(object):
    geography_operators = {}
    geography_functions = {}
    gis_terms = {}
    truncate_params = {}

    # Quick booleans for the type of this spatial backend, and
    # an attribute for the spatial database version tuple (if applicable)
+3 −1
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ class SDORelate(SpatialFunction):
    "Class for using SDO_RELATE."
    masks = 'TOUCH|OVERLAPBDYDISJOINT|OVERLAPBDYINTERSECT|EQUAL|INSIDE|COVEREDBY|CONTAINS|COVERS|ANYINTERACT|ON'
    mask_regex = re.compile(r'^(%s)(\+(%s))*$' % (masks, masks), re.I)
    sql_template = "%(function)s(%(geo_col)s, %(geometry)s, 'mask=%(mask)s)' = 'TRUE'"
    sql_template = "%(function)s(%(geo_col)s, %(geometry)s, 'mask=%(mask)s') = 'TRUE'"
    relate_func = 'SDO_RELATE'
    def __init__(self, mask):
        if not self.mask_regex.match(mask):
@@ -128,6 +128,8 @@ class OracleOperations(DatabaseOperations, BaseSpatialOperations):
    gis_terms += geometry_functions.keys()
    gis_terms = dict([(term, None) for term in gis_terms])

    truncate_params = {'relate' : None}

    def __init__(self, connection):
        super(OracleOperations, self).__init__()
        self.connection = connection
+5 −1
Original line number Diff line number Diff line
@@ -165,7 +165,7 @@ class GeometryField(Field):
            except GeometryException:
                raise ValueError('Could not create geometry from lookup value.')
        else:
            raise ValueError('Cannot use parameter of `%s` type as lookup parameter.' % type(value))
            raise ValueError('Cannot use object with type %s for a geometry lookup parameter.' % type(geom).__name__)

        # Assigning the SRID value.
        geom.srid = self.get_srid(geom)
@@ -228,6 +228,10 @@ class GeometryField(Field):
                if lookup_type in connection.ops.distance_functions:
                    # Getting the distance parameter in the units of the field.
                    params += self.get_distance(value[1:], lookup_type, connection)
                elif lookup_type in connection.ops.truncate_params:
                    # Lookup is one where SQL parameters aren't needed from the
                    # given lookup value.
                    pass
                else:
                    params += value[1:]
            elif isinstance(value, SQLEvaluator):
+1 −2
Original line number Diff line number Diff line
@@ -426,7 +426,6 @@ class GeoModelTest(TestCase):
    @no_mysql
    def test15_relate(self):
        "Testing the 'relate' lookup type."
        return
        # To make things more interesting, we will have our Texas reference point in
        # different SRIDs.
        pnt1 = fromstr('POINT (649287.0363174 4177429.4494686)', srid=2847)
@@ -434,7 +433,7 @@ class GeoModelTest(TestCase):

        # Not passing in a geometry as first param shoud
        # raise a type error when initializing the GeoQuerySet
        self.assertRaises(ValueError, Country.objects.filter(mpoly__relate=(23, 'foo')).count)
        self.assertRaises(ValueError, Country.objects.filter, mpoly__relate=(23, 'foo'))

        # Making sure the right exception is raised for the given
        # bad arguments.