Skip to content

Commit

Permalink
Merge pull request #37 from mayurilahane/uni
Browse files Browse the repository at this point in the history
Fixed unique portal name issue.
  • Loading branch information
mayurilahane authored Jan 10, 2020
2 parents 404684e + 134eebc commit d942f56
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions genpass/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, password varchar, pwd 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"""
Expand Down

0 comments on commit d942f56

Please sign in to comment.