mysql solution

Lele Gaifax lele at metapensiero.it
Thu Jan 24 10:39:54 EST 2013


Duncan Booth <duncan.booth at invalid.invalid> 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 at metapensiero.it  |                 -- Fortunato Depero, 1929.




More information about the Python-list mailing list