From c065e3fc1990b7db7c27c7150e0fbab2168f974b Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Mon, 4 May 2015 21:51:18 +0200 Subject: [PATCH] Properly Insert/Update into gamestats_profile. --- gamespy/gs_database.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gamespy/gs_database.py b/gamespy/gs_database.py index d20ff8e..cd59854 100644 --- a/gamespy/gs_database.py +++ b/gamespy/gs_database.py @@ -532,8 +532,12 @@ class GamespyDatabase(object): # Gamestats-related functions def pd_insert(self, profileid, dindex, ptype, data): with Transaction(self.conn) as tx: - tx.nonquery("INSERT OR REPLACE INTO gamestat_profile (profileid, dindex, ptype, data) VALUES(?,?,?,?)", (profileid, dindex, ptype, data)) - tx.nonquery("UPDATE gamestat_profile SET data = ? WHERE profileid = ? AND dindex = ? AND ptype = ?", (data, profileid, dindex, ptype)) + row = tx.queryone("SELECT COUNT(*) FROM gamestat_profile WHERE profileid = ? AND dindex = ? AND ptype = ?", (profileid, dindex, ptype)) + count = int(row[0]) + if count > 0: + tx.nonquery("UPDATE gamestat_profile SET data = ? WHERE profileid = ? AND dindex = ? AND ptype = ?", (data, profileid, dindex, ptype)) + else: + tx.nonquery("INSERT INTO gamestat_profile (profileid, dindex, ptype, data) VALUES(?,?,?,?)", (profileid, dindex, ptype, data)) def pd_get(self, profileid, dindex, ptype): with Transaction(self.conn) as tx: