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
類別無法被實例化。