Introduced error management to prevent crashes and added prints for error reporting during runtime
This commit is contained in:
+54
-36
@@ -11,28 +11,7 @@ def buildSave(action, outputs):
|
||||
with open(f"{action.savepath}", "w") as save_file:
|
||||
json.dump(save_data, save_file)
|
||||
|
||||
print(f"Data saved by {action.name} to {action.savepath}")
|
||||
|
||||
database = sqlite3.connect("savedata/rmmanager.db")
|
||||
for key, value in save_data.items():
|
||||
database.execute("""
|
||||
CREATE TABLE IF NOT EXISTS output_test (
|
||||
dictionary TEXT PRIMARY KEY,
|
||||
value TEXT NOT NULL
|
||||
)
|
||||
""")
|
||||
|
||||
database.execute("""
|
||||
INSERT INTO output_test(dictionary, value)
|
||||
VALUES (?, ?)
|
||||
ON CONFLICT (dictionary)
|
||||
DO UPDATE SET value = excluded.value
|
||||
""", (key, value)
|
||||
)
|
||||
|
||||
database.commit()
|
||||
database.close()
|
||||
|
||||
#print(f"Data saved by {action.name} to {action.savepath}")
|
||||
return outputs
|
||||
|
||||
def loadSave(action, outputs):
|
||||
@@ -43,11 +22,12 @@ def loadSave(action, outputs):
|
||||
for load_name in action.loaddata:
|
||||
outputs[load_name] = load_data[load_name]
|
||||
|
||||
print(f"Data loaded by {action.name} from {action.savepath}")
|
||||
#print(f"Data loaded by {action.name} from {action.savepath}")
|
||||
return outputs
|
||||
|
||||
def saveRow(action, outputs, resolved):
|
||||
if hasattr(action, "saverow"):
|
||||
print("Saverow activated")
|
||||
table = action.saverow["table"]
|
||||
|
||||
columns = action.saverow["columns"]
|
||||
@@ -59,18 +39,24 @@ def saveRow(action, outputs, resolved):
|
||||
columnattr = ""
|
||||
columnattr = key + " " + value
|
||||
|
||||
print(columnattr)
|
||||
#print(columnattr)
|
||||
column_creation.append(columnattr)
|
||||
|
||||
rowitems = action.saverow["rowitems"]
|
||||
|
||||
values = []
|
||||
for item in rowitems:
|
||||
if "outputs" in item:
|
||||
value = outputs[item["outputs"]]
|
||||
elif "resolved" in item:
|
||||
value = resolved[item["resolved"]]
|
||||
|
||||
for item in rowitems:
|
||||
try:
|
||||
if "outputs" in item:
|
||||
value = outputs[item["outputs"]]
|
||||
elif "resolved" in item:
|
||||
value = resolved[item["resolved"]]
|
||||
except KeyError as error:
|
||||
print(f"The save data for {error} was not located in its respective dictionary during {action.name}")
|
||||
print("Bypassing database save")
|
||||
return False
|
||||
|
||||
values.append(value)
|
||||
|
||||
database = sqlite3.connect("savedata/rmmanager.db")
|
||||
@@ -86,14 +72,45 @@ def saveRow(action, outputs, resolved):
|
||||
column_names = ", ".join(column_list)
|
||||
placeholders = ", ".join(["?"] * len(values))
|
||||
|
||||
database.execute(
|
||||
f"INSERT INTO {table} ({column_names}) VALUES ({placeholders})",
|
||||
tuple(values)
|
||||
)
|
||||
query = f"INSERT INTO {table} ({column_names}) VALUES ({placeholders})"
|
||||
|
||||
if "onconflict" in action.saverow:
|
||||
conflict = action.saverow["onconflict"]
|
||||
|
||||
target = conflict["target"]
|
||||
columns = conflict["update"]
|
||||
preserve_null = conflict.get("preservenull", False)
|
||||
|
||||
if columns:
|
||||
if preserve_null:
|
||||
assignments = ", ".join(
|
||||
f"{column} = COALESCE(excluded.{column}, {table}.{column})"
|
||||
for column in columns
|
||||
)
|
||||
else:
|
||||
assignments = ", ".join(
|
||||
f"{column} = excluded.{column}"
|
||||
for column in columns
|
||||
)
|
||||
|
||||
query += f" ON CONFLICT({target}) DO UPDATE SET {assignments}"
|
||||
else:
|
||||
query += f" ON CONFLICT({target}) DO NOTHING"
|
||||
|
||||
database.execute(query, tuple(values))
|
||||
database.commit()
|
||||
database.close()
|
||||
|
||||
|
||||
#database.execute(
|
||||
# f"INSERT INTO {table} ({column_names}) VALUES ({placeholders})",
|
||||
# tuple(values)
|
||||
#)
|
||||
|
||||
#database.commit()
|
||||
#database.close()
|
||||
|
||||
print(f"Successfully saved data to {table} during {action.name}")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def readRow(action, resolved, outputs):
|
||||
@@ -117,12 +134,13 @@ def readRow(action, resolved, outputs):
|
||||
searchcolumn = action.readrow["searchcolumn"]
|
||||
|
||||
values = []
|
||||
|
||||
for item in rowsearchvalue:
|
||||
if "outputs" in item:
|
||||
value = outputs[item["outputs"]]
|
||||
elif "resolved" in item:
|
||||
value = resolved[item["resolved"]]
|
||||
|
||||
|
||||
values.append(value)
|
||||
|
||||
exports = action.readrow["export"]
|
||||
|
||||
Reference in New Issue
Block a user