473,322 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Walking through a mysql db

I'm writing a small wxpython app to display and update a dataset. So far, I
get the first record for display:

try:
cursor = conn.cursor ()
cursor.execute ("SELECT * FROM dataset")
item = cursor.fetchone ()

Now, how do I step through the dataset one row at a time? My form has 'next'
and 'back' buttons, and I'd like them to step forward or back, fetching the
appropriate row in the table. I've tried setting cursor.rownumber by
incrementing it prior to the fetchone() w/o effect.

Thanks for any pointers.

Jeff Elkins


Jul 19 '05 #1
2 1257
Jeff Elkins wrote:
I'm writing a small wxpython app to display and update a dataset. So far,
I get the first record for display:

try:
cursor = conn.cursor ()
cursor.execute ("SELECT * FROM dataset")
item = cursor.fetchone ()

Now, how do I step through the dataset one row at a time? My form has
'next' and 'back' buttons, and I'd like them to step forward or back,
fetching the appropriate row in the table. I've tried setting
cursor.rownumber by incrementing it prior to the fetchone() w/o effect.

You could either execute N-1 fetchone()s before you fetch the Nth dataset
(with N starting at 1)
or use the 'LIMIT' feature of MySQL:
cursor.execute ("SELECT * FROM dataset LIMIT %s,1", n)
where n is the index of the requested dataset (starting at 0)

--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
Jul 19 '05 #2
Jeff Elkins wrote:
I'm writing a small wxpython app to display and update a dataset. So far, I
get the first record for display:

try:
cursor = conn.cursor ()
cursor.execute ("SELECT * FROM dataset")
item = cursor.fetchone ()

Now, how do I step through the dataset one row at a time? My form has 'next'
and 'back' buttons, and I'd like them to step forward or back, fetching the
appropriate row in the table. I've tried setting cursor.rownumber by
incrementing it prior to the fetchone() w/o effect.

Thanks for any pointers.

Jeff Elkins


Jeff,
You just check for a fetchone return of None. "list" is a list
of tuples here.
...
cursor.execute( sql )
list = []
while 1:
row = cursor.fetchone()
if not row:
break
list.append(row)
...
wes
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Who Cares | last post by:
Okay, this may be a bit of a newbie question but I could really use some help. I want to write a set of routines that will read in the contents of XML files. I'll be reading the tag names,...
0
by: Chris Lyon | last post by:
I handle a lot of audio files of different formats, which live in a directory tree. WAV files in a wav directory, AIFF's in an AIFF directory next to the wav directory and mp3's in an MP3 directory...
4
by: mikey | last post by:
Hi all, I'm having great problems trying to install the latest MySQl RPM package onto my Red Hat Linux OS. There is already MySQL v 3.0 pre-installed with the RH Linux distribution disk but I...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
4
by: Jim Bancroft | last post by:
Sorry for the basic nature of this question. I know XSL can do this, but I don't recall a good method... Say I have an xml structure like this: <folder_structure> <folder name="folder1">...
1
by: Zachary Hartnett | last post by:
I was trying to write a routine this morning that would open a given assembly, walk the inheritance tree of classes in the assembly, and provide a list of classes in the assembly that inherit from...
5
by: TrulyUnusualdotcom | last post by:
I'm reading PHP & MySQL for Dummies 2nd edition...ya ya I know..lame. Anyway I got to the part about walking through an array and I just can't seem to figure out what this would be used for. What...
8
by: Ben Hallert | last post by:
Hi guys! I'm working on a little javascriptlet/greasemonkey script, and I've run into a challenge that I think can be solved with walking the DOM, but I feel like I'm kludging my way through and...
11
by: Simon Woods | last post by:
Hi I have this recursive function and I want to walk the inheritance hierarchy to set field values .... the generic T is constrainted as the base class of the inheritance hierarchy Friend...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.