Skip to content

Commit

Permalink
wxGUI/dbmgr: fix enclosing column name with SQL standard double quotes (
Browse files Browse the repository at this point in the history
OSGeo#3634)

Enable to use (show/add/delete/rename/query) column name which is
reserved DB backend keyword.
  • Loading branch information
tmszi authored and HuidaeCho committed May 21, 2024
1 parent f5846f6 commit 7789cf3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions gui/wxpython/dbmgr/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions gui/wxpython/dbmgr/sqlbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7789cf3

Please sign in to comment.