Disable undo redo for scada device
This commit is contained in:
@@ -112,21 +112,21 @@ def get_current_operation(name: str) -> int:
|
|||||||
return int(read(name, 'select id from current_operation')['id'])
|
return int(read(name, 'select id from current_operation')['id'])
|
||||||
|
|
||||||
|
|
||||||
def execute_command(name: str, command: DbChangeSet) -> ChangeSet:
|
def execute_command(name: str, command: DbChangeSet, undo_redo: bool = True) -> ChangeSet:
|
||||||
op_table = read(name, "select * from operation_table")['option']
|
|
||||||
|
|
||||||
write(name, command.redo_sql)
|
write(name, command.redo_sql)
|
||||||
|
|
||||||
parent = get_current_operation(name)
|
if undo_redo:
|
||||||
redo_sql = command.redo_sql.replace("'", "''")
|
op_table = read(name, "select * from operation_table")['option']
|
||||||
undo_sql = command.undo_sql.replace("'", "''")
|
parent = get_current_operation(name)
|
||||||
redo_cs_str = str(command.redo_cs).replace("'", "''")
|
redo_sql = command.redo_sql.replace("'", "''")
|
||||||
undo_cs_str = str(command.undo_cs).replace("'", "''")
|
undo_sql = command.undo_sql.replace("'", "''")
|
||||||
write(name, f"insert into {op_table} (id, redo, undo, parent, redo_cs, undo_cs) values (default, '{redo_sql}', '{undo_sql}', {parent}, '{redo_cs_str}', '{undo_cs_str}')")
|
redo_cs_str = str(command.redo_cs).replace("'", "''")
|
||||||
|
undo_cs_str = str(command.undo_cs).replace("'", "''")
|
||||||
|
write(name, f"insert into {op_table} (id, redo, undo, parent, redo_cs, undo_cs) values (default, '{redo_sql}', '{undo_sql}', {parent}, '{redo_cs_str}', '{undo_cs_str}')")
|
||||||
|
|
||||||
if op_table == 'operation':
|
if op_table == 'operation':
|
||||||
current = read(name, 'select max(id) as id from operation')['id']
|
current = read(name, 'select max(id) as id from operation')['id']
|
||||||
write(name, f"update current_operation set id = {current}")
|
write(name, f"update current_operation set id = {current}")
|
||||||
|
|
||||||
return ChangeSet.from_list(command.redo_cs)
|
return ChangeSet.from_list(command.redo_cs)
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ def _set_scada_device(name: str, cs: ChangeSet) -> DbChangeSet:
|
|||||||
def set_scada_device(name: str, cs: ChangeSet) -> ChangeSet:
|
def set_scada_device(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
if get_scada_device(name, cs.operations[0]['id']) == {}:
|
if get_scada_device(name, cs.operations[0]['id']) == {}:
|
||||||
return ChangeSet()
|
return ChangeSet()
|
||||||
return execute_command(name, _set_scada_device(name, cs))
|
return execute_command(name, _set_scada_device(name, cs), False)
|
||||||
|
|
||||||
|
|
||||||
def _add_scada_device(name: str, cs: ChangeSet) -> DbChangeSet:
|
def _add_scada_device(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||||
@@ -89,7 +89,7 @@ def _add_scada_device(name: str, cs: ChangeSet) -> DbChangeSet:
|
|||||||
def add_scada_device(name: str, cs: ChangeSet) -> ChangeSet:
|
def add_scada_device(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
if get_scada_device(name, cs.operations[0]['id']) != {}:
|
if get_scada_device(name, cs.operations[0]['id']) != {}:
|
||||||
return ChangeSet()
|
return ChangeSet()
|
||||||
return execute_command(name, _add_scada_device(name, cs))
|
return execute_command(name, _add_scada_device(name, cs), False)
|
||||||
|
|
||||||
|
|
||||||
def _delete_scada_device(name: str, cs: ChangeSet) -> DbChangeSet:
|
def _delete_scada_device(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||||
@@ -107,7 +107,7 @@ def _delete_scada_device(name: str, cs: ChangeSet) -> DbChangeSet:
|
|||||||
def delete_scada_device(name: str, cs: ChangeSet) -> ChangeSet:
|
def delete_scada_device(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
if get_scada_device(name, cs.operations[0]['id']) == {}:
|
if get_scada_device(name, cs.operations[0]['id']) == {}:
|
||||||
return ChangeSet()
|
return ChangeSet()
|
||||||
return execute_command(name, _delete_scada_device(name, cs))
|
return execute_command(name, _delete_scada_device(name, cs), False)
|
||||||
|
|
||||||
|
|
||||||
def get_all_scada_device_ids(name: str) -> list[str]:
|
def get_all_scada_device_ids(name: str) -> list[str]:
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ def _set_scada_device_data(name: str, cs: ChangeSet) -> DbChangeSet:
|
|||||||
|
|
||||||
|
|
||||||
def set_scada_device_data(name: str, cs: ChangeSet) -> ChangeSet:
|
def set_scada_device_data(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
return execute_command(name, _set_scada_device_data(name, cs))
|
return execute_command(name, _set_scada_device_data(name, cs), False)
|
||||||
|
|
||||||
|
|
||||||
def _add_scada_device_data(name: str, cs: ChangeSet) -> DbChangeSet:
|
def _add_scada_device_data(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||||
@@ -66,7 +66,7 @@ def add_scada_device_data(name: str, cs: ChangeSet) -> ChangeSet:
|
|||||||
row = try_read(name, f"select * from scada_device_data where device_id = '{cs.operations[0]['device_id']}' and time = '{cs.operations[0]['time']}'")
|
row = try_read(name, f"select * from scada_device_data where device_id = '{cs.operations[0]['device_id']}' and time = '{cs.operations[0]['time']}'")
|
||||||
if row != None:
|
if row != None:
|
||||||
return ChangeSet()
|
return ChangeSet()
|
||||||
return execute_command(name, _add_scada_device_data(name, cs))
|
return execute_command(name, _add_scada_device_data(name, cs), False)
|
||||||
|
|
||||||
|
|
||||||
def _delete_scada_device_data(name: str, cs: ChangeSet) -> DbChangeSet:
|
def _delete_scada_device_data(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||||
@@ -87,4 +87,4 @@ def delete_scada_device_data(name: str, cs: ChangeSet) -> ChangeSet:
|
|||||||
row = try_read(name, f"select * from scada_device_data where device_id = '{cs.operations[0]['device_id']}' and time = '{cs.operations[0]['time']}'")
|
row = try_read(name, f"select * from scada_device_data where device_id = '{cs.operations[0]['device_id']}' and time = '{cs.operations[0]['time']}'")
|
||||||
if row == None:
|
if row == None:
|
||||||
return ChangeSet()
|
return ChangeSet()
|
||||||
return execute_command(name, _delete_scada_device_data(name, cs))
|
return execute_command(name, _delete_scada_device_data(name, cs), False)
|
||||||
|
|||||||
Reference in New Issue
Block a user