From a0c47ca97c2388e80cac0bad9123058a6ddc9265 Mon Sep 17 00:00:00 2001 From: caminsha Date: Sun, 17 Jul 2022 23:57:13 +0200 Subject: [PATCH] Script to update the values inside the database --- sql/update_sg.sql | 3 +++ start.py | 10 ++++++++++ 2 files changed, 13 insertions(+) create mode 100644 sql/update_sg.sql diff --git a/sql/update_sg.sql b/sql/update_sg.sql new file mode 100644 index 0000000..781c8e9 --- /dev/null +++ b/sql/update_sg.sql @@ -0,0 +1,3 @@ +UPDATE customers +SET CITY = 'St. Gallen' +WHERE CITY LIKE "St.%gallen"; diff --git a/start.py b/start.py index dfe9c9f..4338bc9 100644 --- a/start.py +++ b/start.py @@ -23,6 +23,11 @@ def parse_args(): default='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() @@ -39,6 +44,11 @@ def execute_sql(args): print("insert") with open ('sql/insert_data.sql', 'r') as sql_file: 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: cur.execute("SELECT * from customers") if args.print == 'table':