Python MYSQLdb 文档缺少细节?
我正在试着理解 MySQLdb 的文档。我在想,文档里是不是缺少了一些东西。例如,我想知道“rowcount”(一个常量)到底是干什么用的,但在文档里找不到相关信息。
所以,是文档不完整,还是我看错地方了呢?
谢谢。
4 个回答
1
经过仔细查看源代码,这里有一行相关的代码(MySQLdb/cursors.py:120)
self.rowcount = db.affected_rows()
所以,rowcount
只是 Cursor
类的一个成员变量(不是一个方法),它用来存储 affected_rows
的结果。我想这样做可能是为了省去调用那个特定函数的步骤。
2
我发现这个关于MySQLDB的教程挺有用的。里面提到了行数(rowcount),但在一个例子中没有用到。
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.