Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'syntax': 0.03; 'booth': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; ':-)': 0.13; '"standard': 0.16; 'emanuele': 0.16; 'expert,': 0.16; 'great!': 0.16; 'mean,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'storing': 0.16; 'surprising': 0.16; 'works...': 0.16; 'equivalent': 0.20; 'skip:v 30': 0.20; 'statement': 0.23; 'seems': 0.23; 'header:User-Agent:1': 0.26; 'wonder': 0.27; 'header:X-Complaints-To:1': 0.28; 'writes:': 0.29; "i'm": 0.29; 'primary': 0.30; 'to:addr:python-list': 0.33; 'whatever': 0.35; 'table': 0.35; 'something': 0.35; 'received:org': 0.36; 'but': 0.36; 'why': 0.37; '(for': 0.37; 'skip:v 20': 0.37; 'subject:: ': 0.38; 'page': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'first': 0.61; 'here:': 0.62; 'world': 0.63; 'more': 0.63; 'date,': 0.65; 'as:': 0.75; 'quando': 0.84; 'visits': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Lele Gaifax Subject: Re: mysql solution Date: Thu, 24 Jan 2013 16:39:54 +0100 Organization: Nautilus Entertainments References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> <774065a6-3d15-4cff-88d8-7f822ed1c0b0@googlegroups.com> <25438e79-de00-463d-9ae3-7ea63e282e4a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 78-134-78-49.v4.ngi.it User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) Cancel-Lock: sha1:Imtz/Iu0JYhVQCfFbKvkwvkOgus= 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: , Newsgroups: comp.lang.python Message-ID: Lines: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1359042007 news.xs4all.nl 6907 [2001:888:2000:d::a6]:49771 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37601 Duncan Booth writes: > I'm not MySQL expert, but something like this might work: > > cursor.execute('''UPDATE visitors,counter > SET visitors.hits=visitors.hits+1, visitors.useros=%s, > visitors.browser =%s, visitors.date=%s > WHERE visitors.pin=counter.pin AND counter.page = %s > AND visitors.host=%s''', > (useros, browser, date, page, host)) I stopped surprising at MySQL syntax eons ago, so if that works... great! Otherwise I would write the equivalent statement with a more "standard syntax" (for whatever meaning of "standard" in the SQL world :-) as: UPDATE visitors SET visitors.hits=visitors.hits+1, visitors.useros=%s, visitors.browser=%s, visitors.date=%s WHERE visitors.pin=(SELECT counters.pin FROM counters WHERE counters.page=%s) AND visitors.host=%s But I wonder about the "logic" here: why are you storing the "useros", "browser" and "date" in a table where the primary key seems to be ("pin", "host")? I mean, what happens if a user visits the same page twice, first with Firefox and then with Chrome? hope this helps, ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. lele@metapensiero.it | -- Fortunato Depero, 1929.