On Sun, Oct 6, 2013 at 1:31 AM, Νίκος Αλεξόπουλος <nikos.gr...@gmail.com> wrote: > # find the visitor record for the (saved) cID and current > host > cur.execute('''SELECT * FROM visitors WHERE counterID = %s > and cookieID = %s''', (cID, cookieID) ) > > data = cur.fetchone() #cookieID is unique > > if not data: > > # first time visitor on this page, create new record > cur.execute('''INSERT INTO visitors (counterID, > cookieID, host, city, useros, browser, ref, lastvisit) VALUES (%s, %s, %s, > %s, %s, %s, %s, %s)''', (cID, cookieID, host, city, useros, browser, ref, > lastvisit) ) > else: > # found the page, save its primary key for later use > vID = data[0] > # UPDATE record using retrieved vID > cur.execute('''UPDATE visitors SET host = %s, city = > %s, useros = %s, browser = %s, ref= %s, hits = hits + 1, lastvisit = %s > > WHERE counterID = %s and cookieID = %s''', (host, city, useros, browser, > ref, lastvisit, vID, cookieID) )
Do you understand the expression "race condition", and how it applies to the above code? If not, you MUST read up on that before relying on code like this, and as that's not a Python question, I recommend Google and Wikipedia.[1] ChrisA [1] Yes, I know they're not primary sources. For something like this, tertiary sources are going to do him fine. -- https://mail.python.org/mailman/listinfo/python-list