Python MYSQLdb文档缺少详细信息?

2024-05-21 02:21:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图弄清楚 MySQLdb文档。我只是想知道有没有东西遗漏。例如,我试图查看“rowcount”(一个常量)的实际作用,但在文档中没有看到它。在

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

谢谢。在


Tags: 文件文档地方常量mysqldb遗漏rowcount
3条回答

在仔细研究了源代码之后,下面是相关的代码行(MySQLdb/光标.py:120)在

self.rowcount = db.affected_rows()

因此rowcount只是Cursor类的一个成员变量(不是一个方法),它恰好保存了affected_rows的结果。我想它可能会帮你省去对那个特定函数的调用。在

我发现MySQLDB上的tutorial很有用。Rowcount被提到,但没有在其中一个示例中使用。在

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.

相关问题 更多 >