Refs #33308 -- Made PostGISAdapter do not use psycopg2's Binary().
This commit is contained in:
parent
0ff46591ac
commit
2fecf99ade
@ -1,7 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
This object provides quoting for GEOS geometries into PostgreSQL/PostGIS.
|
This object provides quoting for GEOS geometries into PostgreSQL/PostGIS.
|
||||||
"""
|
"""
|
||||||
from psycopg2 import Binary
|
from psycopg2 import extensions
|
||||||
from psycopg2.extensions import ISQLQuote
|
from psycopg2.extensions import ISQLQuote
|
||||||
|
|
||||||
from django.contrib.gis.db.backends.postgis.pgraster import to_pgraster
|
from django.contrib.gis.db.backends.postgis.pgraster import to_pgraster
|
||||||
@ -19,7 +19,6 @@ class PostGISAdapter:
|
|||||||
# the adaptor) and the SRID from the geometry or raster.
|
# the adaptor) and the SRID from the geometry or raster.
|
||||||
if self.is_geometry:
|
if self.is_geometry:
|
||||||
self.ewkb = bytes(obj.ewkb)
|
self.ewkb = bytes(obj.ewkb)
|
||||||
self._adapter = Binary(self.ewkb)
|
|
||||||
else:
|
else:
|
||||||
self.ewkb = to_pgraster(obj)
|
self.ewkb = to_pgraster(obj)
|
||||||
|
|
||||||
@ -48,13 +47,12 @@ class PostGISAdapter:
|
|||||||
def _fix_polygon(cls, poly):
|
def _fix_polygon(cls, poly):
|
||||||
return poly
|
return poly
|
||||||
|
|
||||||
def prepare(self, conn):
|
def _quote(self, value):
|
||||||
"""
|
adapted = extensions.adapt(value)
|
||||||
This method allows escaping the binary in the style required by the
|
if hasattr(adapted, "encoding"):
|
||||||
server's `standard_conforming_string` setting.
|
adapted.encoding = "utf8"
|
||||||
"""
|
# getquoted() returns a quoted bytestring of the adapted value.
|
||||||
if self.is_geometry:
|
return adapted.getquoted().decode()
|
||||||
self._adapter.prepare(conn)
|
|
||||||
|
|
||||||
def getquoted(self):
|
def getquoted(self):
|
||||||
"""
|
"""
|
||||||
@ -64,8 +62,8 @@ class PostGISAdapter:
|
|||||||
# Psycopg will figure out whether to use E'\\000' or '\000'.
|
# Psycopg will figure out whether to use E'\\000' or '\000'.
|
||||||
return b"%s(%s)" % (
|
return b"%s(%s)" % (
|
||||||
b"ST_GeogFromWKB" if self.geography else b"ST_GeomFromEWKB",
|
b"ST_GeogFromWKB" if self.geography else b"ST_GeomFromEWKB",
|
||||||
self._adapter.getquoted(),
|
self._quote(self.ewkb).encode(),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# For rasters, add explicit type cast to WKB string.
|
# For rasters, add explicit type cast to WKB string.
|
||||||
return b"'%s'::raster" % self.ewkb.encode()
|
return b"'%s'::raster" % self.ewkb.hex().encode()
|
||||||
|
@ -149,5 +149,4 @@ def to_pgraster(rast):
|
|||||||
# Add packed header and band data to result
|
# Add packed header and band data to result
|
||||||
result += bandheader + band.data(as_memoryview=True)
|
result += bandheader + band.data(as_memoryview=True)
|
||||||
|
|
||||||
# Convert raster to hex string before passing it to the DB.
|
return result
|
||||||
return result.hex()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user