[Tutor] Counting MySQL Fields
alan.gauld at freenet.co.uk
Sat Jun 11 10:07:58 CEST 2005
> I'd like to use the result.numfields() function to count the fields
> given table, but apparently don't quite grasp how to implement it.
> my lame attempt.
OK, I've never use the numfields function so have no idea how it works
nor why I'd want to use it but...
> sql = "SELECT * FROM person order by lst_name"
Oh OK, I see why - you are using * instead of named fields...
> # Fetch all results from the cursor into a sequence and close the
> result = Cursor.fetchone()
> # Count the fields
First of all this seems odd since, although you call the function, you
aren't storing the result anywhere, even if it worked!
> ------ Relevant info from the resulting Traceback ---------
> AttributeError: 'Tuple' object has no attribute 'num_fields'
If results is a tuple then presumably the number of fields is just
the len() of the tuple?
More information about the Tutor