2011-08-01 116 views
1

我試圖弄清 MySQLdb文檔。我只是想知道是否有遺漏的東西。例如,我試圖查看「rowcount」(一個常量)實際上做了什麼,但在文檔中沒有看到它。Python MYSQLdb文檔缺少詳細信息?

所以是文件不完整或我只是看錯了地方?

謝謝。

+1

您還可以查看MySQLdb實現的[DB-API](http://www.python.org/dev/peps/pep-0249/)。 – bernie

+2

你有沒有試過pydoc文檔?運行交互式shell,導入MySQLdb,運行查詢,並運行'help(Cursor.rowcount)'。我不能保證文檔將在那裏,但它值得一試。 –

+0

@Chris:+1對於pydoc評論 –

回答

2

爲Python數據庫模塊文檔的主要來源是the DB-API 2.0 specification

.rowcount 

     This read-only attribute specifies the number of rows that 
     the last .execute*() produced (for DQL statements like 
     'select') or affected (for DML statements like 'update' or 
     'insert'). 

     The attribute is -1 in case no .execute*() has been 
     performed on the cursor or the rowcount of the last 
     operation is cannot be determined by the interface. [7] 

     Note: Future versions of the DB API specification could 
     redefine the latter case to have the object return None 
     instead of -1. 
+0

明白了。謝謝。 – user721975

0

我用下面的谷歌搜索:rowcount site:mysql-python.sourceforge.net

它往往是更好地使用谷歌site:運算符搜索一個網站,而不是使用該網站的本地搜索。但是你的權利,它沒有它自己的文檔。

+0

我很欣賞google-fu,但是你忽略了實際點擊鏈接。在該頁面上沒有稱爲'rowcount'的函數。有'field_count'和'affected_rows',兩者都建議你調用'Cursor.rowcount'。 –

+0

有趣的是,'Cursor.rowcount'似乎是無證的,這可能是OP爲什麼要問這個問題的原因... –

+0

@chris:我不是說它是一個Fu,並不是每個人都知道site:operator。你是對的,我誤解了鏈接,但幾乎立即糾正了我的帖子。 –

1

通過源代碼研讀之後那麼,這裏的相關行(MySQLdb的/ cursors.py:120)

self.rowcount = db.affected_rows() 

所以rowcount是隻爲Cursor類(不是法),成員變量,其恰好持有affected_rows的結果。我想這可能會節省您對該特定功能的調用。

+0

謝謝@Chris。這非常有幫助。 – user721975

2

我發現這個tutorial上MySQLdb的是有用的。 Rowcount被提及,但沒有用在其中一個例子中。

+0

+1。非常有用和易於理解的教程。謝謝。 – user721975