mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
[FEATURE][DB Manager] Be able to update every Db layer from Postgres, Spatialite and Oracle
This commit is contained in:
parent
e45206ab3e
commit
e6c64f69ce
@ -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')
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user