Ticket #16778: postgis-adapter.patch
File postgis-adapter.patch, 1.4 KB (added by , 13 years ago) |
---|
-
django/contrib/gis/db/backends/postgis/adapter.py
old new 3 3 """ 4 4 5 5 from psycopg2 import Binary 6 from psycopg2.extensions import ISQLQuote 6 from psycopg2.extensions import ISQLQuote, adapt 7 7 8 8 class PostGISAdapter(object): 9 9 def __init__(self, geom): … … 12 12 # the adaptor) and the SRID from the geometry. 13 13 self.ewkb = str(geom.ewkb) 14 14 self.srid = geom.srid 15 self._adapter = Binary(self.ewkb) 15 16 16 17 def __conform__(self, proto): 17 18 # Does the given protocol conform to what Psycopg2 expects? … … 26 27 def __str__(self): 27 28 return self.getquoted() 28 29 30 def prepare(self, conn): 31 # Pass the connection to the adapter: this allows escaping the binary 32 # in the style required by the server's standard_conforming_string setting. 33 self._adapter.prepare(conn) 34 29 35 def getquoted(self): 30 36 "Returns a properly quoted string for use in PostgreSQL/PostGIS." 31 # Want to use WKB, so wrap with psycopg2 Binary() to quote properly.32 return 'ST_GeomFromEWKB( E%s)' % Binary(self.ewkb)37 # psycopg will figure out whether to use E'\\000' or '\000' 38 return 'ST_GeomFromEWKB(%s)' % adapt(self._adapter) 33 39 34 40 def prepare_database_save(self, unused): 35 41 return self