Skip to content
Permalink
Browse files

Merge pull request #8037 from elpaso/bugfix-db-manager-sql

Bugfix db manager sql
  • Loading branch information
elpaso committed Sep 27, 2018
2 parents a1d130a + c06c475 commit 08ac1f0edece8b009c5e8241e2f5d52172a81d38
Showing with 12 additions and 2 deletions.
  1. +12 −2 python/plugins/db_manager/dlg_sql_layer_window.py
@@ -116,6 +116,10 @@ def __init__(self, iface, layer, parent=None):
self.presetCombo.activated[str].connect(self.loadPreset)
self.presetCombo.activated[str].connect(self.presetName.setText)

self.editSql.textChanged.connect(self.updatePresetButtonsState)
self.presetName.textChanged.connect(self.updatePresetButtonsState)
self.presetCombo.currentIndexChanged.connect(self.updatePresetButtonsState)

self.updatePresetsCombobox()

self.geomCombo.setEditable(True)
@@ -145,11 +149,11 @@ def __init__(self, iface, layer, parent=None):
# First the SQL from QgsDataSourceUri table
sql = uri.table()
if uri.keyColumn() == '_uid_':
match = re.search('^\(SELECT .+ AS _uid_,\* FROM \((.*)\) AS _subq_.+_\s*\)$', sql, re.S)
match = re.search(r'^\(SELECT .+ AS _uid_,\* FROM \((.*)\) AS _subq_.+_\s*\)$', sql, re.S | re.X)
if match:
sql = match.group(1)
else:
match = re.search('^\((SELECT .+ FROM .+)\)$', sql, re.S)
match = re.search(r'^\((SELECT .+ FROM .+)\)$', sql, re.S | re.X)
if match:
sql = match.group(1)
# Need to check on table() since the parentheses were removed by the regexp
@@ -186,6 +190,12 @@ def __init__(self, iface, layer, parent=None):
def getQueryHash(self, name):
return 'q%s' % md5(name.encode('utf8')).hexdigest()

def updatePresetButtonsState(self, *args):
"""Slot called when the combo box or the sql or the query name have changed:
sets store button state"""
self.presetStore.setEnabled(bool(self._getSqlQuery() and self.presetName.text()))
self.presetDelete.setEnabled(bool(self.presetCombo.currentIndex() != -1))

def updatePresetsCombobox(self):
self.presetCombo.clear()

0 comments on commit 08ac1f0

Please sign in to comment.
You can’t perform that action at this time.