Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MySql and field names.
#1
Hi folks, I'm a programmer of many, many years, but not with Python, so I'm very new to the way of thinking and the syntax.

At the moment I'm struggling to find a way to work with the field 'names' of database queries. I can find forum posts where people return field names for printing, but that's no use, I need to be able to use them.

I have a data set in a cursor, it runs a fetch many(x), then a for row loop.

I need to run sql commands on the data in each row. Because of the complexity to he calculations, updating the rows and other database tables is impractical using one single update statement.

So I want to loop the cursor.rows with something like
"Update trees set Height=1.354, Mass=4.2437563 Where TreeName=", row[TreeName]

With the standard cursor I have to use [0], [1], [2] etc for field reference, this is crap!

(And yes, I'll need a second cursor/connection but that's a price I'm prepared to pay)

All help would be appreciated.
Thanks.
Reply
#2
https://dev.mysql.com/doc/connector-pyth...rdict.html
https://stackoverflow.com/questions/2276...dictcursor
does this help?
Reply
#3
Many thanks bran, I will give these a good read through. Cheers.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Mysql and mysql.connector error lostintime 2 610 Oct-03-2023, 10:25 PM
Last Post: lostintime
  Mysql error message: Lost connection to MySQL server during query tomtom 6 15,673 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  Bug ? when dataclass field name == field type Cyril 0 1,525 Oct-22-2020, 03:26 AM
Last Post: Cyril
  MySql Cursor field names. MuntyScruntfundle 1 2,518 Oct-22-2018, 04:10 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020