-
Notifications
You must be signed in to change notification settings - Fork 0
/
Disciplina.py
83 lines (71 loc) · 2.33 KB
/
Disciplina.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
import sqlite3
class Disciplina:
def __init__(self):
self.nome = ""
self.codigo = ""
def get_nome(self):
return self.nome
def set_nome(self, novo_nome):
self.nome = novo_nome
def get_codigo(self):
return self.codigo
def set_codigo(self, novo_codigo):
self.codigo = novo_codigo
def adicionar(self):
conexao = sqlite3.connect("database.db")
cursor = conexao.cursor()
try:
cursor.execute("""
INSERT INTO disciplinas(nome, codigo) VALUES (?,?)
""", (self.nome, self.codigo))
pass
except Exception as erro:
print(erro)
cursor.close()
conexao.close()
return erro
cursor.close()
conexao.commit()
conexao.close()
def apagar(self):
conexao = sqlite3.connect("database.db")
cursor = conexao.cursor()
try:
cursor.execute("""
DELETE FROM disciplinas WHERE codigo = (?)
""", (self.codigo,))
except Exception as erro:
print(erro)
cursor.close()
conexao.colose()
return erro
cursor.close()
conexao.commit()
conexao.close()
def atualizar(self, novo_nome ,novo_codigo):
conexao = sqlite3.connect("database.db")
cursor = conexao.cursor()
try:
cursor.execute("""
UPDATE disciplinas SET codigo = "{}", nome = "{}" WHERE codigo = "{}"
""".format(novo_codigo, novo_nome, self.codigo))
except Exception as erro:
print(erro)
cursor.close()
conexao.colose()
return erro
cursor.close()
conexao.commit()
conexao.close()
def listar(self):
conexao = sqlite3.connect("database.db")
cursor = conexao.cursor()
cursor.execute("SELECT * FROM disciplinas")
Lista_disciplinas = cursor.fetchall()
print("\n--- Lista com todas as disciplinas registradas ---")
print("=" *50)
for info_disciplinas in Lista_disciplinas:
print("Nome: {} Codigo: {}".format(info_disciplinas[1], info_disciplinas[2]))
cursor.close()
conexao.commit()
conexao.close()