Added local module imports for each definition. Improved database exception handling to reduce crashes
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import json
|
||||
import sqlite3
|
||||
import tempfile
|
||||
import os
|
||||
|
||||
def buildSave(action, outputs):
|
||||
import tempfile
|
||||
|
||||
if hasattr(action, "savedata"):
|
||||
save_data = {}
|
||||
|
||||
@@ -51,8 +51,11 @@ def loadSave(action, outputs):
|
||||
return outputs
|
||||
|
||||
def saveRow(action, outputs, resolved):
|
||||
import sqlite3
|
||||
from contextlib import closing
|
||||
|
||||
if hasattr(action, "saverow"):
|
||||
print("Saverow activated")
|
||||
#print("Saverow activated")
|
||||
table = action.saverow["table"]
|
||||
|
||||
columns = action.saverow["columns"]
|
||||
@@ -121,9 +124,15 @@ def saveRow(action, outputs, resolved):
|
||||
query += f" ON CONFLICT({target}) DO UPDATE SET {assignments}"
|
||||
else:
|
||||
query += f" ON CONFLICT({target}) DO NOTHING"
|
||||
|
||||
try:
|
||||
with closing(sqlite3.connect("savedata/rmmanager.db")) as database:
|
||||
with database:
|
||||
database.execute(query, tuple(values))
|
||||
|
||||
database.execute(query, tuple(values))
|
||||
database.commit()
|
||||
except sqlite3.IntegrityError as error:
|
||||
print(f"Unable to complete database write during {action.name}: {error}")
|
||||
return False
|
||||
|
||||
#database.execute(
|
||||
# f"INSERT INTO {table} ({column_names}) VALUES ({placeholders})",
|
||||
@@ -139,6 +148,8 @@ def saveRow(action, outputs, resolved):
|
||||
|
||||
|
||||
def readRow(action, resolved, outputs):
|
||||
import sqlite3
|
||||
|
||||
result = None
|
||||
if hasattr(action, "readrow"):
|
||||
table = action.readrow["table"]
|
||||
|
||||
Reference in New Issue
Block a user