-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.py
More file actions
74 lines (66 loc) · 2.32 KB
/
Database.py
File metadata and controls
74 lines (66 loc) · 2.32 KB
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
import mysql.connector as mysql
from mysql.connector import Error
def CreateConnection():
connection = mysql.connect(host='localhost',
database='sgt_consulta_old_certo21_03_2020',
user='root',
password='')
return connection
def GetCodItem():
connection = CreateConnection()
query = ("""select cod_item from itens i
left join assuntos a on a.cod_assunto = i.cod_item
where i.tipo_item = 'A' """)
cursor = connection.cursor(buffered=True)
cursor.execute(query)
result = cursor.fetchall()
connection.commit()
connection.close()
return result
def GetCodItemPai():
connection = CreateConnection()
query = ("""select cod_item_pai from itens i
left join assuntos a on a.cod_assunto = i.cod_item
where i.tipo_item = 'A' """)
cursor = connection.cursor(buffered=True)
cursor.execute(query)
result = cursor.fetchall()
connection.commit()
connection.close()
return result
def GetNome():
connection = CreateConnection()
query = ("""select nome from itens i
left join assuntos a on a.cod_assunto = i.cod_item
where i.tipo_item = 'A' """)
cursor = connection.cursor(buffered=True)
cursor.execute(query)
result = cursor.fetchall()
connection.commit()
connection.close()
return result
def GetDataSet(item):
if item == "Assuntos":
connection = CreateConnection()
query = ("""select cod_item, cod_item_pai, nome, situacao, a.glossario from itens i
left join assuntos a on a.cod_assunto = i.cod_item
where i.tipo_item = 'A'
order by cod_item_pai""")
cursor = connection.cursor(buffered=True)
cursor.execute(query)
result = cursor.fetchall()
connection.commit()
connection.close()
return result
else:
connection = CreateConnection()
query = ("""select cod_item, cod_item_pai, nome, situacao, c.glossario from itens i
left join classes c on c.cod_classe = i.cod_item
where i.tipo_item = 'C'
order by cod_item_pai""")
cursor = connection.cursor(buffered=True)
cursor.execute(query)
result = cursor.fetchall()
connection.commit()
connection.close()
return result