GUI: make SQLite writes compatible with older sqlite versions
This commit is contained in:
19
gui/app.py
19
gui/app.py
@@ -20,7 +20,9 @@ ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "")
|
|||||||
|
|
||||||
|
|
||||||
def db_conn():
|
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 = sqlite3.connect(DB_PATH)
|
||||||
conn.row_factory = sqlite3.Row
|
conn.row_factory = sqlite3.Row
|
||||||
return conn
|
return conn
|
||||||
@@ -264,12 +266,15 @@ def new_peer():
|
|||||||
|
|
||||||
with db_conn() as conn:
|
with db_conn() as conn:
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
cur.execute("""
|
cur.execute(
|
||||||
INSERT INTO peers(name, public_key, client_address, advertised_routes)
|
"UPDATE peers SET name=?, client_address=?, advertised_routes=? WHERE public_key=?",
|
||||||
VALUES (?,?,?,?)
|
(name, client_addr, routes, client_pub),
|
||||||
ON CONFLICT(public_key)
|
)
|
||||||
DO UPDATE SET name=excluded.name, client_address=excluded.client_address, advertised_routes=excluded.advertised_routes
|
if cur.rowcount == 0:
|
||||||
""", (name, client_pub, client_addr, routes))
|
cur.execute(
|
||||||
|
"INSERT INTO peers(name, public_key, client_address, advertised_routes) VALUES (?,?,?,?)",
|
||||||
|
(name, client_pub, client_addr, routes),
|
||||||
|
)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
|
|||||||
Reference in New Issue
Block a user