文件首頁
MySQL Connector/Python 開發者指南
相關文件 下載本手冊
PDF (美式信紙) - 0.7Mb
PDF (A4) - 0.7Mb


MySQL Connector/Python 開發者指南  /  ...  /  MySQLCursor.fetchwarnings() 方法

10.5.12 MySQLCursor.fetchwarnings() 方法

語法

tuples = cursor.fetchwarnings()

此方法會傳回一個元組列表,其中包含先前執行操作所產生的警告。要設定是否擷取警告,請使用連線的 get_warnings 屬性。

以下範例顯示產生警告的 SELECT 陳述式

>>> cnx.get_warnings = True
>>> cursor.execute("SELECT 'a'+1")
>>> cursor.fetchall()
[(1.0,)]
>>> cursor.fetchwarnings()
[(u'Warning', 1292, u"Truncated incorrect DOUBLE value: 'a'")]

當產生警告時,可以使用連線的 raise_on_warnings 屬性來改為引發錯誤。