sqlite在第二次cursor.fetchall()后返回空结果
为什么我在执行 cursor.execute() 后,调用 cursor.fetchall() 两次却什么都得不到?有没有办法避免这种情况?我需要把信息存储到一个变量里吗?这应该是这样工作的吧?
相关问题:
1 个回答
5
fetchall 就是字面意思,它会把所有的结果都拿回来。拿完之后就没有剩下的了。如果你想要更多的结果,就需要再执行一次查询(或者再执行同样的查询)。
来自 Python 的 db-api 2.0 规范:
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]