-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAluno.py
More file actions
87 lines (71 loc) · 2.26 KB
/
Copy pathAluno.py
File metadata and controls
87 lines (71 loc) · 2.26 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
75
76
77
78
79
80
81
82
83
84
85
86
import sqlite3
class Aluno:
def __init__(self):
self.nome = ""
self.cpf = ""
def get_nome(self):
return self.nome
def set_nome(self, novo_nome):
self.nome = novo_nome
def get_cpf(self):
return self.cpf
def set_cpf(self, novo_cpf):
self.cpf = novo_cpf
def adicionar_ao_banco(self):
conexao = sqlite3.connect("database.db")
cursor = conexao.cursor()
try:
cursor.execute("""
INSERT INTO alunos(nome, cpf) VALUES (?, ?)
""", (self.nome, self.cpf))
except Exception as erro:
print(erro)
cursor.close()
conexao.close()
return erro
cursor.close()
conexao.commit()
conexao.close()
return True
def apagar_do_banco(self):
conexao = sqlite3.connect("database.db")
cursor = conexao.cursor()
try:
cursor.execute("""
DELETE FROM alunos WHERE cpf = ?
""", (self.cpf,))
except Exception as erro:
print(erro)
cursor.close()
conexao.close()
return erro
cursor.close()
conexao.commit()
conexao.close()
def atualizar_banco(self, novo_nome, novo_cpf):
conexao = sqlite3.connect("database.db")
cursor = conexao.cursor()
try:
cursor.execute("""
UPDATE alunos SET cpf = "{}", nome = "{}" WHERE cpf = "{}"
""".format(novo_cpf, novo_nome, self.cpf))
except Exception as erro:
print(erro)
cursor.close()
conexao.close()
return erro
cursor.close()
conexao.commit()
conexao.close
def listar_todos(self):
conexao = sqlite3.connect("database.db")
cursor = conexao.cursor()
cursor.execute("SELECT * FROM alunos")
lista_alunos = cursor.fetchall()
print("\n--- Lista de todos os Alunos registrados ---")
print("=" * 50)
for nome_cpf in lista_alunos:
print("Nome: {} CPF: {}".format(nome_cpf[1], nome_cpf[2]))
cursor.close()
conexao.commit()
conexao.close()