Compare commits

...

3 commits

Author SHA1 Message Date
caminsha a162408275 Helper script to show all the entries from St. Gallen 2022-07-17 23:57:40 +02:00
caminsha a0c47ca97c Script to update the values inside the database 2022-07-17 23:57:13 +02:00
caminsha 9e6574bd5a Added another test value 2022-07-17 23:56:28 +02:00
5 changed files with 19 additions and 0 deletions

View file

@ -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

View file

@ -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');

3
sql/show_sg.sql Normal file
View file

@ -0,0 +1,3 @@
SELECT *
from customers
where CITY LIKE "St.%gallen";

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