Guest User

Untitled

a guest
Nov 1st, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. def connect_to_db(db_name):
  2. cnx = connect(user = "root", password="", host = "localhost", database = db_name)
  3. cnx.autocommit = True
  4. return cnx
  5.  
  6.  
  7. sql_create_table_cinema = """
  8. CREATE TABLE cinema (
  9. id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  10. name CHAR(50),
  11. adress VARCHAR(255),
  12. """
  13. sql_create_table_schedule = """
  14. CREATE TABLE schedule (
  15. id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  16. date DATE,
  17.  
  18. """
  19. sql_create_table_show = """
  20. CREATE TABLE show(
  21. id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  22. time TIME,
  23. """
  24.  
  25. sql_create_relation_schedule_show = """
  26. CREATE TABLE schedule_show(
  27. id INT PRIMARY KEY AUTO_INCREMENT,
  28. schedule_id INT,
  29. show_id INT,
  30. FOREIGN KEY(schedule_id) REFERENCES schedule(id),
  31. FOREIGN KEY(show_id) REFERENCES show(id));
  32. """
  33. sql_create_relation_cinema_show = """
  34. CREATE TABLE cinema_show(
  35. id INT PRIMARY KEY AUTO_INCREMENT,
  36. cinema_id INT,
  37. show_id INT,
  38. FOREIGN KEY(cinema_id) REFERENCES cinema(id),
  39. FOREIGN KEY(show_id) REFERENCES show(id));
  40. """
  41. try:
  42. cnx = connect_to_db("project_x")
  43. cursor = cnx.cursor()
  44. #cursor.execute(sql_create_table_cinema)
  45. print(cursor.lastrowid)
  46. #cursor.execute(sql_create_table_schedule)
  47. print(cursor.lastrowid)
  48. #cursor.execute(sql_create_table_show)
  49. print(cursor.lastrowid)
  50. #cursor.execute(sql_create_relation_schedule_show )
  51. print(cursor.lastrowid)
  52. #cursor.execute(sql_create_relation_cinema_show)
  53. print(cursor.lastrowid)
  54.  
  55. cursor.close()
  56. cnx.close()
  57. except ProgrammingError as e:
  58. print(e)
  59. except InterfaceError as e:
  60. print(e)
Add Comment
Please, Sign In to add comment