From 9e6574bd5a8e53e074b1677975898b844cc3298a Mon Sep 17 00:00:00 2001 From: caminsha Date: Sun, 17 Jul 2022 23:56:28 +0200 Subject: [PATCH 1/3] Added another test value --- sql/insert_data.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/insert_data.sql b/sql/insert_data.sql index 0793608..6c151af 100644 --- a/sql/insert_data.sql +++ b/sql/insert_data.sql @@ -2,3 +2,4 @@ INSERT INTO customers VALUES(1, 'Egger', 'Stefan', 'St. Gallen', '9000'); INSERT INTO customers VALUES(2, 'Müller', 'Sepp', 'St.Gallen', '9000'); INSERT INTO customers VALUES(3, 'Kurt', 'Kurtl', 'St. gallen', '9000'); INSERT INTO customers VALUES(4, 'Kurt', 'Kurtl', 'St.gallen', '9000'); +INSERT INTO customers VALUES(5, 'Kurt', 'Kurtl', 'St. Moritz', '9200'); From a0c47ca97c2388e80cac0bad9123058a6ddc9265 Mon Sep 17 00:00:00 2001 From: caminsha Date: Sun, 17 Jul 2022 23:57:13 +0200 Subject: [PATCH 2/3] 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': From a162408275fa522d2f23701f7e03c6f39337caf1 Mon Sep 17 00:00:00 2001 From: caminsha Date: Sun, 17 Jul 2022 23:57:40 +0200 Subject: [PATCH 3/3] Helper script to show all the entries from St. Gallen --- script.sh | 2 ++ sql/show_sg.sql | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 sql/show_sg.sql diff --git a/script.sh b/script.sh index 393f0e2..22fbabb 100644 --- a/script.sh +++ b/script.sh @@ -4,6 +4,8 @@ if [[ $1 -eq "0" ]]; then sqlite3 test.db ".read sql/create_db.sql" elif [[ $1 -eq "1" ]]; then sqlite3 test.db ".read sql/insert_data.sql" +elif [[ $1 -eq "2" ]]; then + sqlite3 test.db ".read sql/show_sg.sql" elif [[ $1 -eq "9" ]]; then sqlite3 test.db ".read sql/show_all.sql" fi diff --git a/sql/show_sg.sql b/sql/show_sg.sql new file mode 100644 index 0000000..44d52a0 --- /dev/null +++ b/sql/show_sg.sql @@ -0,0 +1,3 @@ +SELECT * +from customers +where CITY LIKE "St.%gallen";