Documentation Home
MySQL Connector/Python Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 0.7Mb
PDF (A4) - 0.7Mb


10.5.15 MySQLCursor.description Property

Syntax:

tuples = cursor.description

This read-only property returns a list of tuples describing the columns in a result set. Each tuple in the list contains values as follows:

(column_name,
 type,
 None,
 None,
 None,
 None,
 null_ok,
 column_flags)

The following example shows how to interpret description tuples:

import mysql.connector
from mysql.connector import FieldType

...

cursor.execute("SELECT emp_no, last_name, hire_date "
               "FROM employees WHERE emp_no = %s", (123,))
for i in range(len(cursor.description)):
  print("Column {}:".format(i+1))
  desc = cursor.description[i]
  print("  column_name = {}".format(desc[0]))
  print("  type = {} ({})".format(desc[1], FieldType.get_info(desc[1])))
  print("  null_ok = {}".format(desc[6]))
  print("  column_flags = {}".format(desc[7]))

The output looks like this:

Column 1:
  column_name = emp_no
  type = 3 (LONG)
  null_ok = 0
  column_flags = 20483
Column 2:
  column_name = last_name
  type = 253 (VAR_STRING)
  null_ok = 0
  column_flags = 4097
Column 3:
  column_name = hire_date
  type = 10 (DATE)
  null_ok = 0
  column_flags = 4225

The column_flags value is an instance of the constants.FieldFlag class. To see how to interpret it, do this:

>>> from mysql.connector import FieldFlag
>>> FieldFlag.desc