Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.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: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subsequent': 0.04; 'column': 0.07; 'extracted': 0.07; 'key.': 0.07; 'parameter': 0.07; 'exist.': 0.09; 'fails.': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; '%s,': 0.16; 'hits': 0.16; 'duplicate': 0.17; 'integer': 0.17; 'cc:2**0': 0.23; 'insert': 0.23; 'statement': 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; 'correct': 0.28; 'record': 0.28; 'primary': 0.30; 'received:google.com': 0.34; 'returning': 0.35; 'received:209.85': 0.35; 'except': 0.36; 'one,': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'where': 0.40; 'date,': 0.65; 'following.': 0.65; 'pin': 0.65 X-Received: by 10.50.187.133 with SMTP id fs5mr392732igc.12.1359033857230; Thu, 24 Jan 2013 05:24:17 -0800 (PST) Newsgroups: comp.lang.python Date: Thu, 24 Jan 2013 05:24:15 -0800 (PST) In-Reply-To: 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> <774065a6-3d15-4cff-88d8-7f822ed1c0b0@googlegroups.com> 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 To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1359033865 news.xs4all.nl 6948 [2001:888:2000:d::a6]:37831 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37586 column 'pin' is an 5-digit integer auto_increment primary key. What i want is to insert a new record or update the existing one, if 'pin' = column's value exist. The following statement fails. [code] cursor.execute( '''INSERT INTO counters(page, hits) VALUES(%s, %s) RETURNIN= G (pin)=20 ON DUPLICATE KEY UPDATE hits =3D hits + 1''', (html= page, 1) ) [/code]=20 Also except from the inserting/updating job, i also need 'pin' colum's valu= e to be extracted from the above statement so to be used to subsequent stat= ement like the following. This is not happening, hence the following statem= ent have no way to find 'pin' column's value which is to be used as a param= eter to it. [code] cursor.execute( '''UPDATE visitors SET hits =3D hits + 1, useros =3D %s, br= owser =3D %s, date =3D %s WHERE pin =3D %s AND host =3D %s''', (useros, bro= wser, date, pin, host))=20 [/code] Can someone correct this please and explain?