This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql.py
60 lines (49 loc) · 1.51 KB
/
sql.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
import sqlite3
#Create the .sqlite database, and create the table
def CreateDB():
try:
with open('data/data.sqlite'):pass
except IOError:
con = sqlite3.connect('data/data.sqlite')
cur = con.cursor()
cur.execute('''CREATE TABLE Users
(discord_id text, username text, tag text)''')
con.commit()
con.close()
#Add a new user in the db table
def AddUser(id, username, tag):
status = False
con = sqlite3.connect('data/data.sqlite')
cur = con.cursor()
cur.execute('SELECT * FROM Users WHERE discord_id = '+id)
if len(cur.fetchall()) == 0:
cur.execute('''INSERT INTO Users (discord_id,username,tag)
VALUES (?,?,?)''',(id,username,tag))
con.commit()
status = True
else:
status = False
con.close()
return status
#Delete an existing user from the db table
def DelUser(id):
status = False
con = sqlite3.connect('data/data.sqlite')
cur = con.cursor()
cur.execute('SELECT * FROM Users WHERE discord_id = '+id)
if len(cur.fetchall()) == 0:
status = False
else:
cur.execute('''DELETE FROM Users WHERE discord_id = ?''', (id,))
con.commit()
status = True
con.close()
return status
#Return the list of all suscribed users
def GetUsers():
con = sqlite3.connect('data/data.sqlite')
cur = con.cursor()
cur.execute('SELECT * FROM Users ORDER BY username ASC')
list_users = cur.fetchall()
con.close()
return list_users