Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37601
| From | Lele Gaifax <lele@metapensiero.it> |
|---|---|
| Subject | Re: mysql solution |
| Date | 2013-01-24 16:39 +0100 |
| Organization | Nautilus Entertainments |
| References | (3 earlier) <mailman.977.1359030166.2939.python-list@python.org> <25438e79-de00-463d-9ae3-7ea63e282e4a@googlegroups.com> <mailman.984.1359034659.2939.python-list@python.org> <mailman.986.1359038146.2939.python-list@python.org> <XnsA1529BEFD8BCAduncanbooth@127.0.0.1> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.991.1359042007.2939.python-list@python.org> (permalink) |
Duncan Booth <duncan.booth@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@metapensiero.it | -- Fortunato Depero, 1929.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 03:04 -0800
Re: mysql solution Chris Angelico <rosuav@gmail.com> - 2013-01-24 22:16 +1100
Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 05:31 -0800
Re: mysql solution Chris Angelico <rosuav@gmail.com> - 2013-01-25 01:46 +1100
Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 05:31 -0800
Re: mysql solution Lele Gaifax <lele@metapensiero.it> - 2013-01-24 12:25 +0100
Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 04:01 -0800
Re: mysql solution Lele Gaifax <lele@metapensiero.it> - 2013-01-24 13:22 +0100
Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 05:24 -0800
Re: mysql solution Lele Gaifax <lele@metapensiero.it> - 2013-01-24 14:37 +0100
Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 06:35 -0800
Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 06:35 -0800
Re: mysql solution Duncan Booth <duncan.booth@invalid.invalid> - 2013-01-24 15:19 +0000
Re: mysql solution Chris Angelico <rosuav@gmail.com> - 2013-01-25 02:27 +1100
Re: mysql solution Lele Gaifax <lele@metapensiero.it> - 2013-01-24 16:39 +0100
Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 10:22 -0800
Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 10:22 -0800
Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 05:24 -0800
Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 04:01 -0800
Re: mysql solution Chris Angelico <rosuav@gmail.com> - 2013-01-24 22:29 +1100
Re: mysql solution Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-01-24 15:43 -0500
Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-25 07:43 -0800
Re: mysql solution Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-01-25 16:56 -0500
Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-26 02:35 -0800
Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-26 02:35 -0800
Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-25 07:43 -0800
csiph-web