I have a thread that runs independently
thread.start_new_thread(listeningTF2Servers, ())
which calls up this method eventually:
def updateStats():
...
for player in pastGames[i]['players']:
...
cursor.execute('SELECT yes FROM newstats WHERE nick = \'' + player['nick'] + '\' ORDER BY totalgames DESC LIMIT 1')
for row in cursor.fetchall():
if row[0] == 1:
if scoreDict[player['team']] == 1:
cursor.execute('UPDATE newstats SET totalgames = totalgames + 1, wins = wins + 1, medicgames = medicgames + 1, medicwins = medicwins +1 WHERE nick = \'' + lower(player['nick']) + '\'')
cursor.execute('COMMIT;')
else:
#similar query
else:
if scoreDict[player['team']] == 1:
cursor.execute('UPDATE newstats SET totalgames = totalgames + 1, wins = wins + 1 WHERE nick = \'' + lower(player['nick']) + '\'')
cursor.execute('COMMIT;')
else:
#similar query
...
Here's the thing. Everything else in the thread that comes before this method works fine.
But updateStats() seems to work... weirdly. But about HALF of the players that have to get updated do not seem to get updated in the database.
For example, after every game this method is called so that players' game stats and win stats are incremented. But for some group of players, this NEVER happens, even though for all other players who played the SAME GAME the stats get updated properly.
Is there an issue with my code that causes issues with threading or postgres? Or is there something with SQL or postgres or Python that I'm not aware of that causes these issues?
execute ('select 1 where a=\'' + x + '\'')useexecute ('select 1 where a=%s', [x]).