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
Closes #16626
  • Loading branch information
strk committed Jun 2, 2017
1 parent 19ddeb1 commit 6f42b78
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
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,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 @@ -313,6 +311,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 6f42b78

Please sign in to comment.