From 91b5e6ae7b58a2e0c1b051d0433fcf49910894e9 Mon Sep 17 00:00:00 2001 From: Darksider3 Date: Thu, 17 Oct 2019 15:27:38 +0200 Subject: [PATCH] Positional fix: OperationalError before general --- private/lib/sqlitedb.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/private/lib/sqlitedb.py b/private/lib/sqlitedb.py index be4c98f..c51fb2d 100644 --- a/private/lib/sqlitedb.py +++ b/private/lib/sqlitedb.py @@ -85,15 +85,17 @@ class SQLitedb: self.cursor.execute(qq, deliver) self.last_result = self.cursor.fetchall() self.connection.commit() - except sqlite3.Error as e: - print("Couldn't execute query %s, exception: %s" % (qq, e), file=stderr) - self.last_result = [] except TypeError as e: print("Types in given tuple doesnt match to execute query \"%s\": %s" % (qq, e), file=stderr) self.last_result = [] except sqlite3.OperationalError as e: self._createTable() return self.safequery(qq, deliver) + except sqlite3.Error as e: + print("Couldn't execute query %s, exception: %s" % (qq, e), file=stderr) + print(deliver) + print(type(e)) + self.last_result = [] return self.last_result def removeApplicantFromDB(self, userid: int) -> bool: @@ -107,13 +109,13 @@ class SQLitedb: try: self.last_result = self.cursor.execute("DELETE FROM `applications` WHERE id = ? ", [userid]) self.connection.commit() - except sqlite3.Error as e: - print(f"Could not delete user with id: {userid}, exception in DB: {e}") # @TODO LOGGING FFS - return False except sqlite3.OperationalError: print("The database has probably not yet seen any users, so it didnt create your table yet. Come back" "when a user tried to register") return False + except sqlite3.Error as e: + print(f"Could not delete user with id: {userid}, exception in DB: {e}") # @TODO LOGGING FFS + return False return True def removeApplicantFromDBperUsername(self, username: str) -> bool: @@ -127,13 +129,13 @@ class SQLitedb: try: self.last_result = self.cursor.execute("DELETE FROM `applications` WHERE username = ?", [username]) self.connection.commit() - except sqlite3.Error as e: - print(f"Could not delete user {username}, exception in DB: {e}") # @TODO LOGGING - return False except sqlite3.OperationalError: print("The database has probably not yet seen any users, so it didnt create your table yet. Come back" "when a user tried to register") return False + except sqlite3.Error as e: + print(f"Could not delete user {username}, exception in DB: {e}") # @TODO LOGGING + return False return True def _createTable(self):