1

我正在尝试理解MySQLdb文档。我只是想知道那里是否缺少一些东西。例如,我试图查看“rowcount”(一个常量)实际上做了什么,但在文档中的任何地方都没有看到它。

那么文档是不完整的还是我只是看错了地方?

谢谢。

4

4 回答 4

2

Python 数据库模块的主要文档来源是DB-API 2.0 规范

.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.
于 2011-08-01T19:23:01.097 回答
2

我发现这个关于 MySQLDB 的教程很有用。提到了行数,但没有在其中一个示例中使用。

于 2011-08-01T20:20:30.363 回答
1

仔细阅读源代码后,这里是相关行(MySQLdb/cursors.py:120)

self.rowcount = db.affected_rows()

所以rowcount只是Cursor类的一个成员变量(不是方法),它恰好保存affected_rows. 我想它可能会为您节省对该特定功能的调用。

于 2011-08-01T19:12:37.540 回答
0

我使用了以下谷歌搜索:rowcount site:mysql-python.sourceforge.net

使用 google 运算符搜索站点通常site:比使用站点的本地搜索更好。但是你的权利,它没有自己的文档。

于 2011-08-01T18:32:45.983 回答