Obtaining Query Results

After you execute any SELECT statement, you will need to use one of these methods to obtain your results.

Method 1: Fetch All-at-Once

		# Print results in comma delimited format
		cur.execute("SELECT * FROM song")
		rows = cur.fetchall()
		for row in rows:
			for col in row:
				print "%s," % col
			print "\n"

Method 2: Fetch One-at-a-Time

		cur.execute("SELECT * FROM song WHERE id = 1")
		print "Id: %s -- Title: %s" % cur.fetchone()

There is no "better" way to do things. You should just use the method that works best for what you are trying to do.

**NOTE**Be careful if you are using the cursor class "CursorUseResultMixIn" or any of it's sub-classes. These cursor classes store their results on the server and feed them to your program as you request them. You have to retreive all of the results and close the cursor before you can execute additional queries. For more information on cursor classes see the reference section.

<-- Home -->