File tree Expand file tree Collapse file tree 1 file changed +34
-2
lines changed Expand file tree Collapse file tree 1 file changed +34
-2
lines changed Original file line number Diff line number Diff line change 2323cols = cursor1 .execute (COL_NAME_QUERY ).fetchall ()
2424cols = tuple (col [1 ] for col in cols )
2525
26- additions = res2 - res1
27- deletions = res1 - res2
26+ # Create dictionaries keyed by (vendor_id, device_id) for change detection
27+ dict1 = {(row [0 ], row [2 ]): row for row in res1 }
28+ dict2 = {(row [0 ], row [2 ]): row for row in res2 }
29+
30+ # Find changes where vendor_id and device_id match but other fields differ
31+ changes_old = []
32+ changes_new = []
33+ for key in dict1 .keys () & dict2 .keys ():
34+ old_row = dict1 [key ]
35+ new_row = dict2 [key ]
36+ # Check if device_name (index 3) or is_discrete (index 4) changed
37+ if old_row [1 ] != new_row [1 ] or old_row [3 ] != new_row [3 ] or old_row [4 ] != new_row [4 ]:
38+ changes_old .append (old_row )
39+ changes_new .append (new_row )
40+
41+ # Remove changed rows from additions/deletions
42+ changed_keys = set (zip ([row [0 ] for row in changes_old ], [row [2 ] for row in changes_old ]))
43+ additions = {row for row in res2 - res1 if (row [0 ], row [2 ]) not in changed_keys }
44+ deletions = {row for row in res1 - res2 if (row [0 ], row [2 ]) not in changed_keys }
2845
2946if additions :
3047 print ("### Additions" )
4158 for row in deletions :
4259 print (row )
4360 print ("```" )
61+
62+ if changes_old :
63+ print ("### Changes" )
64+ print ("#### Old values:" )
65+ print ("```" )
66+ print (cols )
67+ for row in changes_old :
68+ print (row )
69+ print ("```\n " )
70+ print ("#### Changed values:" )
71+ print ("```" )
72+ print (cols )
73+ for row in changes_new :
74+ print (row )
75+ print ("```" )
You can’t perform that action at this time.
0 commit comments