From 92b82da08b707aa739bb96166549b163454f0a6a Mon Sep 17 00:00:00 2001 From: Mayuri Lahane Date: Thu, 9 Jan 2020 02:15:58 +0530 Subject: [PATCH 1/2] Fixed unique portal name issue --- genpass/database.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genpass/database.py b/genpass/database.py index d33f890..b5bdeff 100644 --- a/genpass/database.py +++ b/genpass/database.py @@ -34,7 +34,7 @@ def __init__(self): def create_table(self): """Checked for table is created? if not then created as per required values """ self.cursor_obj.execute("""CREATE TABLE IF NOT EXISTS passwords( - id integer PRIMARY KEY, portal_name text, password varchar, pwd varchar)""") + id integer PRIMARY KEY, portal_name text PRIMARY KEY NOT NULL, password varchar)""") self.con.commit() def insert_data(self, portal_name, password): From 134eebcd5d27d6c72644e952739d5b5d94926456 Mon Sep 17 00:00:00 2001 From: Mayuri Lahane Date: Fri, 10 Jan 2020 23:44:47 +0530 Subject: [PATCH 2/2] Added portal name as unique name --- genpass/database.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/genpass/database.py b/genpass/database.py index b5bdeff..631bf63 100644 --- a/genpass/database.py +++ b/genpass/database.py @@ -33,18 +33,22 @@ def __init__(self): def create_table(self): """Checked for table is created? if not then created as per required values """ - self.cursor_obj.execute("""CREATE TABLE IF NOT EXISTS passwords( - id integer PRIMARY KEY, portal_name text PRIMARY KEY NOT NULL, password varchar)""") + self.cursor_obj.execute( + """CREATE TABLE IF NOT EXISTS passwords + (id integer PRIMARY KEY,portal_name text NOT NULL UNIQUE, password varchar) + """) self.con.commit() def insert_data(self, portal_name, password): """Adding values into database""" - self.portal_name = portal_name - self.password = password # Inserting user entered password - - self.cursor_obj.execute("""INSERT INTO passwords(portal_name, password) VALUES (?, ?)""", - (self.portal_name, self.password),) - self.con.commit() + try: + self.portal_name = portal_name + self.password = password + self.cursor_obj.execute("""INSERT INTO passwords(portal_name, password) VALUES (?, ?)""", + (self.portal_name, self.password),) + self.con.commit() + except sqlite3.IntegrityError: + print("Portal name already exists") def delete_data(self, portal_name): """Deleting values from database"""