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 json
|
||||||
import sqlite3
|
|
||||||
import tempfile
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
def buildSave(action, outputs):
|
def buildSave(action, outputs):
|
||||||
|
import tempfile
|
||||||
|
|
||||||
if hasattr(action, "savedata"):
|
if hasattr(action, "savedata"):
|
||||||
save_data = {}
|
save_data = {}
|
||||||
|
|
||||||
@@ -51,8 +51,11 @@ def loadSave(action, outputs):
|
|||||||
return outputs
|
return outputs
|
||||||
|
|
||||||
def saveRow(action, outputs, resolved):
|
def saveRow(action, outputs, resolved):
|
||||||
|
import sqlite3
|
||||||
|
from contextlib import closing
|
||||||
|
|
||||||
if hasattr(action, "saverow"):
|
if hasattr(action, "saverow"):
|
||||||
print("Saverow activated")
|
#print("Saverow activated")
|
||||||
table = action.saverow["table"]
|
table = action.saverow["table"]
|
||||||
|
|
||||||
columns = action.saverow["columns"]
|
columns = action.saverow["columns"]
|
||||||
@@ -122,8 +125,14 @@ def saveRow(action, outputs, resolved):
|
|||||||
else:
|
else:
|
||||||
query += f" ON CONFLICT({target}) DO NOTHING"
|
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(
|
#database.execute(
|
||||||
# f"INSERT INTO {table} ({column_names}) VALUES ({placeholders})",
|
# f"INSERT INTO {table} ({column_names}) VALUES ({placeholders})",
|
||||||
@@ -139,6 +148,8 @@ def saveRow(action, outputs, resolved):
|
|||||||
|
|
||||||
|
|
||||||
def readRow(action, resolved, outputs):
|
def readRow(action, resolved, outputs):
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
result = None
|
result = None
|
||||||
if hasattr(action, "readrow"):
|
if hasattr(action, "readrow"):
|
||||||
table = action.readrow["table"]
|
table = action.readrow["table"]
|
||||||
|
|||||||
Reference in New Issue
Block a user