-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpictsql.py
90 lines (62 loc) · 1.91 KB
/
pictsql.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
86
87
88
### Manages SQL
import sqlite3, os
import threading
class SQLManager(threading.Thread):
def __init__(self):
self.path = "./data"
self.database = ""
self.table = "user"
def main(self):
if not os.path.exists(self.path):
os.makedirs("./data")
self.connection = sqlite3.connect('./data/example', check_same_thread = False)
self.con = self.connection.cursor()
def create_table(self, table):
self.con.execute(table)
def execute(self, execution):
self.con.execute(execution)
self.connection.commit()
def retrieve_data(self, execution):
self.con.execute(execution)
self.data = self.con.fetchall()
print(self.data)
def add_user(self, username, password, email):
a = """insert into {}(username,password,email)
values (?,?,?)""".format(self.table)
data = (username, password, email,)
self.con.execute(a, data)
self.connection.commit()
def check_field(self, field, value):
name = (value,)
exec_str = 'select * from {} where {}=?'.format(self.table, field)
self.con.execute(exec_str, name)
data = self.con.fetchone()
if data is None:
return False
else:
return True
def user_login(self, username, password):
data = (username, password)
exec_str = 'select * from {} where username=? and password=?'.format(self.table)
self.con.execute(exec_str, data)
a = self.con.fetchall()
if len(a) != 0:
print("True")
return True
else:
print("False")
return False
def tests():
pass
user_table = ('''CREATE TABLE IF NOT EXISTS user
(id INTEGER PRIMARY KEY AUTOINCREMENT,
username VARCHAR(25) NOT NULL,
password VARCHAR(25) NOT NULL,
rank VARCHAR(25) DEFAULT 'member' not NULL,
timeplayed INTEGER DEFAULT 0 NOT NULL,
email VARCHAR(25) NOT NULL,
score VARCHAR(25) DEFAULT '0' NOT NULL,
UNIQUE (username),
UNIQUE (email))''')
test_execution = ("""insert into user
values ('usernametest','password1',1,'[email protected]',10)""")