saveRow and readRow genericized and working
This commit is contained in:
+110
-13
@@ -46,20 +46,117 @@ def loadSave(action, outputs):
|
|||||||
print(f"Data loaded by {action.name} from {action.savepath}")
|
print(f"Data loaded by {action.name} from {action.savepath}")
|
||||||
return outputs
|
return outputs
|
||||||
|
|
||||||
def buildSave2(action, outputs):
|
def saveRow(action, outputs, resolved):
|
||||||
|
if hasattr(action, "saverow"):
|
||||||
|
table = action.saverow["table"]
|
||||||
|
|
||||||
database.execute("""
|
columns = action.saverow["columns"]
|
||||||
CREATE TABLE IF NOT EXISTS message_mapping (
|
column_list = []
|
||||||
rmass_message_id INTEGER PRIMARY KEY,
|
column_creation = []
|
||||||
matrix_event_id TEXT NOT NULL UNIQUE
|
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 = sqlite3.connect("rmmanager.db")
|
|
||||||
|
|
||||||
database.execute(
|
database.commit()
|
||||||
"INSERT INTO message_mapping VALUES (?, ?)",
|
database.close()
|
||||||
(action.savedata[savename], outputs["event_id"])
|
|
||||||
)
|
|
||||||
|
|
||||||
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
|
||||||
Reference in New Issue
Block a user