Advertisement
xavicano

Untitled

May 17th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. import sqlite3
  2. conn = sqlite3.connect("computer_cards.db")
  3.  
  4. def create(name, cores,cpu_speed, ram, cost):
  5.     insert_sql = "INSERT INTO computer(name, cores, cpu_speed, ram, cost) VALUES ('{}',{},{},{},{})".format(name, cores, cpu_speed, ram, cost)
  6.     conn.execute(insert_sql)
  7.     conn.commit()
  8.    
  9. def read(name):
  10.     select_sql = "SELECT * FROM computer WHERE name = '{}'".format(name)
  11.     result = conn.execute(select_sql)
  12.     return result.fetchone()
  13.    
  14.    
  15. def update(name, cores,cpu_speed, ram, cost):
  16.     select_sql = "SELECT * FROM computer WHERE name = '{}'".format(name)
  17.     insert_sql="UPDATE computer SET cores = {}, cpu_speed = {}, ram = {}, cost = {} WHERE name = '{}'"
  18.     result = conn.execute(select_sql)
  19.     conn.commit()
  20.  
  21.    
  22. def delete(name):
  23.     select_sql = "SDELETE FROM computer WHERE name = '{}'"
  24.     result = conn.execute(select_sql)
  25.     conn.commit()
  26.  
  27.  
  28. command = input("(C)reate or (R)ead a card or (U)pdate or (D)elete ")
  29.  
  30. if command == "C":
  31.     name = input("Name >")
  32.     cores = input("Cores >")
  33.     cpu_speed = input("CPU speed (GHz) >")
  34.     ram = input("RAM (MB) >")
  35.     cost = input("Cost ($) >")
  36.     create(name, cores, cpu_speed, ram, cost)
  37. elif command == "R":
  38.     name = input("Name >")
  39.     card = read(name)
  40.     print(card)  
  41. elif command == "U":
  42.     name = input("Which compter Name do you want to update? >")
  43.     cores = input("Cores >")
  44.     cpu_speed = input("CPU speed (GHz) >")
  45.     ram = input("RAM (MB) >")
  46.     cost = input("Cost ($) >")
  47.     update(name, cores, cpu_speed, ram, cost)  
  48. elif command == "D":
  49.     name = input("Which computer Name do you want ro remove>")
  50.     delete(name)
  51.  
  52.  
  53. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement