Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. import sqlite3
  2. from Employee import Employee
  3.  
  4.  
  5.  
  6. def create_employee_table():
  7. connection = sqlite3.connect("employee.db")
  8.  
  9. connection_cursor = connection.cursor()
  10.  
  11. connection_cursor.execute(""" CREATE TABLE IF NOT EXISTS employee (
  12. id integer PRIMARY KEY,
  13. first_name text,
  14. last_name text,
  15. pay_roll integer
  16. )""")
  17.  
  18. connection.commit()
  19.  
  20. connection.close()
  21.  
  22.  
  23. create_employee_table()
  24.  
  25.  
  26. def create_employee():
  27. connection = sqlite3.connect("employee.db")
  28.  
  29. connection_cursor = connection.cursor()
  30.  
  31. connection_cursor.execute(""" INSERT INTO employee (first_name, last_name, pay_roll)
  32. VALUES ('Vardenis', 'Pavardenis', 300)""")
  33.  
  34. connection.commit()
  35.  
  36. connection.close()
  37. create_employee()
  38.  
  39.  
  40. def get_employee():
  41. connection = sqlite3.connect("employee.db")
  42.  
  43. connection_cursor = connection.cursor()
  44. connection_cursor.execute(""" SELECT * FROM employee """)
  45. connection.commit()
  46.  
  47. for row in connection_cursor.execute(""" SELECT * FROM employee """):
  48. print(row)
  49.  
  50. connection.close()
  51.  
  52.  
  53. # create_employee_table()
  54. get_employee()
  55. def update_employee():
  56. try:
  57. connection = sqlite3.connect("employee.db")
  58.  
  59. connection_cursor = connection.cursor()
  60.  
  61. connection_cursor.execute("""UPDATE employee SET first_name = "Petras" WHERE first_name = "Vardenis" """)
  62.  
  63. connection.commit()
  64. print(connection_cursor().fetchall())
  65.  
  66. connection.close()
  67. except:
  68. print(sqlite3.Error)
  69. finally:
  70. connection.close()
  71.  
  72. def delete_employee():
  73. connection = sqlite3.connect("employee.db")
  74.  
  75. connection_cursor = connection.cursor()
  76.  
  77. connection_cursor.execute(""" DELETE FROM employee WHERE last_name = "Vardenis" """)
  78.  
  79. connection.commit()
  80.  
  81. connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement