-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdatabase.py
61 lines (49 loc) · 1.98 KB
/
database.py
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
56
57
58
59
60
61
import sqlite3
from config import databaseName
class TicketData():
def connect():
con = sqlite3.connect(f"./{databaseName}")
return con
def cursor(connection):
cur = connection.cursor()
return cur
def createlayout(connection, cursor):
cursor.execute("CREATE TABLE TicketData(ChannelID, AuthorID, Claimed, TimeCreated, Type, Status, MessageID)")
connection.commit()
TicketData.verifylayout(cursor)
def verifylayout(cursor):
res = cursor.execute("SELECT name FROM sqlite_master WHERE name='TicketData'")
if res.fetchone() is None:
return False
else:
return True
def add(connection, cursor, ChannelID, AuthorID, TimeCreated, Type, Status, MessageID):
cursor.execute(f"""
INSERT INTO TicketData VALUES
('{ChannelID}', '{AuthorID}', 'No', '{TimeCreated}', '{Type}', '{Status}', '{MessageID}')
""")
connection.commit()
def getall(cursor, list):
for rows in cursor.execute("SELECT * FROM TicketData ORDER BY ChannelID"):
list.append(rows)
return list
def find(cursor, ChannelID):
for row in cursor.execute("SELECT * FROM TicketData ORDER BY ChannelID"):
if row[0] == f"{ChannelID}":
return row
else:
pass
return None
def edit(connection, cursor, row, Claimed, Status):
TicketData.delete(connection, cursor, row[0])
cursor.execute(f"INSERT INTO TicketData VALUES ('{row[0]}', '{row[1]}', '{Claimed}', '{row[3]}', '{row[4]}', '{Status}', '{row[6]}')")
connection.commit()
def delete(connection, cursor, ChannelID):
try:
sql_update_query = ("""DELETE from TicketData where ChannelID = ?""")
cursor.execute(sql_update_query, (str(ChannelID),))
connection.commit()
except Exception as e:
print(e)
def close(connection):
connection.close()