Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def connect_to_db(db_name):
- cnx = connect(user = "root", password="", host = "localhost", database = db_name)
- cnx.autocommit = True
- return cnx
- sql_create_table_cinema = """
- CREATE TABLE cinema (
- id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
- name CHAR(50),
- adress VARCHAR(255),
- """
- sql_create_table_schedule = """
- CREATE TABLE schedule (
- id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
- date DATE,
- """
- sql_create_table_show = """
- CREATE TABLE show(
- id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
- time TIME,
- """
- sql_create_relation_schedule_show = """
- CREATE TABLE schedule_show(
- id INT PRIMARY KEY AUTO_INCREMENT,
- schedule_id INT,
- show_id INT,
- FOREIGN KEY(schedule_id) REFERENCES schedule(id),
- FOREIGN KEY(show_id) REFERENCES show(id));
- """
- sql_create_relation_cinema_show = """
- CREATE TABLE cinema_show(
- id INT PRIMARY KEY AUTO_INCREMENT,
- cinema_id INT,
- show_id INT,
- FOREIGN KEY(cinema_id) REFERENCES cinema(id),
- FOREIGN KEY(show_id) REFERENCES show(id));
- """
- try:
- cnx = connect_to_db("project_x")
- cursor = cnx.cursor()
- #cursor.execute(sql_create_table_cinema)
- print(cursor.lastrowid)
- #cursor.execute(sql_create_table_schedule)
- print(cursor.lastrowid)
- #cursor.execute(sql_create_table_show)
- print(cursor.lastrowid)
- #cursor.execute(sql_create_relation_schedule_show )
- print(cursor.lastrowid)
- #cursor.execute(sql_create_relation_cinema_show)
- print(cursor.lastrowid)
- cursor.close()
- cnx.close()
- except ProgrammingError as e:
- print(e)
- except InterfaceError as e:
- print(e)
Add Comment
Please, Sign In to add comment