From 06d16a58c868efc4cb820a1efc9d91bc3914501e Mon Sep 17 00:00:00 2001 From: Lyncoln Date: Wed, 21 Oct 2026 00:31:17 -0400 Subject: [PATCH] saveRow and readRow genericized and working --- core/runtime/savedata.py | 129 ++++++++++++++++++++++++++++++++++----- 1 file changed, 113 insertions(+), 16 deletions(-) diff --git a/core/runtime/savedata.py b/core/runtime/savedata.py index 52696d8..8750dde 100644 --- a/core/runtime/savedata.py +++ b/core/runtime/savedata.py @@ -46,20 +46,117 @@ def loadSave(action, outputs): print(f"Data loaded by {action.name} from {action.savepath}") return outputs -def buildSave2(action, outputs): - - database.execute(""" - CREATE TABLE IF NOT EXISTS message_mapping ( - rmass_message_id INTEGER PRIMARY KEY, - matrix_event_id TEXT NOT NULL UNIQUE - ) - """) - database = sqlite3.connect("rmmanager.db") - - database.execute( - "INSERT INTO message_mapping VALUES (?, ?)", - (action.savedata[savename], outputs["event_id"]) - ) +def saveRow(action, outputs, resolved): + if hasattr(action, "saverow"): + table = action.saverow["table"] - database.commit() - database.close() \ No newline at end of file + columns = action.saverow["columns"] + column_list = [] + column_creation = [] + for item in columns: + for key, value in item.items(): + column_list.append(key) + columnattr = "" + columnattr = key + " " + value + + 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"]] + + values.append(value) + + database = sqlite3.connect("savedata/rmmanager.db") + + columnitems = ", ".join(column_creation) + + database.execute(f""" + CREATE TABLE IF NOT EXISTS {table} ( + {columnitems} + ) + """) + + column_names = ", ".join(column_list) + placeholders = ", ".join(["?"] * len(values)) + + database.execute( + f"INSERT INTO {table} ({column_names}) VALUES ({placeholders})", + tuple(values) + ) + + database.commit() + database.close() + + + +def readRow(action, resolved, outputs): + result = None + if hasattr(action, "readrow"): + table = action.readrow["table"] + + columns = action.readrow["columns"] + column_list = [] + column_creation = [] + for item in columns: + for key, value in item.items(): + column_list.append(key) + columnattr = "" + columnattr = key + " " + value + + print(columnattr) + column_creation.append(columnattr) + + rowsearchvalue = action.readrow["rowsearchvalue"] + 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) + + database = sqlite3.connect("savedata/rmmanager.db") + + columnitems = ", ".join(column_creation) + + database.execute(f""" + CREATE TABLE IF NOT EXISTS {table} ( + {columnitems} + ) + """) + + cursor = database.execute( + f""" + SELECT * FROM {table} + WHERE {searchcolumn} = ? + """, + (value,) + ) + print("DEBUG RESOLVED TARGET ITEM") + print(value) + + result = cursor.fetchone() + print(result) + + + try: + target = result[action.readrow["columnnumber"]] + except TypeError: + target = None + print("Message ID not found in database") + + outputs["databasetarget"] = target + + print("READROW TEST") + print(target) + return resolved, outputs \ No newline at end of file