Skip to content

Commit

Permalink
[db_manager] Fix #14796 - Quote values depending on data type in quer…
Browse files Browse the repository at this point in the history
…y builder
  • Loading branch information
arnaud-morvan authored and slarosa committed May 29, 2016
1 parent 87121d6 commit 8e5b28f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
7 changes: 6 additions & 1 deletion python/plugins/db_manager/db_plugins/data_model.py
Expand Up @@ -57,11 +57,16 @@ def columnCount(self, parent=None):
return len(self._header)

def data(self, index, role):
if role != Qt.DisplayRole and role != Qt.FontRole:
if role not in [Qt.DisplayRole,
Qt.EditRole,
Qt.FontRole]:
return None

val = self.getData(index.row(), index.column())

if role == Qt.EditRole:
return val

if role == Qt.FontRole: # draw NULL in italic
if val is not None:
return None
Expand Down
17 changes: 12 additions & 5 deletions python/plugins/db_manager/dlg_query_builder.py
Expand Up @@ -21,7 +21,7 @@
Query builder dialog, based on the QSpatialite plugin (GPLv2+) by Romain Riviere
"""

from qgis.PyQt.QtCore import QObject, QEvent
from qgis.PyQt.QtCore import Qt, QObject, QEvent
from qgis.PyQt.QtWidgets import QDialog, QMessageBox, QTextEdit

from .ui.ui_DlgQueryBuilder import Ui_DbManagerQueryBuilderDlg as Ui_Dialog
Expand Down Expand Up @@ -287,10 +287,17 @@ def list_values(self):
self.ui.values.setModel(model)

def query_item(self, index):
queryWord = index.data()
queryWord = ' "%s"' % queryWord
if queryWord != '':
self.ui.where.insertPlainText(queryWord)
value = index.data(Qt.EditRole)

if value is None:
queryWord = u'NULL'
elif isinstance(value, (int, float)):
queryWord = unicode(value)
else:
queryWord = self.db.connector.quoteString(value)

if queryWord.strip() != '':
self.ui.where.insertPlainText(u' ' + queryWord)
self.ui.where.setFocus()

def use_rtree(self):
Expand Down

0 comments on commit 8e5b28f

Please sign in to comment.