aprs_tool/test_db.py

30 lines
728 B
Python
Raw Normal View History

# 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()