interact with db

parent 0f2e391f
import sqlite3
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
reader = SimpleMFRC522()
con = sqlite3.connect("mydb.db")
cur = con.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS persone (
id INTEGER PRIMARY KEY,
nome TEXT NOT NULL,
cognome TEXT NOT NULL,
n_card TEXT NOT NULL UNIQUE);""")
n = input("Quale e il nome che vuoi cercare nel database? ")
database = cur.execute('SELECT n_card FROM persone WHERE nome=?;',(n,))
for row in database:
print(row)
import sqlite3
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
reader = SimpleMFRC522()
con = sqlite3.connect("mydb.db")
cur = con.cursor()
def leggi_prodotto():
try:
print("Ciao, avvicina il prodotto al ricevitore!")
id,text = reader.read()
print(id)
#print(text)
except:
pass
finally:
GPIO.cleanup()
return int(id)
n = leggi_prodotto()
database = cur.execute('SELECT n_cliente FROM prodotti WHERE n_rfid=?;',(n,))
for row in database:
xx=row[0]
print(xx)
cliente = cur.execute('SELECT * FROM persone WHERE n_card=?;',(xx,))
#for i in cliente:
print(cliente.fetchone())
\ No newline at end of file
import sqlite3
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
reader = SimpleMFRC522()
con = sqlite3.connect("mydb.db")
cur = con.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS persone (
id INTEGER PRIMARY KEY,
nome TEXT NOT NULL,
cognome TEXT NOT NULL,
n_card TEXT NOT NULL UNIQUE);""")
database = cur.execute("""SELECT * FROM persone;""")
for row in database:
print(row)
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
reader = SimpleMFRC522()
try:
print("Ciao, avvicina il tag RFID al ricevitore!")
id,text = reader.read()
print(id)
print(text)
except:
pass
finally:
GPIO.cleanup()
\ No newline at end of file
import sqlite3
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
reader = SimpleMFRC522()
con = sqlite3.connect("mydb.db")
cur = con.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS persone (
id INTEGER PRIMARY KEY,
nome TEXT NOT NULL,
cognome TEXT NOT NULL,
n_card TEXT NOT NULL UNIQUE);""")
def leggi_codice():
try:
print("Ciao, avvicina il tag RFID al ricevitore!")
id,text = reader.read()
print(id)
print(text)
except:
pass
finally:
GPIO.cleanup()
return id
n = input("Quale e il tuo nome?")
c = input("Quale e il tuo cognome?")
a = leggi_codice()
try:
b = int(a)
cur.execute("INSERT INTO persone(nome, cognome, n_card) VALUES(?, ?, ?)",(n,c,a))
print("Ciao ", n , " la tua tessera ha il numero : ", b)
con.commit()
cur.close()
except:
print("Codice non corretto")
\ No newline at end of file
import sqlite3
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
import time
reader = SimpleMFRC522()
con = sqlite3.connect("mydb.db")
cur = con.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS prodotti (
id INTEGER PRIMARY KEY,
n_rfid TEXT NOT NULL UNIQUE,
n_cliente TEXT NOT NULL);""")
def leggi_cliente():
try:
print("Ciao, avvicina il tag del cliente al ricevitore!")
id,text = reader.read()
print(id)
#print(text)
except:
pass
finally:
GPIO.cleanup()
return int(id)
def leggi_prodotto():
try:
print("Ciao, avvicina il prodotto al ricevitore!")
id,text = reader.read()
print(id)
#print(text)
except:
pass
finally:
GPIO.cleanup()
return int(id)
#n = input("Quale e il tuo nome?")
#c = input("Quale e il tuo cognome?")
codice_cliente = leggi_cliente()
time.sleep(2)
codice_prodotto = leggi_prodotto()
try:
cur.execute("INSERT INTO prodotti(n_rfid, n_cliente) VALUES(?, ?)",(codice_prodotto,codice_cliente))
#print("ciao")
print("Ciao ", codice_cliente , " abbiamo registrato il prodotto numero : ", codice_prodotto)
con.commit()
cur.close()
except:
print("Codice non corretto")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment