Skip to content

Commit 2a77ba7

Browse files
committedFeb 2, 2017
[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 c861682 commit 2a77ba7

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed
 

‎python/plugins/db_manager/db_manager_plugin.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def unload(self):
8181
def onLayerWasAdded(self, aMapLayer):
8282
if hasattr(aMapLayer, 'dataProvider') and aMapLayer.dataProvider().name() in ['postgres', 'spatialite', 'oracle']:
8383
uri = QgsDataSourceUri(aMapLayer.source())
84-
if re.search('^\(SELECT .+ FROM .+\)$', uri.table(), re.S):
84+
table = uri.table()
85+
if table.startswith('(') and table.endswith(')'):
8586
self.addCustomActionForLayer(self.layerAction, aMapLayer)
8687
# virtual has QUrl source
8788
# url = QUrl(QUrl.fromPercentEncoding(l.source()))
@@ -92,8 +93,8 @@ def onLayerWasAdded(self, aMapLayer):
9293
def onUpdateSqlLayer(self):
9394
l = self.iface.activeLayer()
9495
if l.dataProvider().name() in ['postgres', 'spatialite', 'oracle']:
95-
uri = QgsDataSourceUri(l.source())
96-
if re.search('^\(SELECT .+ FROM .+\)$', uri.table(), re.S):
96+
table = uri.table()
97+
if table.startswith('(') and table.endswith(')'):
9798
self.run()
9899
self.dlg.runSqlLayerWindow(l)
99100
# virtual has QUrl source

0 commit comments

Comments
 (0)
Please sign in to comment.