def execute_insert_party_data(cursor, party_id, party_name): insert_command_string = f"INSERT INTO {db_name}.Party (partyID, partyName) VALUES (\"{party_id}\",\"{party_name}\")" print(f"party insert command string") print(insert_command_string) #cursor.execute(insert_command_string) db_agent.interact(insert_command_string)
def execute_insert_new_bill_into_bills_table(conn, cursor, bill): sessions_string = get_sessions_string(bill.sessions) summary_sanitised = bill.summary.replace("\"", "") insertion_command_string \ = f"INSERT INTO {db_name}.Bills (titleStripped, billOrAct, shortDesc, sessions, link) " \ f"VALUES (\"{bill.title_stripped}\",\"{bill.title_postfix}\",\"{summary_sanitised}\",\"{sessions_string}\",\"{bill.url}\")" #cursor.execute(insertion_command_string) db_agent.interact(insertion_command_string)
def add_user_to_database(user: core.User) -> None: """ Add the given User to the database. :param user: User object :return: None """ if not user: # Ignore None return # The SQL statement to add the user into the Users table: statement = f"INSERT INTO Users (email,password,postcode,sessionToken,notificationToken) VALUES ('{user.email}','" \ f"{user.password_hash}','{user.postcode}','{user.session_token}','{user.notification_token}');" database.interact(statement) # Carry out the SQL statement return
def execute_insert_mp_data_in_db(conn, cursor, first_name, second_name, constituency, member_id, party_id, active): if active == True: current = 1 else: current = 0 insert_command_string = f"INSERT INTO MP (mpID, firstName, lastName, partyID, area, current) VALUES (\"{member_id}\",\"{first_name}\",\"{second_name}\",{party_id},\"{constituency}\",\"{current}\")" print(f"mp insert command string") print(insert_command_string) #cursor.execute(insert_command_string) db_agent.interact(insert_command_string)
def execute_insert_new_vote_into_mpvotes_table(cursor, division_title, stage, bill_id, mp_id, aye=True): if aye == True: positive = 1 else: positive = 0 insert_command_string = f"INSERT INTO {db_name}.MPVotes (positive, billID, mpID, stage, title)" \ f"VALUES (\"{positive}\",\"{bill_id}\",\"{mp_id}\",\"{stage}\",\"{division_title}\")" #print(f"insert_command_string {insert_command_string}") #cursor.execute(insert_command_string) db_agent.interact(insert_command_string)
def execute_update_mp_data_in_db(cursor, conn, first_name, second_name, email, constituency, member_id, party_id, active): if active == True: current = 1 else: current = 0 update_command_string = f"UPDATE {db_name}.MP " \ f"SET mpID = \"{member_id}\", " \ f"firstName = \"{first_name}\", " \ f"lastName = \"{second_name}\", " \ f"email = \"{email}\", " \ f"partyID = {party_id}, " \ f"area = \"{constituency}\", " \ f"current = {current} " \ f"WHERE mpID = {member_id}" print(f"mp update command string") print(update_command_string) #cursor.execute(update_command_string) db_agent.interact(update_command_string)
def execute_update_bill(conn, cursor, bill): sessions_string = get_sessions_string(bill.sessions) update_command_string = f"UPDATE {db_name}.Bills " \ f"SET " \ f"billOrAct = \"{bill.title_postfix}\", " \ f"shortDesc = \"{bill.summary}\", " \ f"sessions = \"{sessions_string}\", " \ f"link = \"{bill.url}\" " \ f"WHERE titleStripped = \"{bill.title_stripped}\"" print(f"update command string {update_command_string}") #cursor.execute(update_command_string) cursor = db_agent.interact(update_command_string)
def db_testing(): database.interact("INSERT INTO Users (email,password,postcode,norificationToken,sessionToken) VALUES ('*****@*****.**', 'johncenalover2', 'BA23PZ', 'ExponentPushToken[dTC1ViHeJ36_SqB7MPj6B7]', 'Ga70JuPC');") return database.select("SELECT * FROM Users;")
def clear_table(conn, cursor, table_name): #cursor.execute(f"DELETE FROM {db_name}.{table_name}") #cursor.execute(f"ALTER TABLE {db_name}.{table_name} AUTO_INCREMENT = 1") #conn.commit() db_agent.interact(f"DELETE FROM {db_name}.{table_name}") db_agent.interact(f"ALTER TABLE {db_name}.{table_name} AUTO_INCREMENT = 1")
def execute_update_party_data(cursor, party_id, party_name): update_command_string = f"UPDATE {db_name}.Party SET partyName = \"{party_name}\" WHERE partyID = {party_id}" #cursor.execute(update_command_string) db_agent.interact(update_command_string)