我试图弄清 MySQLdb文档。我只是想知道是否有遗漏的东西。例如,我试图查看“rowcount”(一个常量)实际上做了什么,但在文档中没有看到它。Python MYSQLdb文档缺少详细信息?
所以是文件不完整或我只是看错了地方?
谢谢。
我试图弄清 MySQLdb文档。我只是想知道是否有遗漏的东西。例如,我试图查看“rowcount”(一个常量)实际上做了什么,但在文档中没有看到它。Python MYSQLdb文档缺少详细信息?
所以是文件不完整或我只是看错了地方?
谢谢。
为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.
明白了。谢谢。 – user721975
我用下面的谷歌搜索:rowcount site:mysql-python.sourceforge.net
它往往是更好地使用谷歌site:
运算符搜索一个网站,而不是使用该网站的本地搜索。但是你的权利,它没有它自己的文档。
我很欣赏google-fu,但是你忽略了实际点击链接。在该页面上没有称为'rowcount'的函数。有'field_count'和'affected_rows',两者都建议你调用'Cursor.rowcount'。 –
有趣的是,'Cursor.rowcount'似乎是无证的,这可能是OP为什么要问这个问题的原因... –
@chris:我不是说它是一个Fu,并不是每个人都知道site:operator。你是对的,我误解了链接,但几乎立即纠正了我的帖子。 –
通过源代码研读之后那么,这里的相关行(MySQLdb的/ cursors.py:120)
self.rowcount = db.affected_rows()
所以rowcount
是只为Cursor
类(不是法),成员变量,其恰好持有affected_rows
的结果。我想这可能会节省您对该特定功能的调用。
谢谢@Chris。这非常有帮助。 – user721975
您还可以查看MySQLdb实现的[DB-API](http://www.python.org/dev/peps/pep-0249/)。 – bernie
你有没有试过pydoc文档?运行交互式shell,导入MySQLdb,运行查询,并运行'help(Cursor.rowcount)'。我不能保证文档将在那里,但它值得一试。 –
@Chris:+1对于pydoc评论 –