Skip to content
Permalink
Browse files

[dbmanager] Fix stored queries retrieve

Fixes #19802 - DB Manager saved SQL statements are saved empty
  • Loading branch information
elpaso committed Sep 18, 2018
1 parent 5b7e60a commit a74b6262df6e07473d1c02568b9cce5eb2b41fdd
Showing with 19 additions and 11 deletions.
  1. +9 −5 python/plugins/db_manager/dlg_sql_layer_window.py
  2. +10 −6 python/plugins/db_manager/dlg_sql_window.py
@@ -24,6 +24,7 @@
from builtins import zip
from builtins import next
from builtins import str
from hashlib import md5

from qgis.PyQt.QtCore import Qt, pyqtSignal
from qgis.PyQt.QtWidgets import QDialog, QWidget, QAction, QApplication, QStyledItemDelegate
@@ -181,6 +182,9 @@ def __init__(self, iface, layer, parent=None):
if uri.selectAtIdDisabled():
self.avoidSelectById.setCheckState(Qt.Checked)

def getQueryHash(self, name):
return 'q%s' % md5(name.encode('utf8')).hexdigest()

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

@@ -199,8 +203,8 @@ def storePreset(self):
if query == "":
return
name = self.presetName.text()
QgsProject.instance().writeEntry('DBManager', 'savedQueries/q' + str(name.__hash__()) + '/name', name)
QgsProject.instance().writeEntry('DBManager', 'savedQueries/q' + str(name.__hash__()) + '/query', query)
QgsProject.instance().writeEntry('DBManager', 'savedQueries/' + self.getQueryHash(name) + '/name', name)
QgsProject.instance().writeEntry('DBManager', 'savedQueries/' + self.getQueryHash(name) + '/query', query)
index = self.presetCombo.findText(name)
if index == -1:
self.presetCombo.addItem(name)
@@ -210,13 +214,13 @@ def storePreset(self):

def deletePreset(self):
name = self.presetCombo.currentText()
QgsProject.instance().removeEntry('DBManager', 'savedQueries/q' + str(name.__hash__()))
QgsProject.instance().removeEntry('DBManager', 'savedQueries/q' + self.getQueryHash(name))
self.presetCombo.removeItem(self.presetCombo.findText(name))
self.presetCombo.setCurrentIndex(-1)

def loadPreset(self, name):
query = QgsProject.instance().readEntry('DBManager', 'savedQueries/q' + str(name.__hash__()) + '/query')[0]
name = QgsProject.instance().readEntry('DBManager', 'savedQueries/q' + str(name.__hash__()) + '/name')[0]
query = QgsProject.instance().readEntry('DBManager', 'savedQueries/' + self.getQueryHash(name) + '/query')[0]
name = QgsProject.instance().readEntry('DBManager', 'savedQueries/' + self.getQueryHash(name) + '/name')[0]
self.editSql.setText(query)

def clearSql(self):
@@ -24,6 +24,7 @@
from builtins import zip
from builtins import next
from builtins import str
from hashlib import md5

from qgis.PyQt.QtCore import Qt, pyqtSignal
from qgis.PyQt.QtWidgets import QDialog, QWidget, QAction, QApplication, QInputDialog, QStyledItemDelegate, QTableWidgetItem
@@ -197,6 +198,9 @@ def writeQueryHistory(self, sql, affectedRows, secs):

self.populateQueryHistory()

def getQueryHash(self, name):
return 'q%s' % md5(name.encode('utf8')).hexdigest()

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

@@ -214,9 +218,9 @@ def storePreset(self):
query = self._getSqlQuery()
if query == "":
return
name = self.presetName.text()
QgsProject.instance().writeEntry('DBManager', 'savedQueries/q' + str(name.__hash__()) + '/name', name)
QgsProject.instance().writeEntry('DBManager', 'savedQueries/q' + str(name.__hash__()) + '/query', query)
name = str(self.presetName.text())
QgsProject.instance().writeEntry('DBManager', 'savedQueries/' + self.getQueryHash(name) + '/name', name)
QgsProject.instance().writeEntry('DBManager', 'savedQueries/' + self.getQueryHash(name) + '/query', query)
index = self.presetCombo.findText(name)
if index == -1:
self.presetCombo.addItem(name)
@@ -226,13 +230,13 @@ def storePreset(self):

def deletePreset(self):
name = self.presetCombo.currentText()
QgsProject.instance().removeEntry('DBManager', 'savedQueries/q' + str(name.__hash__()))
QgsProject.instance().removeEntry('DBManager', 'savedQueries/' + self.getQueryHash(name))
self.presetCombo.removeItem(self.presetCombo.findText(name))
self.presetCombo.setCurrentIndex(-1)

def loadPreset(self, name):
query = QgsProject.instance().readEntry('DBManager', 'savedQueries/q' + str(name.__hash__()) + '/query')[0]
name = QgsProject.instance().readEntry('DBManager', 'savedQueries/q' + str(name.__hash__()) + '/name')[0]
query = QgsProject.instance().readEntry('DBManager', 'savedQueries/' + self.getQueryHash(name) + '/query')[0]
name = QgsProject.instance().readEntry('DBManager', 'savedQueries/' + self.getQueryHash(name) + '/name')[0]
self.editSql.setText(query)

def loadAsLayerToggled(self, checked):

0 comments on commit a74b626

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