Fix query for updating the stations table.

I am still not good at knowing when to use quotes for values.
This commit is contained in:
W1CDN 2023-07-09 10:15:54 -05:00
parent b0f0a4f8dc
commit c0ff61063f

View File

@ -61,6 +61,7 @@ def main():
attrib_names = ', '.join('"%s"' % w for w in a.keys()) attrib_names = ', '.join('"%s"' % w for w in a.keys())
attrib_values = ", ".join("?" * len(a.keys())) attrib_values = ", ".join("?" * len(a.keys()))
sql = "INSERT INTO frames ("+attrib_names+") VALUES ("+attrib_values+")" sql = "INSERT INTO frames ("+attrib_names+") VALUES ("+attrib_values+")"
try: try:
# Insert data # Insert data
conn.execute(sql, list(a.values())) conn.execute(sql, list(a.values()))
@ -71,13 +72,17 @@ def main():
# It's not immediately needed, so I'm skipping it. # It's not immediately needed, so I'm skipping it.
# Build query # Build query
# "from" is wrappedin [] because it is a reserved word and using '' doesn't work. # "from" is wrappedin [] because it is a reserved word and using '' doesn't work.
station_update = ", ".join((a['from'], a['created_unix'], "1")) try:
station_update = "'"+a['from'] +"', '"+ str(a['created_unix']) +"', '1'"
query3 = "INSERT INTO stations ([from], last_heard_unix, count) \ query3 = "INSERT INTO stations ([from], last_heard_unix, count) \
VALUES("+station_update+", 1) \ VALUES("+station_update+") \
ON CONFLICT([from]) \ ON CONFLICT([from]) \
DO UPDATE SET count = count + 1;" DO UPDATE SET count = count + 1;"
print(query3)
# Insert/update data # Insert/update data
conn.execute(query3) conn.execute(query3)
except:
print("Stations table couldn't be updated.")
conn.commit() conn.commit()