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':