-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
80 lines (56 loc) · 1.81 KB
/
main.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
import mysql.connector
# create the connection between python and the database
connection = mysql.connector.connect(
host='localhost',
user='root',
password='root',
database='estante',
)
# execute the connection
cursor = connection.cursor()
editora = '(idEditora, nome)'
livro = '(idLivro, idEditora, titulo, autor, ano)'
def create(table_, content_):
sql_command = f'INSERT INTO {table_} VALUES ({content_});'
cursor.execute(sql_command)
connection.commit()
def read(table_):
sql_command = f'SELECT * FROM {table_};'
cursor.execute(sql_command)
result = cursor.fetchall()
print(result)
def update(table_, value_, where_):
sql_command = f'UPDATE {table_} SET {value_} WHERE {where_};'
cursor.execute(sql_command)
connection.commit()
def delete(table_, where_):
sql_command = f'DELETE FROM {table_} WHERE {where_};'
cursor.execute(sql_command)
connection.commit()
doIt = input('DIGITE O NUMERO DE SUA ESCOLHA: \n 1 - Criar\n 2 - Ler\n 3 - Atualizar\n 4 - Apagar\n')
if doIt == '1':
table = input('EM QUAL TABELA?')
table.lower()
content = input('DIGITE O CONTEUDO: ')
if table == 'editora':
table = table + ' ' + editora
create(table, content)
elif table == 'livro':
table = table + ' ' + livro
elif doIt == '2':
table = input('EM QUAL TABELA?')
table.lower()
read(table)
elif doIt == '3':
table = input('EM QUAL TABELA?')
table.lower()
value = input('QUAL O NOVO VALOR?')
where = input('QUAL A CONDIÇAO? ')
update(table, value, where)
elif doIt == '4':
table = input('EM QUAL TABELA?')
table.lower()
where = input('QUAL A CONDIÇAO? ')
delete(table, where)
cursor.close()
connection.close()