Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '%s"': 0.07; 'host,': 0.07; 'try:': 0.07; '(1,': 0.09; 'logic': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; '"error': 0.16; '%d:': 0.16; '%s,': 0.16; 'hits': 0.16; 'mean,': 0.16; 'row': 0.16; 'storing': 0.16; 'duplicate': 0.17; 'exists': 0.17; 'creates': 0.18; 'skip:v 30': 0.20; 'work,': 0.22; 'cc:2**0': 0.23; 'insert': 0.23; 'seems': 0.23; 'cc:no real name:2**0': 0.24; 'host': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'wonder': 0.27; 'entries': 0.27; "doesn't": 0.28; 'received:209.85.212': 0.28; 'record': 0.28; 'primary': 0.30; 'print': 0.32; 'received:google.com': 0.34; 'wrong': 0.34; 'table': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'except': 0.36; 'but': 0.36; 'why': 0.37; 'skip:v 20': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'page': 0.38; 'instead': 0.39; 'where': 0.40; 'first': 0.61; 'here:': 0.62; 'visit': 0.64; 'date,': 0.65; 'pin': 0.65; 'webpage': 0.65; '8bit%:100': 0.70; '8bit%:92': 0.70; 'now:': 0.71; '2013': 0.84; 'visits': 0.91 X-Received: by 10.50.158.227 with SMTP id wx3mr1005519igb.2.1359051752242; Thu, 24 Jan 2013 10:22:32 -0800 (PST) Newsgroups: comp.lang.python Date: Thu, 24 Jan 2013 10:22:30 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=94.68.70.179; posting-account=DYJQ-woAAACEPH85Au2BhUVfFTfSfVa4 References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> <774065a6-3d15-4cff-88d8-7f822ed1c0b0@googlegroups.com> <25438e79-de00-463d-9ae3-7ea63e282e4a@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 94.68.70.179 MIME-Version: 1.0 Subject: Re: mysql solution From: Ferrous Cranus To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 65 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1359051760 news.xs4all.nl 6938 [2001:888:2000:d::a6]:49654 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37617 =CE=A4=CE=B7 =CE=A0=CE=AD=CE=BC=CF=80=CF=84=CE=B7, 24 =CE=99=CE=B1=CE=BD=CE= =BF=CF=85=CE=B1=CF=81=CE=AF=CE=BF=CF=85 2013 5:39:54 =CE=BC.=CE=BC. UTC+2, = =CE=BF =CF=87=CF=81=CE=AE=CF=83=CF=84=CE=B7=CF=82 Lele Gaifax =CE=AD=CE=B3= =CF=81=CE=B1=CF=88=CE=B5: > UPDATE visitors >=20 > SET visitors.hits=3Dvisitors.hits+1,=20 >=20 > visitors.useros=3D%s, >=20 > visitors.browser=3D%s,=20 >=20 > visitors.date=3D%s >=20 > WHERE visitors.pin=3D(SELECT counters.pin >=20 > FROM counters >=20 > WHERE counters.page=3D%s) >=20 > AND visitors.host=3D%s >=20 >=20 >=20 > But I wonder about the "logic" here: why are you storing the "useros", >=20 > "browser" and "date" in a table where the primary key seems to be >=20 > ("pin", "host")? I mean, what happens if a user visits the same page >=20 > twice, first with Firefox and then with Chrome? it doesn't work, it creates new entries on every webpage visit instead of u= pdating. this is what i have up until now: [code] # insert new page record in table counters or update it if already exists try: cursor.execute( '''INSERT INTO counters(page, hits) VALUES(%s, %s) ON DUPLICATE KEY UPDATE hits =3D hits + 1''', (htmlpage, 1) ) except MySQLdb.Error, e: print ( "Error %d: %s" % (e.args[0], e.args[1]) ) =09 # update existing visitor record if same pin and same host found try: cursor.execute('''UPDATE visitors SET hits=3Dhits+1, useros=3D%s, browser= =3D%s, date=3D%s=20 WHERE id=3D(SELECT id FRO= M counters WHERE page=3D%s) AND host=3D%s''', = (useros, browser, date, htmlpage, host)) except MySQLdb.Error, e: print ( "Error %d: %s" % (e.args[0], e.args[1]) ) =09 # insert new visitor record if above update did not affect a row if cursor.rowcount =3D=3D 0: cursor.execute( '''INSERT INTO visitors(hits, host, useros, browser, date= ) VALUES(%s, %s, %s, %s, %s)''', (1, host, useros, browser, date) ) [/code] Something is definately wrong here, its logic is not correct.....