Python MYSQLdb documentation missing details?

末鹿安然 提交于 2019-12-11 11:51:05

问题


I am trying to make sense of MySQLdb documentation. I was just wondering if there are things missing from there. For example, I am trying to see what "rowcount" (a constant) actually does, but am not seeing it anywhere in the documentation.

So is the documentation incomplete or am I just looking at the wrong place?

Thanks.


回答1:


The primary source of documentation for Python database modules is 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.



回答2:


I found this tutorial on MySQLDB useful. Rowcount is mentioned, but not used in one of the examples.




回答3:


Well after poring through the source code, here's the relevant line (MySQLdb/cursors.py:120)

self.rowcount = db.affected_rows()

So rowcount is just a member variable for the Cursor class (not a method), which happens to hold the result of affected_rows. I guess it probably saves you a call to that particular function.




回答4:


I used the following google search: rowcount site:mysql-python.sourceforge.net

It is often better to use google site: operator to search a site than to use the site's native search. But your right, it doesn't have it's own documentation.



来源:https://stackoverflow.com/questions/6902638/python-mysqldb-documentation-missing-details

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!