-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbController.py
85 lines (69 loc) · 2.51 KB
/
dbController.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import sqlite3
import getFromSite
dbname = ("users.db")
conn = sqlite3.connect(dbname,isolation_level=None)
cursor = conn.cursor()
def dbinit():
sql = """CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY AUTOINCREMENT, name, rate, smashmate_id,discord_id)"""
cursor.execute(sql)
def dbinsertNameAndSmashmateId(name,smashmate_id):
sql="""INSERT INTO users(name,smashmate_id) VALUES(?,?)"""
data=((name,smashmate_id))
cursor.execute(sql,data)
def dbPrintall():
sql="""SELECT * FROM users"""
cursor.execute(sql)
sql='select * from users order by rate;'
cursor.execute(sql)
return cursor.fetchall()
def dbdelete(discord_id):
cursor.execute("delete from users where discord_id=?",(discord_id,))
def dbdeleteBySmashmate_id(smashmate_id):
cursor.execute("delete from users where smashmate_id=?",(smashmate_id,))
def dbMakeUser(name,discord_id):
if dbCheckUserExists(discord_id):
return dbCheckUserExists(discord_id)
else:
sql="""INSERT INTO users(name, discord_id) VALUES (?,?) """
data=((name,discord_id))
cursor.execute(sql,data)
def dbMakeUserWithSmashmate_id(name,smashmate_id):
if dbCheckUserExists(smashmate_id):
return dbCheckUserExists(smashmate_id)
else:
sql="""INSERT INTO users(name, smashmate_id) VALUES (?,?) """
data=((name,smashmate_id))
cursor.execute(sql,data)
def dbNameUpdate(name,discord_id):
sql='UPDATE users SET name = ? WHERE discord_id = ?;'
data=(name,discord_id)
cursor.execute(sql,data)
def dbCheckUserExists(discord_id):
sql = 'select * from users where discord_id = ? '
data = (discord_id, )
if cursor.execute(sql, data).fetchall():
return cursor.execute(sql, data).fetchall()
else:
return False
def dbUpdaterate(discord_id,rate):
sql = 'UPDATE users SET rate = ? WHERE discord_id = ?;'
data=(rate,discord_id)
cursor.execute(sql,data)
def dbUpdaterateBysmashmate_id(smashmate_id,rate):
sql = 'UPDATE users SET rate = ? WHERE smashmate_id = ?;'
data=(rate,smashmate_id)
cursor.execute(sql,data)
def dbSetSmashmate_id(discord_id,smashmate_id):
sql = 'UPDATE users SET smashmate_id = ? WHERE discord_id = ?;'
data=(smashmate_id,discord_id)
cursor.execute(sql,data)
def dbReadSmashmateID(discord_id):
sql = 'select smashmate_id from users where discord_id = ? '
data = (discord_id, )
return cursor.execute(sql, data).fetchall()[0][0]
def dbReadname(discord_id):
sql = 'select name from users where discord_id = ? '
data = (discord_id, )
return cursor.execute(sql, data).fetchall()[0][0]
def dbclean():
cursor.execute("delete from users where smashmate_id IS NULL")