sql - Python threading with Postgres: things are not being updated properly -


i have thread runs independently

thread.start_new_thread(listeningtf2servers, ()) 

which calls method eventually:

    def updatestats():         ...         player in pastgames[i]['players']:         ...                         cursor.execute('select yes newstats nick = \'' + player['nick'] + '\' order totalgames desc limit 1')                         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 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 nick = \'' + lower(player['nick']) + '\'')                                     cursor.execute('commit;')                                 else:                                     #similar query        ... 

here's thing. else in thread comes before method works fine.

but updatestats() seems work... weirdly. half of players have updated not seem updated in database.

for example, after every game method called players' game stats , win stats incremented. group of players, never happens, though other players played same game stats updated properly.

is there issue code causes issues threading or postgres? or there sql or postgres or python i'm not aware of causes these issues?

just educated guess: first query pass player['nick'], other calls lower(player['nick']) although queries affect newstats.nick. guess results different depending on whether player's nick lower-case or not.

you should try this:

lowernick = lower(player['nick']) ... cursor.execute('select yes newstats nick = %s order totalgames desc limit 1', [lowernick] ) ... cursor.execute('update newstats set totalgames = totalgames + 1, wins = wins + 1, medicgames = medicgames + 1, medicwins = medicwins +1 nick = %s', [lowernick]) ... cursor.execute('update newstats set totalgames = totalgames + 1, wins = wins + 1 nick = %s', [lowernick]) 

Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -