sqlite 在第二个 cursor.fetchall() 之后什么都不返回 [英] sqlite returning nothing after 2nd cursor.fetchall()

查看:25
本文介绍了sqlite 在第二个 cursor.fetchall() 之后什么都不返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在 cursor.execute() 之后执行 cursor.fetchall() 两次时我什么也没得到?有没有办法防止这种情况发生?我需要将信息存储在变量上吗?它应该以这种方式工作吗?

解决方案

fetchall 做它所说的——它获取所有.之后就什么都没有了.要获得更多结果,您需要运行另一个查询(或再次运行相同的查询).

来自 python db-api 2.0 规范:

<块引用>

cursor.fetchall()获取查询结果的所有(剩余)行,返回它们作为序列序列(例如元组列表).请注意,游标的 arraysize 属性会影响执行此操作.cursor.fetchone()获取查询结果集的下一行,返回一个单个序列,或 None 当没有更多数据时可用.[6]

Why do I get nothing when I execute cursor.fetchall() twice after a cursor.execute()? Is there anyway of preventing this from happening? Do I need to store the information on a variable? Is it suppose to work this way?

解决方案

fetchall does what it says--it fetches all. There's nothing left after that. To get more results, you'd need to run another query (or the same query again).

From the python db-api 2.0 specification:

cursor.fetchall() 

        Fetch all (remaining) rows of a query result, returning
        them as a sequence of sequences (e.g. a list of tuples).
        Note that the cursor's arraysize attribute can affect the
        performance of this operation.

cursor.fetchone() 

        Fetch the next row of a query result set, returning a
        single sequence, or None when no more data is
        available. [6]

这篇关于sqlite 在第二个 cursor.fetchall() 之后什么都不返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆