mysql solution

Chris Angelico rosuav at gmail.com
Thu Jan 24 10:27:03 EST 2013


On Fri, Jan 25, 2013 at 2:19 AM, Duncan Booth
<duncan.booth at invalid.invalid> wrote:
> Ferrous Cranus <nikos.gr33k at gmail.com> wrote:
>
>> I can do that but then i have to use that pin column's value in my
>> next statement.
>>
>> cursor.execute( '''UPDATE visitors SET hits = hits + 1, useros = %s,
>> browser = %s, date = %s WHERE pin = %s AND host = %s''', (useros,
>> browser, date, pin, host))
>
> 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))

Not sure that that works. This should, though:

UPDATE visitors SET hits=hits+1,blah,blah WHERE visitors.pin=(SELECT
pin FROM counter WHERE page=%s)

I prefer not to mention a table for updating if it's not actually being updated.

ChrisA



More information about the Python-list mailing list