From c0ff61063f485e4ce118e1d3d7a7f73da448b69e Mon Sep 17 00:00:00 2001 From: W1CDN Date: Sun, 9 Jul 2023 10:15:54 -0500 Subject: [PATCH] Fix query for updating the stations table. I am still not good at knowing when to use quotes for values. --- kiss_and_db.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/kiss_and_db.py b/kiss_and_db.py index 3cd25b1..d8e5320 100644 --- a/kiss_and_db.py +++ b/kiss_and_db.py @@ -61,6 +61,7 @@ def main(): attrib_names = ', '.join('"%s"' % w for w in a.keys()) attrib_values = ", ".join("?" * len(a.keys())) sql = "INSERT INTO frames ("+attrib_names+") VALUES ("+attrib_values+")" + try: # Insert data conn.execute(sql, list(a.values())) @@ -71,13 +72,17 @@ def main(): # It's not immediately needed, so I'm skipping it. # Build query # "from" is wrappedin [] because it is a reserved word and using '' doesn't work. - station_update = ", ".join((a['from'], a['created_unix'], "1")) - query3 = "INSERT INTO stations ([from], last_heard_unix, count) \ - VALUES("+station_update+", 1) \ - ON CONFLICT([from]) \ - DO UPDATE SET count = count + 1;" - # Insert/update data - conn.execute(query3) + try: + station_update = "'"+a['from'] +"', '"+ str(a['created_unix']) +"', '1'" + query3 = "INSERT INTO stations ([from], last_heard_unix, count) \ + VALUES("+station_update+") \ + ON CONFLICT([from]) \ + DO UPDATE SET count = count + 1;" + print(query3) + # Insert/update data + conn.execute(query3) + except: + print("Stations table couldn't be updated.") conn.commit()