MySQL Connector/Python 发行说明
此类提供所有支持的 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
类不可实例化。