sqlite returning nothing after 2nd cursor.fetchall()

与世无争的帅哥 提交于 2021-02-04 06:54:51

问题


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?


回答1:


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]


来源:https://stackoverflow.com/questions/4150957/sqlite-returning-nothing-after-2nd-cursor-fetchall

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!