Code

Ticket #16778: postgis-adapter-2.patch

File postgis-adapter-2.patch, 1.2 KB (added by piro, 3 years ago)

Better patch, slightly more efficient

  • django/contrib/gis/db/backends/postgis/adapter.py

    old new  
    1212        # the adaptor) and the SRID from the geometry. 
    1313        self.ewkb = str(geom.ewkb) 
    1414        self.srid = geom.srid 
     15        self._adapter = Binary(self.ewkb) 
    1516 
    1617    def __conform__(self, proto): 
    1718        # Does the given protocol conform to what Psycopg2 expects? 
     
    2627    def __str__(self): 
    2728        return self.getquoted() 
    2829 
     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 
    2935    def getquoted(self): 
    3036        "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)' % self._adapter.getquoted() 
    3339 
    3440    def prepare_database_save(self, unused): 
    3541        return self