Skip to content

Commit

Permalink
For GDAL sake extract a dbname from the connection
Browse files Browse the repository at this point in the history
Works around GDAL limitation reported in:
https://trac.osgeo.org/gdal/ticket/6910

Ref #16625
Ref #16626
  • Loading branch information
strk committed Jun 2, 2017
1 parent 861cf9a commit 78c3423
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions python/plugins/db_manager/db_plugins/postgis/plugin.py
Expand Up @@ -310,8 +310,6 @@ def info(self):
def gdalUri(self, uri=None):
if not uri:
uri = self.database().uri()
# NOTE: service-only URIs won't work with GDAL up to 2.2.x
# See: https://issues.qgis.org/issues/16626
service = (u'service=%s' % uri.service()) if uri.service() else ''
schema = (u'schema=%s' % self.schemaName()) if self.schemaName() else ''
dbname = (u'dbname=%s' % uri.database()) if uri.database() else ''
Expand All @@ -320,6 +318,15 @@ def gdalUri(self, uri=None):
passw = (u'password=%s' % uri.password()) if uri.password() else ''
port = (u'port=%s' % uri.port()) if uri.port() else ''

if not dbname:
# GDAL postgisraster driver *requires* ad dbname
# See: https://trac.osgeo.org/gdal/ticket/6910
# TODO: cache this ?
connector = self.database().connector
r = connector._execute(None, "SELECT current_database()")
dbname = (u'dbname=%s' % connector._fetchone(r)[0])
connector._close_cursor(r)

# Find first raster field
col = ''
for fld in self.fields():
Expand Down

0 comments on commit 78c3423

Please sign in to comment.