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
This commit is contained in:
Justin Bronn 2010-01-26 17:32:11 +00:00
parent a260980f98
commit 474ce51ffd
4 changed files with 10 additions and 4 deletions

View File

@ -18,6 +18,7 @@ class BaseSpatialOperations(object):
geography_operators = {} geography_operators = {}
geography_functions = {} geography_functions = {}
gis_terms = {} gis_terms = {}
truncate_params = {}
# Quick booleans for the type of this spatial backend, and # Quick booleans for the type of this spatial backend, and
# an attribute for the spatial database version tuple (if applicable) # an attribute for the spatial database version tuple (if applicable)

View File

@ -57,7 +57,7 @@ class SDORelate(SpatialFunction):
"Class for using SDO_RELATE." "Class for using SDO_RELATE."
masks = 'TOUCH|OVERLAPBDYDISJOINT|OVERLAPBDYINTERSECT|EQUAL|INSIDE|COVEREDBY|CONTAINS|COVERS|ANYINTERACT|ON' masks = 'TOUCH|OVERLAPBDYDISJOINT|OVERLAPBDYINTERSECT|EQUAL|INSIDE|COVEREDBY|CONTAINS|COVERS|ANYINTERACT|ON'
mask_regex = re.compile(r'^(%s)(\+(%s))*$' % (masks, masks), re.I) 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' relate_func = 'SDO_RELATE'
def __init__(self, mask): def __init__(self, mask):
if not self.mask_regex.match(mask): if not self.mask_regex.match(mask):
@ -128,6 +128,8 @@ class OracleOperations(DatabaseOperations, BaseSpatialOperations):
gis_terms += geometry_functions.keys() gis_terms += geometry_functions.keys()
gis_terms = dict([(term, None) for term in gis_terms]) gis_terms = dict([(term, None) for term in gis_terms])
truncate_params = {'relate' : None}
def __init__(self, connection): def __init__(self, connection):
super(OracleOperations, self).__init__() super(OracleOperations, self).__init__()
self.connection = connection self.connection = connection

View File

@ -165,7 +165,7 @@ class GeometryField(Field):
except GeometryException: except GeometryException:
raise ValueError('Could not create geometry from lookup value.') raise ValueError('Could not create geometry from lookup value.')
else: 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. # Assigning the SRID value.
geom.srid = self.get_srid(geom) geom.srid = self.get_srid(geom)
@ -228,6 +228,10 @@ class GeometryField(Field):
if lookup_type in connection.ops.distance_functions: if lookup_type in connection.ops.distance_functions:
# Getting the distance parameter in the units of the field. # Getting the distance parameter in the units of the field.
params += self.get_distance(value[1:], lookup_type, connection) 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: else:
params += value[1:] params += value[1:]
elif isinstance(value, SQLEvaluator): elif isinstance(value, SQLEvaluator):

View File

@ -426,7 +426,6 @@ class GeoModelTest(TestCase):
@no_mysql @no_mysql
def test15_relate(self): def test15_relate(self):
"Testing the 'relate' lookup type." "Testing the 'relate' lookup type."
return
# To make things more interesting, we will have our Texas reference point in # To make things more interesting, we will have our Texas reference point in
# different SRIDs. # different SRIDs.
pnt1 = fromstr('POINT (649287.0363174 4177429.4494686)', srid=2847) 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 # Not passing in a geometry as first param shoud
# raise a type error when initializing the GeoQuerySet # 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 # Making sure the right exception is raised for the given
# bad arguments. # bad arguments.