From 5ec13d89ecfb1ccb5bc4ad08647272775eacf401 Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Wed, 22 Nov 2023 19:22:07 +1100 Subject: [PATCH] =?UTF-8?q?fix=202=20vendor=20overwrite=20=20#509?= =?UTF-8?q?=F0=9F=A9=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pialert/device.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/pialert/device.py b/pialert/device.py index a119b149..eda19ad1 100755 --- a/pialert/device.py +++ b/pialert/device.py @@ -200,17 +200,30 @@ def update_devices_data_from_scan (db): WHERE NOT EXISTS (SELECT 1 FROM CurrentScan WHERE dev_MAC = cur_MAC) """) - # Update IP & Vendor - mylog('debug', '[Update Devices] - 3 LastIP & Vendor') + # Update IP + mylog('debug', '[Update Devices] - 3 LastIP ') sql.execute("""UPDATE Devices SET dev_LastIP = (SELECT cur_IP FROM CurrentScan - WHERE dev_MAC = cur_MAC), - dev_Vendor = (SELECT cur_Vendor FROM CurrentScan - WHERE dev_MAC = cur_MAC - ) + WHERE dev_MAC = cur_MAC) WHERE EXISTS (SELECT 1 FROM CurrentScan WHERE dev_MAC = cur_MAC) """) + # Update only devices with empty or NULL vendors + mylog('debug', '[Update Devices] - 3 Vendor') + sql.execute("""UPDATE Devices + SET dev_Vendor = ( + SELECT cur_Vendor + FROM CurrentScan + WHERE dev_MAC = cur_MAC + ) + WHERE + (dev_Vendor = "" OR dev_Vendor IS NULL) + AND EXISTS ( + SELECT 1 + FROM CurrentScan + WHERE dev_MAC = cur_MAC + )""") + # Update (unknown) or (name not found) Names if available mylog('debug','[Update Devices] - 4 Unknown Name') sql.execute ("""UPDATE Devices