Fixed #16778 -- Improved escaping of geometries on PostgreSQL, allowing GeoDjango to work on 9.1. Thanks, piro for ticket and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16826 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
dd292b948e
commit
67e05fcd39
|
@ -12,6 +12,7 @@ class PostGISAdapter(object):
|
||||||
# the adaptor) and the SRID from the geometry.
|
# the adaptor) and the SRID from the geometry.
|
||||||
self.ewkb = str(geom.ewkb)
|
self.ewkb = str(geom.ewkb)
|
||||||
self.srid = geom.srid
|
self.srid = geom.srid
|
||||||
|
self._adapter = Binary(self.ewkb)
|
||||||
|
|
||||||
def __conform__(self, proto):
|
def __conform__(self, proto):
|
||||||
# Does the given protocol conform to what Psycopg2 expects?
|
# Does the given protocol conform to what Psycopg2 expects?
|
||||||
|
@ -28,10 +29,17 @@ class PostGISAdapter(object):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.getquoted()
|
return self.getquoted()
|
||||||
|
|
||||||
|
def prepare(self, conn):
|
||||||
|
"""
|
||||||
|
This method allows escaping the binary in the style required by the
|
||||||
|
server's `standard_conforming_string` setting.
|
||||||
|
"""
|
||||||
|
self._adapter.prepare(conn)
|
||||||
|
|
||||||
def getquoted(self):
|
def getquoted(self):
|
||||||
"Returns a properly quoted string for use in PostgreSQL/PostGIS."
|
"Returns a properly quoted string for use in PostgreSQL/PostGIS."
|
||||||
# Want to use WKB, so wrap with psycopg2 Binary() to quote properly.
|
# psycopg will figure out whether to use E'\\000' or '\000'
|
||||||
return 'ST_GeomFromEWKB(E%s)' % Binary(self.ewkb)
|
return 'ST_GeomFromEWKB(%s)' % self._adapter.getquoted()
|
||||||
|
|
||||||
def prepare_database_save(self, unused):
|
def prepare_database_save(self, unused):
|
||||||
return self
|
return self
|
||||||
|
|
Loading…
Reference in New Issue