Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37719
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <nikos.gr33k@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'retrieved': 0.05; 'data:': 0.07; 'host,': 0.07; "%s'": 0.09; 'logic': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; "wouldn't": 0.11; '%s,': 0.16; '(%s,': 0.16; 'entry.': 0.16; 'expected,': 0.16; 'hits': 0.16; 'host)': 0.16; 'record,': 0.16; 'later': 0.16; 'skip:= 20': 0.22; 'cc:2**0': 0.23; 'insert': 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; 'values': 0.26; 'first,': 0.27; 'record': 0.28; 'primary': 0.30; 'received:google.com': 0.34; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'easier': 0.38; 'instead': 0.39; 'where': 0.40; 'save': 0.61; '8bit%:95': 0.61; 'dont': 0.64; 'skip:= 30': 0.64; 'date,': 0.65; '8bit%:100': 0.70; '8bit%:92': 0.70; '2013': 0.84; 'cid': 0.84; 'vid': 0.84; 'dennis': 0.91 |
| X-Received | by 10.49.12.238 with SMTP id b14mr1760412qec.18.1359196542535; Sat, 26 Jan 2013 02:35:42 -0800 (PST) |
| Newsgroups | comp.lang.python |
| Date | Sat, 26 Jan 2013 02:35:42 -0800 (PST) |
| In-Reply-To | <mailman.1056.1359151015.2939.python-list@python.org> |
| 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> <mailman.1012.1359060248.2939.python-list@python.org> <b96ad10a-783a-416e-adc1-abdc404c1e92@googlegroups.com> <mailman.1056.1359151015.2939.python-list@python.org> |
| 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 <nikos.gr33k@gmail.com> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Message-ID | <mailman.1071.1359199323.2939.python-list@python.org> (permalink) |
| Lines | 35 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1359199323 news.xs4all.nl 6858 [2001:888:2000:d::a6]:37297 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:37719 |
Show key headers only | View raw
Τη Παρασκευή, 25 Ιανουαρίου 2013 11:56:44 μ.μ. UTC+2, ο χρήστης Dennis Lee Bieber έγραψε:
=====================
#find the visitor record for the (saved) cID and current host
cur.execute('''SELECT * FROM visitors WHERE counterID = %s and host = %s''', (cID, host) )
data = cur.fetchone() #cID&host are unique
if not data:
#first time for this host on this page, create new record
cur.execute('''INSERT INTO visitors (counterID, host, userOS, browser, lastvisit) VALUES (%s, %s, %s, %s, %s)''',
(cID, host, useros, browser, date) )
else:
#found the page, save its primary key for later use
vID = data[0]
#UPDATE record using retrieved vID
cur.execute('''UPDATE visitors SET userOS = %s, browser = %s, hits = hits + 1, lastvisit = %s
WHERE counterID = %s and host = %s''', (useros, browser, date, vID, host) )
=======================================
Instead of the above logic which you provided and it works as expected, wouldn't be easier to just:
Try to update the 'visitors' record, for that 'page' and that 'host'
if update fails(doesnt return any data), then we insert a new record entry.
We dont have to check 'SELECT * FROM visitors WHERE counterID = %s and host = %s' first, this one less cursor.execute.
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