From 8db8deee791bf125b0479e514a8114f611222063 Mon Sep 17 00:00:00 2001 From: Jan Bertram Date: Thu, 16 Nov 2023 11:22:03 +0100 Subject: [PATCH] fixes bug: setting user who is not present in `pianist`-table is no longer allowed --- README.md | 4 ++-- rep_cli.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index aafb966..547b336 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,8 @@ At the moment, an alpha version is undertaken, with these features: - Works are shown sorted by composer and opus/work_directory-number (`s`, `smo`) or by composer and collection (`sm`) - Remove work or movement from being mastered for active user (`r number_of_work` or `r number_of_work number_of_movement`) - Remove user (`delete_my_user_record_including_all_mastered_works`) -- Fix bug: double marking crashes the program +- Fixed bug: double marking crashes the program +- Fixed bug: check for user before setting _(planned) Release piano_repertoire_cli V 0.0.1 alpha (learn about versioning before)_ @@ -44,6 +45,5 @@ _(planned) Port funtionality to a kivy-GUI_ ## Known Bugs -- User numbers are allowed to set without a user being present, with marking works as mastered leading to crash the program - Trying to mark works as mastered that are not present crashes the program - Providing alphabetic chars where numbers are expected crashes the program \ No newline at end of file diff --git a/rep_cli.py b/rep_cli.py index 28d7010..6d03f8a 100644 --- a/rep_cli.py +++ b/rep_cli.py @@ -23,9 +23,19 @@ class Session: } def set_user(self, arguments): + resultstring = '' db_index = arguments[0] - self.user = db_index - return 'User set' + sql_command = f''' + SELECT * + FROM pianist + WHERE id = {db_index} + ''' + if self.db_agent.execute(sql_command).fetchone(): + self.user = db_index + resultstring += 'User set' + else: + resultstring += 'No such user' + return resultstring def get_active_user(self): sql_command = f'''