diff --git a/gui/wxpython/dbmgr/base.py b/gui/wxpython/dbmgr/base.py index 482c3ccf7db..3db3bf40918 100644 --- a/gui/wxpython/dbmgr/base.py +++ b/gui/wxpython/dbmgr/base.py @@ -238,7 +238,10 @@ def LoadData(self, layer, columns=None, where=None, sql=None): self.sqlFilter = {"where": where} if columns: - cmdParams.update(dict(columns=",".join(columns))) + # Enclose column name with SQL standard double quotes + cmdParams.update( + dict(columns=",".join([f'"{col}"' for col in columns])) + ) ret = RunCommand("v.db.select", **cmdParams) @@ -2109,8 +2112,9 @@ def OnApplySqlStatement(self, event): try: if len(whereVal) > 0: showSelected = True + # Enclose column name with SQL standard double quotes keyColumn = listWin.LoadData( - self.selLayer, where=whereCol + whereOpe + whereVal + self.selLayer, where=f'"{whereCol}"' + whereOpe + whereVal ) else: keyColumn = listWin.LoadData(self.selLayer) diff --git a/gui/wxpython/dbmgr/sqlbuilder.py b/gui/wxpython/dbmgr/sqlbuilder.py index a4bc926463c..eaada441652 100644 --- a/gui/wxpython/dbmgr/sqlbuilder.py +++ b/gui/wxpython/dbmgr/sqlbuilder.py @@ -365,8 +365,8 @@ def OnUniqueValues(self, event, justsample=False): return self.list_values.Clear() - - sql = "SELECT DISTINCT {column} FROM {table} ORDER BY {column}".format( + # Enclose column name with SQL standard double quotes + sql = 'SELECT DISTINCT "{column}" FROM {table} ORDER BY "{column}"'.format( column=column, table=self.tablename ) if justsample: @@ -399,7 +399,8 @@ def OnAddColumn(self, event): idx = self.list_columns.GetSelections() for i in idx: column = self.list_columns.GetString(i) - self._add(element="column", value=column) + # Enclose column name with SQL standard double quotes + self._add(element="column", value=f'"{column}"') if not self.btn_uniquesample.IsEnabled(): self.btn_uniquesample.Enable(True)