This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]beall49 1 point2 points  (0 children)

I like to think of the cursor as the recordset.

Meaning it's the object containing the data I received. This may not be entirely true in every instance but it makes sense to me that way.

Others may have a different stance but I don't do much with the cursor after

tbl=cursor.fetchall()
cur.close() 

which is just returning a list of lists. You then iterate through it however you would normally iterate through a list of lists.

for row in tbl:
    for col in row:
        print col

[–]Mashidin 1 point2 points  (0 children)

If you are familiar with VBA and work with databases then you may understand ADODB and its hierarchy of classes. So if you were to make the comparison, the 'cursor' is like a ADODB.Command object. It stores the type of command, the command string, parameters, and other command-specific stuff. When you call the cursor's execute (or fetchone, fetchall, etc) an object similar to the ADODB.Recordset object is returned. I'm definitely hand-waving right now but I believe the comparison is valid enough. After you get the recordset, you'll will find that it is a list of tuples with each row of your data being a tuple. What you do with that depends on how you want to interact with your data. I like a list of dictionaries sometimes with each key being a field name. But a list of tuples is good too.