Skip to content

Commit

Permalink
Fixed #12690 -- Fixed SQL template used for Oracle's with `SDO_RELATE…
Browse files Browse the repository at this point in the history
…` 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
  • Loading branch information
jbronn committed Jan 26, 2010
1 parent a260980 commit 474ce51
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions django/contrib/gis/db/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion django/contrib/gis/db/backends/oracle/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion django/contrib/gis/db/models/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def get_prep_value(self, value):
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)
Expand Down Expand Up @@ -228,6 +228,10 @@ def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False):
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):
Expand Down
3 changes: 1 addition & 2 deletions django/contrib/gis/tests/geoapp/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,14 @@ def test14_equals(self):
@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)
pnt2 = fromstr('POINT(-98.4919715741052 29.4333344025053)', srid=4326)

# 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.
Expand Down

0 comments on commit 474ce51

Please sign in to comment.