Script to update the values inside the database

This commit is contained in:
caminsha 2022-07-17 23:57:13 +02:00
parent 9e6574bd5a
commit a0c47ca97c
2 changed files with 13 additions and 0 deletions

3
sql/update_sg.sql Normal file
View file

@ -0,0 +1,3 @@
UPDATE customers
SET CITY = 'St. Gallen'
WHERE CITY LIKE "St.%gallen";

View file

@ -23,6 +23,11 @@ def parse_args():
default='table', default='table',
help='prints all the cells from the table', help='prints all the cells from the table',
) )
parser.add_argument(
'-u', '--update',
action='store_true',
help='Updates the city names'
)
return parser.parse_args() return parser.parse_args()
@ -39,6 +44,11 @@ def execute_sql(args):
print("insert") print("insert")
with open ('sql/insert_data.sql', 'r') as sql_file: with open ('sql/insert_data.sql', 'r') as sql_file:
cur.executescript(sql_file.read()) cur.executescript(sql_file.read())
elif args.update:
print("Updating database")
with open ('sql/update_sg.sql', 'r') as sql_file:
cur.executescript(sql_file.read())
elif args.print: elif args.print:
cur.execute("SELECT * from customers") cur.execute("SELECT * from customers")
if args.print == 'table': if args.print == 'table':