Made database connections more efficient

pull/8/head
sgoudham 4 years ago
parent 9b4eeaec4c
commit fe98977695

@ -319,12 +319,11 @@ async def on_member_join(member):
# Define the insert statement that will insert the user's information # Define the insert statement that will insert the user's information
insert_query = """INSERT INTO members (guildID, discordUser, discordID) VALUES (?, ?, ?)""" insert_query = """INSERT INTO members (guildID, discordUser, discordID) VALUES (?, ?, ?)"""
vals = member.guild.id, name, member.id, vals = member.guild.id, name, member.id,
cursor = conn.cursor() with closing(conn.cursor()) as cursor:
# Execute the SQL Query
# Execute the SQL Query cursor.execute(insert_query, vals)
cursor.execute(insert_query, vals) conn.commit()
conn.commit() print(cursor.rowcount, "Record inserted successfully into Members")
print(cursor.rowcount, "Record inserted successfully into Members")
except mariadb.Error as ex: except mariadb.Error as ex:
print("Parameterized Query Failed: {}".format(ex)) print("Parameterized Query Failed: {}".format(ex))
@ -377,12 +376,11 @@ async def on_member_remove(member):
# Delete the record of the member as they leave the server # Delete the record of the member as they leave the server
delete_query = """DELETE FROM members WHERE discordID = (?) AND guildID = (?)""" delete_query = """DELETE FROM members WHERE discordID = (?) AND guildID = (?)"""
vals = member.id, guild.id, vals = member.id, guild.id,
cursor = conn.cursor() with closing(conn.cursor()) as cursor:
# Execute the SQL Query
# Execute the SQL Query cursor.execute(delete_query, vals)
cursor.execute(delete_query, vals) conn.commit()
conn.commit() print(cursor.rowcount, "Record deleted successfully from Members")
print(cursor.rowcount, "Record deleted successfully from Members")
except mariadb.Error as ex: except mariadb.Error as ex:
print("Parameterized Query Failed: {}".format(ex)) print("Parameterized Query Failed: {}".format(ex))

Loading…
Cancel
Save