-
Notifications
You must be signed in to change notification settings - Fork 0
/
conn.py
87 lines (73 loc) · 2.6 KB
/
conn.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
84
85
86
87
import sqlite3
# classe para a conexão
class Conn:
def __init__(self) -> None:
self.criarTabelas()
# criar a conexão
def criarConn(self):
try:
self.conn = sqlite3.connect('banco_de_dados.db')
print('Conectado ao banco de dados!')
except Exception as e:
print(e)
# criar as tabelas
def criarTabelas(self):
try:
self.criarConn()
self.cursor = self.conn.cursor()
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS disciplinas (
id INTEGER PRIMARY KEY,
nome VARCHAR NOT NULL,
ch INTEGER NOT NULL,
area VARCHAR NOT NULL
);
''')
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS professores (
id INTEGER PRIMARY KEY,
nome VARCHAR NOT NULL,
cpf INTEGER NOT NULL,
idade INTEGER NOT NULL,
cod_disc INTEGER NOT NULL,
FOREIGN KEY(cod_disc) REFERENCES disciplinas(id)
);
''')
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS turmas (
id INTEGER PRIMARY KEY,
turma VARCHAR NOT NULL
);
''')
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS estudantes (
id INTEGER PRIMARY KEY,
nome VARCHAR NOT NULL,
idade VARCHAR NOT NULL,
matricula VARCHAR NOT NULL,
cod_turma INTEGER,
FOREIGN KEY (cod_turma) REFERENCES turmas(id)
);
''')
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS notas (
id INTEGER PRIMARY KEY,
nota DECIMAL NOT NULL,
bimestre VARCHAR NOT NULL,
cod_aluno INTEGER,
FOREIGN KEY (cod_aluno)REFERENCES estudantes(id)
);
''')
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS eventos (
id INTEGER PRIMARY KEY,
assunto VARCHAR NOT NULL,
local VARCHAR NOT NULL,
data VARCHAR NOT NULL,
hora VARCHAR NOT NULL
);
''')
self.conn.commit()
except Exception as e:
print('erro: ', e)
Conn()