-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPMDB.py
More file actions
55 lines (45 loc) · 2.05 KB
/
PMDB.py
File metadata and controls
55 lines (45 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import sqlite3
from os import path
#Handles all direct interactions with the database
class PasswordDatabase:
def __init__(self) -> None:
dirname = path.dirname(__file__)
self.file = path.join(dirname,'sicherDB.sqlite')
self.conn = None
self.cur = None
#Connects to an exsisting database file
#or creates the file and sets up the db schema
def connect_or_create(self):
try:
self.conn = sqlite3.connect('file:' + self.file + '?mode=rw', uri=True)
self.cur = self.conn.cursor()
#self.cur.execute("SELECT name FROM sqlite_master where type = 'table';")
#print(self.cur.fetchall())
except sqlite3.OperationalError:
self.conn = sqlite3.connect(self.file)
self.cur = self.conn.cursor()
self.cur.execute('DROP TABLE IF EXISTS LOGIN;')
self.cur.execute('''CREATE TABLE LOGIN
(WEBSITE TEXT NOT NULL,
USER TEXT NOT NULL,
PASS BLOB NOT NULL); ''')
def closeConn(self):
if self.conn is not None:
self.conn.close()
#Database access and modification functions using prepared statements from sqlite
##########################################################################
def newCred(self,site,login,encrypted_password):
self.cur.execute('INSERT INTO LOGIN VALUES(?,?,?)',[site,login,encrypted_password])
self.conn.commit()
print("added new cred")
def delCred(self,site):
self.cur.execute('DELETE FROM LOGIN WHERE website = ?',[site,])
self.conn.commit()
def getCred(self,site):
self.cur.execute('SELECT * FROM LOGIN WHERE website = ?',[site,])
return tuple(self.cur.fetchone())
#q
def getFilteredList(self, search):
self.cur.execute('SELECT * FROM LOGIN WHERE website like ?',['%'+search+'%',])
return self.cur.fetchall()
#SELECT name FROM sqlite_master WHERE type='table' AND name='yourTableName';