-
Notifications
You must be signed in to change notification settings - Fork 1
/
database.py
63 lines (58 loc) · 1.92 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
62
63
import pymysql
import os
import logging
class Suggest_database:
def __init__(self):
self.db = pymysql.connect(
host=os.environ.get("HOST"),
user=os.environ.get("USER"),
password=os.environ.get("PASSWORD"),
db= os.environ.get("DB")
)
self.cursor = self.db.cursor()
def insert_suggest(self,date,suggest):
sql = "INSERT INTO sugerencia(fecha,sugerencia) values ('"+str(date)+"','"+str(suggest)+"')"
try:
# Execute the SQL command
self.cursor.execute(sql)
# Commit your changes in the database
self.db.commit()
except:
# Rollback in case there is any error
self.db.rollback()
self.db.close()
def get_suggests(self):
sql = "SELECT * FROM sugerencia order by id desc"
try:
# Execute the SQL command
self.cursor.execute(sql)
result = self.cursor.fetchall()
return result
except:
# Rollback in case there is any error
self.db.rollback()
self.db.close()
def delete_suggest(self,id):
sql = "DELETE FROM sugerencia where id = %s" % id
try:
# Execute the SQL command
self.cursor.execute(sql)
self.db.commit()
except:
# Rollback in case there is any error
self.db.rollback()
self.db.close()
def is_user_correct(self,user,password):
sql = "SELECT * FROM usuario"
try:
# Execute the SQL command
self.cursor.execute(sql)
result = self.cursor.fetchone()
if(result[1]==user and result[2]==password):
return True
else:
return False
except:
# Rollback in case there is any error
self.db.rollback()
self.db.close()