10.8 constants.FieldType类

此类提供所有受支持的 MySQL 字段或数据类型。它们在处理原始数据或定义您自己的转换器时非常有用。字段类型与每个游标一起存储在每列的描述中。

以下示例显示如何为结果集中的每一列打印数据类型的名称。

from __future__ import print_function
import mysql.connector
from mysql.connector import FieldType

cnx = mysql.connector.connect(user='scott', database='test')
cursor = cnx.cursor()

cursor.execute(
  "SELECT DATE(NOW()) AS `c1`, TIME(NOW()) AS `c2`, "
  "NOW() AS `c3`, 'a string' AS `c4`, 42 AS `c5`")
rows = cursor.fetchall()

for desc in cursor.description:
  colname = desc[0]
  coltype = desc[1]
  print("Column {} has type {}".format(
    colname, FieldType.get_info(coltype)))

cursor.close()
cnx.close()

FieldType无法实例化该类 。