def update_char(event, data): sql = """ UPDATE characters SET char_name = %s, lvl = %s, str = %s, dex = %s, con = %s, intel = %s, wis = %s, cha = %s, armor_class = %s, caster = %s, updated_by = %s, updated_date = SYSDATE() WHERE char_id = %s """ params = (data.get("char_name", ""), data.get("lvl", ""), data.get("str", ""), data.get("dex", ""), data.get("con", ""), data.get("intel", ""), data.get("wis", ""), data.get("cha", ""), data.get("armor_class", ""), (1 if str(data.get("caster", "")).lower() == "true" else 0), mysql_connector.get_username(event), data.get("char_id", "")) mysql_connector.execute_no_return(sql, params)
def delete_class_trait(trait_id): sql = """ DELETE FROM class_traits WHERE trait_id = %s """ params = trait_id mysql_connector.execute_no_return(sql, params)
def create_invite(data): sql = """ INSERT IGNORE INTO campaign_invites ( camp_id, user, accepted, created_by, created_date, updated_by, updated_date ) VALUES ( %s, %s, 1, %s, SYSDATE(), %s, SYSDATE()); """ params = (data.get("camp_id", ""), data.get("user", ""), mysql_connector.get_username(ev), mysql_connector.get_username(ev)) mysql_connector.execute_no_return(sql, params)
def delete_char(char_id): sql = """ DELETE FROM characters WHERE char_id = %s """ params = char_id mysql_connector.execute_no_return(sql, params)
def delete_campaign(camp_id): sql = """ DELETE FROM campaigns WHERE camp_id = %s """ params = camp_id mysql_connector.execute_no_return(sql, params)
def create_class_trait(event, data): sql = """ INSERT INTO class_traits ( class_id, trait_name, trait_desc, char_level, created_by, created_date, updated_by, updated_date ) VALUES ( %s, %s, %s, %s, %s, SYSDATE(), %s, SYSDATE()); """ params = (data.get("class_id", ""), data.get("trait_name", ""), data.get("trait_desc", ""), data.get("char_level", ""), mysql_connector.get_username(event), mysql_connector.get_username(event)) mysql_connector.execute_no_return(sql, params)
def delete_camp_chars(camp_id): sql = """ DELETE FROM campaign_chars WHERE camp_id = %s and created_by = %s """ params = (camp_id, mysql_connector.get_username(ev)) mysql_connector.execute_no_return(sql, params)
def create_class(event, data): sql = """ INSERT INTO classes ( class_name, hit_die, str, dex, con, intel, wis, cha, caster, parent_id, created_by, created_date, updated_by, updated_date ) VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, SYSDATE(), %s, SYSDATE()); """ params = (data.get("class_name", ""), data.get("hit_die", ""), (1 if str(data.get("str", "")).lower() == "true" else 0), (1 if str(data.get("dex", "")).lower() == "true" else 0), (1 if str(data.get("con", "")).lower() == "true" else 0), (1 if str(data.get("intel", "")).lower() == "true" else 0), (1 if str(data.get("wis", "")).lower() == "true" else 0), (1 if str(data.get("cha", "")).lower() == "true" else 0), (1 if str(data.get("caster", "")).lower() == "true" else 0), data.get("parent_id", ""), mysql_connector.get_username(event), mysql_connector.get_username(event)) mysql_connector.execute_no_return(sql, params) class_id = mysql_connector.get_last_insert_id() for sub in data.get("subclasses", list()): sub["parent_id"] = class_id create_class(event, sub) for trait in data.get("class_traits", list()): trait["class_id"] = class_id create_class_trait(event, trait) return class_id
def delete_class(class_id): sql = """ DELETE FROM classes WHERE 1=1 """ params = class_id sqlSub = sql + """ and parent_id = %s""" mysql_connector.execute_no_return(sqlSub, params) sqlclass = sql + """ and class_id = %s""" mysql_connector.execute_no_return(sqlclass, params)
def delete_race(race_id): sql = """ DELETE FROM races WHERE 1=1 """ params = race_id sqlSub = sql + """ and parent_id = %s""" mysql_connector.execute_no_return(sqlSub, params) sqlRace = sql + """ and race_id = %s""" mysql_connector.execute_no_return(sqlRace, params)
def update_campaign(data): sql = """ UPDATE campaigns SET camp_name = %s, updated_by = %s, updated_date = SYSDATE() WHERE camp_id = %s """ params = (data.get("camp_name", ""), mysql_connector.get_username(ev), data.get("camp_id", "")) mysql_connector.execute_no_return(sql, params)
def create_char(event, data): sql = """ INSERT INTO characters ( class_id, race_id, background_id, char_name, lvl, str, dex, con, intel, wis, cha, armor_class, caster, created_by, created_date, updated_by, updated_date ) VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, SYSDATE(), %s, SYSDATE()); """ params = (data.get("class_id", ""), data.get("race_id", ""), data.get("background_id", ""), data.get("char_name", ""), data.get("lvl", ""), data.get("str", ""), data.get("dex", ""), data.get("con", ""), data.get("intel", ""), data.get("wis", ""), data.get("cha", ""), data.get("armor_class", ""), (1 if str(data.get("caster", "")).lower() == "true" else 0), mysql_connector.get_username(event), mysql_connector.get_username(event)) mysql_connector.execute_no_return(sql, params) char_id = mysql_connector.get_last_insert_id() return char_id
def update_invite(data): sql = """ UPDATE campaign_invites SET accepted = 1, updated_by = %s, updated_date = SYSDATE() WHERE camp_id = %s and user = %s """ params = (mysql_connector.get_username(ev), data.get("camp_id", ""), mysql_connector.get_username(ev)) mysql_connector.execute_no_return(sql, params)
def create_race(event, data): sql = """ INSERT INTO races ( race_name, str, dex, con, intel, wis, cha, speed, parent_id, created_by, created_date, updated_by, updated_date ) VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, SYSDATE(), %s, SYSDATE()); """ params = (data.get("race_name", ""), data.get("str", ""), data.get("dex", ""), data.get("con", ""), data.get("intel", ""), data.get("wis", ""), data.get("cha", ""), data.get("speed", ""), data.get("parent_id", ""), mysql_connector.get_username(event), mysql_connector.get_username(event)) mysql_connector.execute_no_return(sql, params) race_id = mysql_connector.get_last_insert_id() for sub in data.get("subraces", list()): sub["parent_id"] = race_id create_race(event, sub) for trait in data.get("race_traits", list()): trait["race_id"] = race_id create_race_trait(event, trait) return race_id
def update_class_trait(event, data): sql = """ UPDATE class_traits SET trait_name = %s, trait_desc = %s, char_level = %s, updated_by = %s, updated_date = SYSDATE() WHERE trait_id = %s """ params = (data.get("trait_name", ""), data.get("trait_desc", ""), data.get("char_level", ""), mysql_connector.get_username(event), data.get("trait_id", "")) mysql_connector.execute_no_return(sql, params)
def update_class(event, data): sql = """ UPDATE classes SET class_name = %s, hit_die = %s, str = %s, dex = %s, con = %s, intel = %s, wis = %s, cha = %s, caster = %s, updated_by = %s, updated_date = SYSDATE() WHERE class_id = %s """ params = (data.get("class_name", ""), data.get("hit_die", ""), (1 if str(data.get("str", "")).lower() == "true" else 0), (1 if str(data.get("dex", "")).lower() == "true" else 0), (1 if str(data.get("con", "")).lower() == "true" else 0), (1 if str(data.get("intel", "")).lower() == "true" else 0), (1 if str(data.get("wis", "")).lower() == "true" else 0), (1 if str(data.get("cha", "")).lower() == "true" else 0), (1 if str(data.get("caster", "")).lower() == "true" else 0), mysql_connector.get_username(event), data.get("class_id", "")) mysql_connector.execute_no_return(sql, params) for sub in data.get("subclasses", list()): if sub.get("delete", False) == True: delete_class(sub["class_id"]) elif sub.get("class_id", None) != None: sub["parent_id"] = data["class_id"] update_class(event, sub) else: sub["parent_id"] = data["class_id"] create_class(event, sub) for trait in data.get("class_traits", list()): if trait.get("delete", False) == True: delete_class_trait(trait["trait_id"]) elif trait.get("trait_id", None) != None: trait["class_id"] = data["class_id"] update_class_trait(event, trait) else: trait["class_id"] = data["class_id"] create_class_trait(event, trait)
def update_race(event, data): sql = """ UPDATE races SET race_name = %s, str = %s, dex = %s, con = %s, intel = %s, wis = %s, cha = %s, speed = %s, updated_by = %s, updated_date = SYSDATE() WHERE race_id = %s """ params = (data.get("race_name", ""), data.get("str", ""), data.get("dex", ""), data.get("con", ""), data.get("intel", ""), data.get("wis", ""), data.get("cha", ""), data.get("speed", ""), mysql_connector.get_username(event), data.get("race_id", "")) mysql_connector.execute_no_return(sql, params) for sub in data.get("subraces", list()): if sub.get("delete", False) == True: delete_race(sub["race_id"]) elif sub.get("race_id", None) != None: sub["parent_id"] = data["race_id"] update_race(event, sub) else: sub["parent_id"] = data["race_id"] create_race(event, sub) for trait in data.get("race_traits", list()): if trait.get("delete", False) == True: delete_race_trait(trait["trait_id"]) elif trait.get("trait_id", None) != None: trait["race_id"] = data["race_id"] update_race_trait(event, trait) else: trait["race_id"] = data["race_id"] create_race_trait(event, trait)
def create_campaign(data): sql = """ INSERT INTO campaigns ( camp_name, created_by, created_date, updated_by, updated_date ) VALUES ( %s, %s, SYSDATE(), %s, SYSDATE()); """ params = (data.get("camp_name", ""), mysql_connector.get_username(ev), mysql_connector.get_username(ev)) mysql_connector.execute_no_return(sql, params) camp_id = mysql_connector.get_last_insert_id() return camp_id