Repository navigation
Expand file tree
/
Copy pathdbInterface.py
More file actions
50 lines (39 loc) · 1.72 KB
/
Copy pathdbInterface.py
File metadata and controls
50 lines (39 loc) · 1.72 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
import sqlite3
class dbInterface(object):
def __init__(self, dbFile):
self._con = sqlite3.connect(dbFile)
self._cur = self._con.cursor()
def close(self):
self._con.close()
def query(self, queryString):
self._cur.execute(queryString)
self._con.commit()
return self._cur
def addSubscriber(self, address):
cur = self.query('SELECT address FROM User WHERE address="%s"' % address)
if len(cur.fetchall()) == 0:
self.query('INSERT INTO User (isSender, isActive, address) VALUES (0, 1, "%s")' % address)
else:
self.query('UPDATE User SET isActive=1 WHERE address="%s"' % address)
def removeSubscriber(self, address):
self.query('UPDATE User SET isSender=0, isActive=0 WHERE address="%s"' % address)
def addSender(self, address):
self.addSubscriber(address)
self.query('UPDATE User SET isSender=1 WHERE address="%s"' % address)
def removeSender(self, address):
self.query('UPDATE User set isSender=0 WHERE address="%s"' % address)
def getAllSubscribers(self):
cur = self.query('SELECT address FROM User WHERE isActive=1')
return cur.fetchall()
def isSender(self, address):
cur = self.query('SELECT address FROM User WHERE isSender=1 AND address="%s"' % address)
if len(cur.fetchall()) > 0:
return True
else:
return False
def getFirstName(self, address):
cur = self.query('SELECT FirstName FROM User WHERE address="%s"' % address)
return cur.fetchall()[0][0]
def getLastName(self, address):
cur = self.query('SELECT LastName FROM User WHERE address="%s"' % address)
return cur.fetchall()[0][0]