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


10.5.17 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 interpretdescription tuples:

import mysql.connectorfrom 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 = 20483Column 2:  column_name = last_name  type = 253 (VAR_STRING)  null_ok = 0  column_flags = 4097Column 3:  column_name = hire_date  type = 10 (DATE)  null_ok = 0  column_flags = 4225

Thecolumn_flags value is an instance of theconstants.FieldFlag class. To see how to interpret it, do this:

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