-
Notifications
You must be signed in to change notification settings - Fork 1
/
sqlOperations.py
148 lines (103 loc) · 3.18 KB
/
sqlOperations.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import mysql.connector as con
import configuration as cfg
def verifyUser(name, pas):
cnx = con.connect(user=cfg.user, password=cfg.password, host=cfg.host, database=cfg.database)
cursor = cnx.cursor()
query = str("SELECT password FROM " + cfg.logintable + " where name like \'" + (name) + "\'")
cursor.execute(query)
empty = cursor.rowcount == 0
passwd = None
if(empty):
passwd = ''
else:
for n in cursor:
passwd = n[0]
if(empty):
print("empty")
if(empty or pas != passwd):
return -1
else:
query = str("SELECT role FROM " + cfg.logintable + " where name like \'" + name + "\'")
role = -1
cursor.execute(query)
for n in cursor:
role = n[0]
return role
cnx.commit()
cursor.close()
cnx.close()
def addEntry(name, string):
if(string == ''):
return False
cnx = con.connect(user=cfg.user, password=cfg.password, host=cfg.host, database=cfg.database)
cursor = cnx.cursor()
query = "INSERT INTO " + cfg.entriestable + "(creator,format) VALUES(%s,%s)"
args = (name, string)
success = True
try:
cursor.execute(query, args)
cnx.commit()
except:
success = False
finally:
cursor.close()
cnx.close()
return success
def delEntry(name, string):
if(string == ''):
return False
cnx = con.connect(user=cfg.user, password=cfg.password, host=cfg.host, database=cfg.database)
cursor = cnx.cursor()
query = "DELETE FROM " + cfg.entriestable + " WHERE creator LIKE %s AND format LIKE %s"
args = (name, string)
success = True
try:
cursor.execute(query, args)
cnx.commit()
except Exception as e:
print e
success = False
finally:
cursor.close()
cnx.close()
return success
def getStrings(name):
cnx = con.connect(user=cfg.user, password=cfg.password, host=cfg.host, database=cfg.database)
cursor = cnx.cursor()
query = str("SELECT format FROM " + cfg.entriestable + " WHERE creator LIKE \'" + name + "\'")
cursor.execute(query)
result = []
for row in cursor:
result.append(row[0])
cnx.commit()
cursor.close()
cnx.close()
return result
def getAdmins():
cnx = con.connect(user=cfg.user, password=cfg.password, host=cfg.host, database=cfg.database)
cursor = cnx.cursor()
query = str("SELECT DISTINCT name FROM " + cfg.logintable + " WHERE role LIKE '1'")
cursor.execute(query)
result = []
for row in cursor:
result.append(row[0])
cnx.commit()
cursor.close()
cnx.close()
return result
def editEntry(name, ostr, nstr):
cnx = con.connect(user=cfg.user, password=cfg.password, host=cfg.host, database=cfg.database)
cursor = cnx.cursor()
query = "UPDATE " + cfg.entriestable + " SET format=%s WHERE creator LIKE %s AND format LIKE %s"
args = (nstr, name, ostr)
success = True
try:
cursor.execute(query, args)
cnx.commit()
except Exception as e:
print e
success = False
finally:
cursor.close()
cnx.close()
return success