Skip to content
Permalink
Browse files

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
  • Loading branch information
strk committed Jun 2, 2017
1 parent 19ddeb1 commit 6f42b784b98580257e584ca6fec57809bdd56bc0
Showing with 9 additions and 2 deletions.
  1. +9 −2 python/plugins/db_manager/db_plugins/postgis/plugin.py
@@ -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 ''
@@ -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():

0 comments on commit 6f42b78

Please sign in to comment.
You can’t perform that action at this time.