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
|
import pymysql
from warnings import filterwarnings
filterwarnings('ignore', category=pymysql.Warning)
class Database:
def __init__(self):
self.connection = pymysql.connect(
host='IP',
port=3306,
user='user',
password='password',
db='db'
)
try:
self.cursor = self.connection.cursor()
except Exception as e:
print("Error al conectar con la BD " + e)
raise
def __disconnect__(self):
self.connection.close()
def select_data(self):
sql = 'SELECT * FROM process'
try:
self.cursor.execute(sql)
ticker = self.cursor.fetchall()
return ticker
except Exception as e:
print("Error en función select_data " + e)
raise
finally:
self.__disconnect__()
def update_status_proces(self, status, idprocess):
sql = 'UPDATE `process` SET `status`= %s WHERE `idprocess` = %s'
values = (status, idprocess)
try:
self.cursor.execute(sql, values)
self.connection.commit()
except pymysql.IntegrityError as e:
if not e[0] == 1062:
raise
print("Oops! Fallo al insertar en la tabla process")
finally:
self.__disconnect__()
def update_proces(self, idprocess, process_name, process_pid, update_date, creation_date, status, pc):
sql = 'UPDATE `process` SET `idprocess` = %s, `process_name`= %s, `process_pid`=%s, `update_date`= %s, `creation_date`= %s, `status`= %s, `pc`= %s WHERE `idprocess` = %s'
values = (idprocess, process_name, process_pid, update_date, creation_date, status, pc, idprocess)
try:
self.cursor.execute(sql, values)
self.connection.commit()
except pymysql.IntegrityError as e:
if not e[0] == 1062:
raise
print("Oops! Fallo al insertar en la tabla process")
finally:
self.__disconnect__()
|