Author: jbronn Date: 2011-09-13 13:43:33 -0700 (Tue, 13 Sep 2011) New Revision: 16826
Modified: django/trunk/django/contrib/gis/db/backends/postgis/adapter.py Log: Fixed #16778 -- Improved escaping of geometries on PostgreSQL, allowing GeoDjango to work on 9.1. Thanks, piro for ticket and patch. Modified: django/trunk/django/contrib/gis/db/backends/postgis/adapter.py =================================================================== --- django/trunk/django/contrib/gis/db/backends/postgis/adapter.py 2011-09-13 20:30:24 UTC (rev 16825) +++ django/trunk/django/contrib/gis/db/backends/postgis/adapter.py 2011-09-13 20:43:33 UTC (rev 16826) @@ -12,6 +12,7 @@ # the adaptor) and the SRID from the geometry. self.ewkb = str(geom.ewkb) self.srid = geom.srid + self._adapter = Binary(self.ewkb) def __conform__(self, proto): # Does the given protocol conform to what Psycopg2 expects? @@ -28,10 +29,17 @@ def __str__(self): 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): "Returns a properly quoted string for use in PostgreSQL/PostGIS." - # Want to use WKB, so wrap with psycopg2 Binary() to quote properly. - return 'ST_GeomFromEWKB(E%s)' % Binary(self.ewkb) + # psycopg will figure out whether to use E'\\000' or '\000' + return 'ST_GeomFromEWKB(%s)' % self._adapter.getquoted() def prepare_database_save(self, unused): return self -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.