From d23dd0122a956bf76c770769f4a9ba627c2ca413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Gr=C3=BCneberg?= Date: Thu, 5 Dec 2013 17:18:17 -0600 Subject: [PATCH] Fix initial user creation. sqlite3.connect automatically creates a database file if it doesn't exist yet. Consequently, os.path.isfile will always return true, the auth table won't be created, and inserting a user will fail. --- ankisyncctl.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ankisyncctl.py b/ankisyncctl.py index 2d19d34..7b0ab9a 100755 --- a/ankisyncctl.py +++ b/ankisyncctl.py @@ -69,9 +69,8 @@ def adduser(username): conn = sqlite3.connect(AUTHDBPATH) cursor = conn.cursor() - if not os.path.isfile(AUTHDBPATH): - cursor.execute( "CREATE TABLE auth " - "(user VARCHAR PRIMARY KEY, hash VARCHAR)") + cursor.execute( "CREATE TABLE IF NOT EXISTS auth " + "(user VARCHAR PRIMARY KEY, hash VARCHAR)") cursor.execute("INSERT INTO auth VALUES (?, ?)", (username, hash))