Skip to content

Commit 73e0811

Browse files
committed
[BUGFIX][DB Manager] Detect query layer like providers do
In postgres provider, a query layer is detected as a table starting with `(` and ending with `)`.
1 parent bf66e0f commit 73e0811

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

python/plugins/db_manager/db_manager_plugin.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def unload(self):
8080
def onLayerWasAdded(self, aMapLayer):
8181
if hasattr(aMapLayer, 'dataProvider') and aMapLayer.dataProvider().name() in ['postgres', 'spatialite', 'oracle']:
8282
uri = QgsDataSourceURI(aMapLayer.source())
83-
if re.search('^\(SELECT .+ FROM .+\)$', uri.table(), re.S):
83+
table = uri.table()
84+
if table.startswith('(') and table.endswith(')'):
8485
self.iface.legendInterface().addLegendLayerActionForLayer(self.layerAction, aMapLayer)
8586
# virtual has QUrl source
8687
# url = QUrl(QUrl.fromPercentEncoding(l.source()))
@@ -92,7 +93,8 @@ def onUpdateSqlLayer(self):
9293
l = self.iface.legendInterface().currentLayer()
9394
if l.dataProvider().name() in ['postgres', 'spatialite', 'oracle']:
9495
uri = QgsDataSourceURI(l.source())
95-
if re.search('^\(SELECT .+ FROM .+\)$', uri.table(), re.S):
96+
table = uri.table()
97+
if table.startswith('(') and table.endswith(')'):
9698
self.run()
9799
self.dlg.runSqlLayerWindow(l)
98100
# virtual has QUrl source

0 commit comments

Comments
 (0)