🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.python
Article #327

Re: mysql + python

#327
From: Adam Przybyla
Date: Tue, 10 Dec 2002 16:02
41 lines
2347 bytes
Ogryzek <slukas5@poczta.onet.pl> wrote:
> Zrobilem tak
>    maxQuery = "select max(pmid) from pub_authors"
>    try:
>        maxQuery_cursor = db.cursor()
>        maxQuery_wyniki = maxQuery_cursor.execute(maxQuery)
>        idRow = maxQuery_cursor.fetchone()
>        highid = idRow[0]
>        self.nextid = highid + 1
>    except:
>        self.nextid = 0
>    if not self.nextid:
>        self.nextid = 1

> i to pieknie dziala
> ale gdy wstawiam wartosc self.nextid do wyrazenia sql to wyrzuca mi blad:
> illegal argument type for built-in operatio
> a wyrazenie wyglada tak:

>    sqlstr = "insert into pub_auhtors values('"+self.nextid+"')"

> probowalem konwertowac self.nextid na int, czyli int(self.nextid) ale to nie
> pomaga, i jestem juz glupi co tu trzeba zrobic zeby to zadzialalo.
	... ja mialem kursor.fetchall() i z tego wychodzilo cos w stylu:
((1345L,),)
jak sciagasz jednego, to mozesz miec co innego. Moj kod:
[root@castle root]# python1.5 test.py
3034
((3034L,),)
[root@castle root]# cat test.py
import MySQLdb
zapytanie='select max(klucz) from baza'
db=MySQLdb.connect(host='localhost',db='baza',user='juzer',passwd='haszlo')
c= db.cursor()
c.execute(zapytanie)
results = c.fetchall()
print int(results[0][0])
print results

Z powazaniem
								Adam Przybyla
Technical Details
Message-ID: <at535r$qo7$2@news.tpi.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!mat.uni.torun.pl!news.man.torun.pl!news.icm.edu.pl!news.onet.pl!newsfeed.gazeta.pl!newsfeed.tpinternet.pl!news.tpi.pl!not-for-mail
References: <at4cc9$fs7$1@news.onet.pl> <at4mi4$fo6$1@news.tpi.pl> <at50v9$1du$1@news.onet.pl> <slrnavc2d3.jg.gminick@hannibal.localdomain> <at52oi$9i6$1@news.onet.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!mat.uni.torun.pl!news.man.torun.pl!news.icm.edu.pl!news.onet.pl!newsfeed.gazeta.pl!newsfeed.tpinternet.pl!news.tpi.pl!not-for-mail
From: Adam Przybyla <adam@gliwice.pl>
Newsgroups: pl.comp.lang.python
Subject: Re: mysql + python
Date: Tue, 10 Dec 2002 16:02:03 +0000 (UTC)
Organization: tp.internet - http://www.tpi.pl/
Lines: 41
Sender: Adam Przybyla <adam@castle.ertel.com.pl>
Message-ID: <at535r$qo7$2@news.tpi.pl>
References: <at4cc9$fs7$1@news.onet.pl> <at4mi4$fo6$1@news.tpi.pl> <at50v9$1du$1@news.onet.pl> <slrnavc2d3.jg.gminick@hannibal.localdomain> <at52oi$9i6$1@news.onet.pl>
NNTP-Posting-Host: castle.ertel.com.pl
X-Trace: news.tpi.pl 1039536123 27399 195.116.54.3 (10 Dec 2002 16:02:03 GMT)
X-Complaints-To: usenet@tpi.pl
NNTP-Posting-Date: Tue, 10 Dec 2002 16:02:03 +0000 (UTC)
User-Agent: tin/1.5.12-20020427 ("Sugar") (UNIX) (Linux/2.4.18 (i686))
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit