MySQL: Get column name or alias from query

后端 未结 10 1758
死守一世寂寞
死守一世寂寞 2020-11-28 20:04

I\'m not asking for the SHOW COLUMNS command.

I want to create an application that works similarly to heidisql, where you can specify an SQL query and w

10条回答
  •  迷失自我
    2020-11-28 20:34

    cursor.description will give you a tuple of tuples where [0] for each is the column header.

    num_fields = len(cursor.description)
    field_names = [i[0] for i in cursor.description]
    

提交回复
热议问题