Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python MySQLdb.cursors.Cursor.execute在不同游标的情况下返回不同的值为什么?_Python_Cursor_Mysql Python - Fatal编程技术网

Python MySQLdb.cursors.Cursor.execute在不同游标的情况下返回不同的值为什么?

Python MySQLdb.cursors.Cursor.execute在不同游标的情况下返回不同的值为什么?,python,cursor,mysql-python,Python,Cursor,Mysql Python,请参阅这两个python代码片段 conn = MySQLdb.connect(c['host'], c['user'], c['password'], c['db']) cur = conn.cursor() cur.execute("select * from geo_weathers;) -> **1147L** 及 为什么在上述两种情况下返回的行数不同? 仅供参考,表中有1147行 SSCursor用于在服务器端保存结果。这是原因吗? 哪些行受此select查询影响 有人知

请参阅这两个python代码片段

conn = MySQLdb.connect(c['host'], c['user'], c['password'], c['db'])
cur = conn.cursor()
cur.execute("select * from geo_weathers;)   ->  **1147L**

为什么在上述两种情况下返回的行数不同? 仅供参考,表中有1147行

SSCursor用于在服务器端保存结果。这是原因吗? 哪些行受此select查询影响


有人知道吗?

MySQLdb使用的标准游标是一个存储的结果游标。这意味着整个结果集从服务器传输,并作为
execute()
调用的结果缓存在客户机内存中

SSCursor
是一个服务器端游标,它只会在请求时将结果返回给客户端

游标
execute()
调用将返回MySql C API函数的结果,该函数反过来返回for
SELECT
查询的结果

因为结果存储在服务器端,所以客户机在迭代结果之前不知道有多少行受到影响

mysql\u num\u rows()的文档说明如下:

mysql_num_rows()的使用取决于您是否使用 mysql\存储\结果()或mysql\使用\结果()返回结果集。 如果使用mysql\u store\u result(),则可能会调用mysql\u num\u rows() 马上。如果使用mysql\u use\u result(),则mysql\u num\u rows()不会 返回正确的值,直到结果集中的所有行都被删除为止 已经找回了

如果要获得行数计数,请使用geo_weathers
中的
SELECT count(*),而不是依赖
execute()
调用的结果

conn = MySQLdb.connect(c['host'], c['user'], c['password'], c['db'], cursorclass=MySQLdb.cursors.SSCursor)
cur = conn.cursor()
cur.execute("select * from geo_weathers")   ->  **18446744073709551615L**