Commit 5a32aa0e authored by Danielvdh03's avatar Danielvdh03
Browse files

Added try catch to executing queries

parent d799778b
......@@ -159,8 +159,8 @@ class Database:
print(query) # For debugging purposes
cursor.execute(query)
results = cursor.fetchall()
results = self.execute_query(query)
print(results)
self.table_list.append(table_name) # Add to list of tables
......@@ -329,8 +329,7 @@ class Database:
return
query = self.generate_insert_query(table_name, column_names, attributes)
cursor.execute(query)
results = cursor.fetchall()
results = self.execute_query(query)
print(results)
......@@ -374,8 +373,8 @@ class Database:
if table_name in self.table_list:
cursor.execute("drop table {0}".format(table_name))
result = cursor.fetchall()
query = "drop table {0}".format(table_name)
result = self.execute_query(query)
print(result)
self.table_list.remove(table_name)
......@@ -454,7 +453,16 @@ class Database:
print(table)
return
def execute_query(self):
def execute_query(self, query):
try:
cursor.execute(query)
results = cursor.fetchall()
return results
except mysql.Error as err:
print("Something went wrong: {}".format(err))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment