Skip to content

Commit

Permalink
v.db.renamecolumn: fix enclosing column name with SQL standard double…
Browse files Browse the repository at this point in the history
… quotes (#3631)
  • Loading branch information
tmszi authored and neteler committed Apr 23, 2024
1 parent 815ef00 commit 2bd3c6d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions scripts/v.db.renamecolumn/v.db.renamecolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ def main():
# some tricks
if driver in ["sqlite", "dbf"]:
if oldcoltype.upper() == "CHARACTER":
colspec = "%s varchar(%s)" % (newcol, oldcollength)
colspec = f"{newcol} varchar({oldcollength})"
else:
colspec = "%s %s" % (newcol, oldcoltype)
colspec = f"{newcol} {oldcoltype}"

grass.run_command("v.db.addcolumn", map=map, layer=layer, column=colspec)
sql = "UPDATE %s SET %s=%s" % (table, newcol, oldcol)
sql = f'UPDATE {table} SET "{newcol}"="{oldcol}"'
grass.write_command(
"db.execute", input="-", database=database, driver=driver, stdin=sql
)
Expand All @@ -119,12 +119,12 @@ def main():
else:
newcoltype = oldcoltype

sql = "ALTER TABLE %s CHANGE %s %s %s" % (table, oldcol, newcol, newcoltype)
sql = f'ALTER TABLE {table} CHANGE "{oldcol}" "{newcol}" {newcoltype}'
grass.write_command(
"db.execute", input="-", database=database, driver=driver, stdin=sql
)
else:
sql = "ALTER TABLE %s RENAME %s TO %s" % (table, oldcol, newcol)
sql = f'ALTER TABLE {table} RENAME "{oldcol}" TO "{newcol}"'
grass.write_command(
"db.execute", input="-", database=database, driver=driver, stdin=sql
)
Expand Down

0 comments on commit 2bd3c6d

Please sign in to comment.