From 15dc9c55750206fea1a9010652c28c278ebfa27c Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Sat, 27 Oct 2018 16:37:24 +0530 Subject: [PATCH] Add add_to_db, update_db to base_quest --- questable.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/questable.py b/questable.py index 4d47d2a..f81297c 100644 --- a/questable.py +++ b/questable.py @@ -21,6 +21,22 @@ class base_quest(): else: date = None + def add_to_db(self): + cursor = self.DB.cursor() + query = (f'INSERT INTO {self.TABLE}(chat_id, qid, name, importance' + ', difficulty, date, state) values(?, ?, ?, ?, ?, ?, ?)') + cursor.execute(query, (self.CHAT_ID, self.QID, self.name, self.imp, + self.diff, self.date, self.state)) + self.DB.commit() + + def update_db(self): + cursor = self.DB.cursor() + query = (f'UPDATE {self.TABLE} SET name=?, importance=?, difficulty=?,' + ' date=?, state=? WHERE chat_id=? AND qid=?') + cursor.execute(query, (self.name, self.imp, self.diff, self.date, + self.state, self.CHAT_ID, self.QID)) + self.DB.commit() + class quest(base_quest): TABLE = "quests"