Skip to content

Commit 8e5b28f

Browse files
arnaud-morvanslarosa
authored andcommittedMay 29, 2016
[db_manager] Fix #14796 - Quote values depending on data type in query builder
1 parent 87121d6 commit 8e5b28f

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed
 

‎python/plugins/db_manager/db_plugins/data_model.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@ def columnCount(self, parent=None):
5757
return len(self._header)
5858

5959
def data(self, index, role):
60-
if role != Qt.DisplayRole and role != Qt.FontRole:
60+
if role not in [Qt.DisplayRole,
61+
Qt.EditRole,
62+
Qt.FontRole]:
6163
return None
6264

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

67+
if role == Qt.EditRole:
68+
return val
69+
6570
if role == Qt.FontRole: # draw NULL in italic
6671
if val is not None:
6772
return None

‎python/plugins/db_manager/dlg_query_builder.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
Query builder dialog, based on the QSpatialite plugin (GPLv2+) by Romain Riviere
2222
"""
2323

24-
from qgis.PyQt.QtCore import QObject, QEvent
24+
from qgis.PyQt.QtCore import Qt, QObject, QEvent
2525
from qgis.PyQt.QtWidgets import QDialog, QMessageBox, QTextEdit
2626

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

289289
def query_item(self, index):
290-
queryWord = index.data()
291-
queryWord = ' "%s"' % queryWord
292-
if queryWord != '':
293-
self.ui.where.insertPlainText(queryWord)
290+
value = index.data(Qt.EditRole)
291+
292+
if value is None:
293+
queryWord = u'NULL'
294+
elif isinstance(value, (int, float)):
295+
queryWord = unicode(value)
296+
else:
297+
queryWord = self.db.connector.quoteString(value)
298+
299+
if queryWord.strip() != '':
300+
self.ui.where.insertPlainText(u' ' + queryWord)
294301
self.ui.where.setFocus()
295302

296303
def use_rtree(self):

0 commit comments

Comments
 (0)
Please sign in to comment.