Skip to content

Commit

Permalink
[FEATURE][DB Manager] Be able to update every Db layer from Postgres,…
Browse files Browse the repository at this point in the history
… Spatialite and Oracle
  • Loading branch information
rldhont committed Oct 6, 2017
1 parent e45206a commit e6c64f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 5 additions & 8 deletions python/plugins/db_manager/db_manager_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,21 @@ def unload(self):
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')
# url.queryItemValue('uid')
# 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')
Expand Down
6 changes: 6 additions & 0 deletions python/plugins/db_manager/dlg_sql_layer_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ def __init__(self, iface, layer, parent=None):
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()

Expand Down

0 comments on commit e6c64f6

Please sign in to comment.