GUI: make SQLite writes compatible with older sqlite versions

This commit is contained in:
Ruslan
2026-04-14 12:12:34 +03:00
parent 8de590c5d0
commit 9b31c5d5c5

View File

@@ -20,7 +20,9 @@ ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "")
def db_conn():
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
db_dir = os.path.dirname(DB_PATH)
if db_dir:
os.makedirs(db_dir, exist_ok=True)
conn = sqlite3.connect(DB_PATH)
conn.row_factory = sqlite3.Row
return conn
@@ -264,12 +266,15 @@ def new_peer():
with db_conn() as conn:
cur = conn.cursor()
cur.execute("""
INSERT INTO peers(name, public_key, client_address, advertised_routes)
VALUES (?,?,?,?)
ON CONFLICT(public_key)
DO UPDATE SET name=excluded.name, client_address=excluded.client_address, advertised_routes=excluded.advertised_routes
""", (name, client_pub, client_addr, routes))
cur.execute(
"UPDATE peers SET name=?, client_address=?, advertised_routes=? WHERE public_key=?",
(name, client_addr, routes, client_pub),
)
if cur.rowcount == 0:
cur.execute(
"INSERT INTO peers(name, public_key, client_address, advertised_routes) VALUES (?,?,?,?)",
(name, client_pub, client_addr, routes),
)
conn.commit()
return render_template(