gpt4 book ai didi

python - Pymysqlexecute() - 返回值不等于受影响的行数

转载 作者:行者123 更新时间:2023-11-29 17:34:24 25 4
gpt4 key购买 nike

我正在使用 pymysql 连接到本地 MySQL 安装。我已经建立了如下所示的连接,但我的问题是关于最后一行的execute() 调用的返回值。

documentation表示执行方法的返回值等于受影响的行数。我知道数据库表正好有 205299 行,所以有人能告诉我为什么我看到的行数要多得多 18446744073709551615 吗?

>>> import pymysql
>>> conn = pymysql.connect(
... host='localhost',
... port=3306,
... user='username',
... passwd='password',
... db='dbname',
... cursorclass = pymysql.cursors.SSCursor
... )
>>> cursor = conn.cursor()
>>> cursor.execute("SELECT support_id FROM tablename")
18446744073709551615

最佳答案

就您而言,问题出在使用SSCursor。阅读您提供的文档,您可以找到 limitations 是什么? :

There are limitations, though. The MySQL protocol doesn’t support returning the total number of rows, so the only way to tell how many rows there are is to iterate over every row returned. Also, it currently isn’t possible to scroll backwards, as only the current row is held in memory.

因此,如果您想知道有多少行受到影响,请使用缓冲游标 conn.cursor() 而不是服务器游标。

注意:受影响的行可能不等于表中的行数。

关于python - Pymysqlexecute() - 返回值不等于受影响的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50409919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com