Big change to operation!

This commit is contained in:
wqy
2022-09-24 23:00:55 +08:00
parent 46df1beedb
commit 11e30cc49f
6 changed files with 286 additions and 256 deletions

View File

@@ -99,15 +99,15 @@ def add_node(name: str, node_type: str, id: str, x: float, y: float, table_sql:
return ChangeSet()
with conn[name].cursor() as cur:
sql = f"insert into _node (id, type) values ('{id}', '{node_type}'); "
sql = f"insert into _node (id, type) values ('{id}', '{node_type}');"
sql += table_sql
sql += f" insert into coordinates (node, coord) values ('{id}', '({x}, {y})');"
sql += f"insert into coordinates (node, coord) values ('{id}', '({x}, {y})');"
cur.execute(sql)
redo = sql.replace("'", '"')
undo = f'delete from coordinates where node = "{id}"; '
undo = f'delete from coordinates where node = "{id}";'
undo += table_undo_sql
undo += f' delete from _node where id = "{id}";'
undo += f'delete from _node where id = "{id}";'
add_operation(name, redo, undo)
change = ChangeSet()
@@ -133,9 +133,9 @@ def delete_node(name: str, node_type: str, id: str, table_sql: str, table_undo_s
cur.execute(sql)
redo = sql.replace("'", '"')
undo = f'insert into _node (id, type) values ("{id}", "{node_type}"); '
undo = f'insert into _node (id, type) values ("{id}", "{node_type}");'
undo += table_undo_sql
undo += f' insert into coordinates (node, coord) values ("{id}", "{coord}");'
undo += f'insert into coordinates (node, coord) values ("{id}", "{coord}");'
add_operation(name, redo, undo)
change = ChangeSet()
@@ -148,13 +148,13 @@ def add_link(name: str, link_type: str, id: str, table_sql: str, table_undo_sql:
return ChangeSet()
with conn[name].cursor() as cur:
sql = f"insert into _link (id, type) values ('{id}', '{link_type}'); "
sql = f"insert into _link (id, type) values ('{id}', '{link_type}');"
sql += table_sql
cur.execute(sql)
redo = sql.replace("'", '"')
undo = table_undo_sql
undo += f' delete from _link where id = "{id}";'
undo += f'delete from _link where id = "{id}";'
add_operation(name, redo, undo)
change = ChangeSet()