From 2bd3c6d7da632bdb3e3e4d1938350d866cb77c26 Mon Sep 17 00:00:00 2001 From: Tomas Zigo <50632337+tmszi@users.noreply.github.com> Date: Sat, 20 Apr 2024 16:54:29 +0200 Subject: [PATCH] v.db.renamecolumn: fix enclosing column name with SQL standard double quotes (#3631) --- scripts/v.db.renamecolumn/v.db.renamecolumn.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/v.db.renamecolumn/v.db.renamecolumn.py b/scripts/v.db.renamecolumn/v.db.renamecolumn.py index 0309cff406a..87f1850a57c 100755 --- a/scripts/v.db.renamecolumn/v.db.renamecolumn.py +++ b/scripts/v.db.renamecolumn/v.db.renamecolumn.py @@ -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 ) @@ -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 )