From e6c64f69ce5c6f0c374f0d5a21f2052b262b97c0 Mon Sep 17 00:00:00 2001 From: rldhont Date: Fri, 6 Oct 2017 17:38:17 +0200 Subject: [PATCH] [FEATURE][DB Manager] Be able to update every Db layer from Postgres, Spatialite and Oracle --- python/plugins/db_manager/db_manager_plugin.py | 13 +++++-------- python/plugins/db_manager/dlg_sql_layer_window.py | 6 ++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/python/plugins/db_manager/db_manager_plugin.py b/python/plugins/db_manager/db_manager_plugin.py index e71dd22d839..a9af1bdc00d 100644 --- a/python/plugins/db_manager/db_manager_plugin.py +++ b/python/plugins/db_manager/db_manager_plugin.py @@ -79,11 +79,9 @@ class DBManagerPlugin(object): self.dlg.close() def onLayerWasAdded(self, aMapLayer): + # Be able to update every Db layer from Postgres, Spatialite and Oracle if hasattr(aMapLayer, 'dataProvider') and aMapLayer.dataProvider().name() in ['postgres', 'spatialite', 'oracle']: - uri = QgsDataSourceUri(aMapLayer.source()) - table = uri.table() - if table.startswith('(') and table.endswith(')'): - self.iface.addCustomActionForLayer(self.layerAction, aMapLayer) + self.iface.addCustomActionForLayer(self.layerAction, aMapLayer) # virtual has QUrl source # url = QUrl(QUrl.fromPercentEncoding(l.source())) # url.queryItemValue('query') @@ -91,12 +89,11 @@ class DBManagerPlugin(object): # url.queryItemValue('geometry') def onUpdateSqlLayer(self): + # Be able to update every Db layer from Postgres, Spatialite and Oracle l = self.iface.activeLayer() if l.dataProvider().name() in ['postgres', 'spatialite', 'oracle']: - table = QgsDataSourceUri(l.source()).table() - if table.startswith('(') and table.endswith(')'): - self.run() - self.dlg.runSqlLayerWindow(l) + self.run() + self.dlg.runSqlLayerWindow(l) # virtual has QUrl source # url = QUrl(QUrl.fromPercentEncoding(l.source())) # url.queryItemValue('query') diff --git a/python/plugins/db_manager/dlg_sql_layer_window.py b/python/plugins/db_manager/dlg_sql_layer_window.py index 8bb7232c9b6..012ed397c14 100644 --- a/python/plugins/db_manager/dlg_sql_layer_window.py +++ b/python/plugins/db_manager/dlg_sql_layer_window.py @@ -151,6 +151,12 @@ class DlgSqlLayerWindow(QWidget, Ui_Dialog): match = re.search('^\((SELECT .+ FROM .+)\)$', sql, re.S) if match: sql = match.group(1) + if not sql.startswith('(') and not sql.endswith(')'): + schema = uri.schema() + if schema and schema.upper() != 'PUBLIC': + sql = 'SELECT * FROM ' + schema + '.' + sql + else + sql = 'SELECT * FROM ' + sql self.editSql.setText(sql) self.executeSql()