Skip to content

Commit

Permalink
[BUGFIX][DB Manager] Detect query layer like providers do
Browse files Browse the repository at this point in the history
In postgres provider, a query layer is detected as a table starting with `(` and ending with `)`.
  • Loading branch information
rldhont committed Feb 3, 2017
1 parent bf66e0f commit 73e0811
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions python/plugins/db_manager/db_manager_plugin.py
Expand Up @@ -80,7 +80,8 @@ def unload(self):
def onLayerWasAdded(self, aMapLayer):
if hasattr(aMapLayer, 'dataProvider') and aMapLayer.dataProvider().name() in ['postgres', 'spatialite', 'oracle']:
uri = QgsDataSourceURI(aMapLayer.source())
if re.search('^\(SELECT .+ FROM .+\)$', uri.table(), re.S):
table = uri.table()
if table.startswith('(') and table.endswith(')'):
self.iface.legendInterface().addLegendLayerActionForLayer(self.layerAction, aMapLayer)
# virtual has QUrl source
# url = QUrl(QUrl.fromPercentEncoding(l.source()))
Expand All @@ -92,7 +93,8 @@ def onUpdateSqlLayer(self):
l = self.iface.legendInterface().currentLayer()
if l.dataProvider().name() in ['postgres', 'spatialite', 'oracle']:
uri = QgsDataSourceURI(l.source())
if re.search('^\(SELECT .+ FROM .+\)$', uri.table(), re.S):
table = uri.table()
if table.startswith('(') and table.endswith(')'):
self.run()
self.dlg.runSqlLayerWindow(l)
# virtual has QUrl source
Expand Down

0 comments on commit 73e0811

Please sign in to comment.