-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-mysql.py
More file actions
63 lines (40 loc) · 1.41 KB
/
python-mysql.py
File metadata and controls
63 lines (40 loc) · 1.41 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
#Conectado a um banco de dados MySQL
import mysql.connector
cnx = mysql.connector.connect(user='root', password='Pavoni77@',
host='localhost',
database='registro')
cursor = cnx.cursor()
flag = True
print("\n")
while flag == True:
print("[1]Adicionar itens\n[2]Remover itens\n[3]Mostrar compras\n[4]Sair da Lista\n")
cmd = input("O que deseja fazer ?: ")
if cmd == "1":
lista = list()
lista.append(input("\nProduto: "))
lista.append(input("\nQuantidade: "))
lista.append(input("\nDescricao: "))
print(lista)
#Comando SQL add
comando = ("INSERT INTO COMPRAS (PRODUTO, QUANTIDADE, DESCRICAO) VALUES (%s, %s, %s)")
cursor.execute(comando, lista)
cnx.commit()
elif cmd == "2":
lista = list()
lista.append(input("\nQual produto deseja remover ?: "))
print("\n")
comando = ("DELETE FROM COMPRAS WHERE PRODUTO = %s")
cursor.execute(comando, lista)
cnx.commit()
elif cmd == "3":
cursor.execute("select * from COMPRAS")
print("\n")
for i in cursor.fetchall():
print("="*40)
print(f" Produto: {i[0]}\n Quantidade: {i[1]}\n Descricao: {i[2]}")
print("="*40)
print("\n")
elif cmd == "4":
flag = False
else:
print("\nErro\n")