From 1c057a5555d21b22971274648be613b83c962b9a Mon Sep 17 00:00:00 2001 From: W1CDN Date: Sat, 8 Jul 2023 21:54:37 -0500 Subject: [PATCH] Stub out db upsert code for stations table in test_db.py. See table definition at https://amiok.net/gitea/W1CDN/aprs_tool/pulls/30#issuecomment-947. --- test_db.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test_db.py diff --git a/test_db.py b/test_db.py new file mode 100644 index 0000000..1dcdf8b --- /dev/null +++ b/test_db.py @@ -0,0 +1,29 @@ + +# Learn how to update database + +import sqlite3 + +def get_db_connection(): + conn = sqlite3.connect('database.db') + conn.row_factory = sqlite3.Row + return conn + +conn = get_db_connection() + +# example https://stackoverflow.com/a/50718957/2152245 +query1 = "INSERT INTO players (user_name, age) \ +VALUES('steven', 32) \ +ON CONFLICT(user_name) \ +DO UPDATE SET age=excluded.age;" + +query2 = "INSERT INTO stations (id, 'from', frames_id, last_heard_unix, count) \ +VALUES(1, 'KC9TZN-9', 4068, 1687623864, 1) \ +ON CONFLICT(id) \ +DO UPDATE SET count = count + 1;" + +query3 = "INSERT INTO stations ('from', frames_id, last_heard_unix, count) \ +VALUES('KC9TZN-9', 4068, 1687623864, 1)" + +conn.execute(query2) +conn.commit() +conn.close()