Skip to content

Commit 6f42b78

Browse files
committed
For GDAL sake extract a dbname from the connection
Works around GDAL limitation reported in: https://trac.osgeo.org/gdal/ticket/6910 Ref #16625 Closes #16626
1 parent 19ddeb1 commit 6f42b78

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

  • python/plugins/db_manager/db_plugins/postgis

‎python/plugins/db_manager/db_plugins/postgis/plugin.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,6 @@ def info(self):
303303
def gdalUri(self, uri=None):
304304
if not uri:
305305
uri = self.database().uri()
306-
# NOTE: service-only URIs won't work with GDAL up to 2.2.x
307-
# See: https://issues.qgis.org/issues/16626
308306
service = (u'service=%s' % uri.service()) if uri.service() else ''
309307
schema = (u'schema=%s' % self.schemaName()) if self.schemaName() else ''
310308
dbname = (u'dbname=%s' % uri.database()) if uri.database() else ''
@@ -313,6 +311,15 @@ def gdalUri(self, uri=None):
313311
passw = (u'password=%s' % uri.password()) if uri.password() else ''
314312
port = (u'port=%s' % uri.port()) if uri.port() else ''
315313

314+
if not dbname:
315+
# GDAL postgisraster driver *requires* ad dbname
316+
# See: https://trac.osgeo.org/gdal/ticket/6910
317+
# TODO: cache this ?
318+
connector = self.database().connector
319+
r = connector._execute(None, "SELECT current_database()")
320+
dbname = (u'dbname=%s' % connector._fetchone(r)[0])
321+
connector._close_cursor(r)
322+
316323
# Find first raster field
317324
col = ''
318325
for fld in self.fields():

0 commit comments

Comments
 (0)