为什么在cursor.execute()之后执行两次cursor.fetchall()时什么也没有得到?有什么办法可以防止这种情况发生吗?我需要将信息存储在变量上吗?它应该这样工作吗?
fetchall言出必行——一切皆有可能。之后就什么都没有剩下了。要获得更多结果,您需要运行另一个查询(或再次运行相同的查询)。
来自 python db-api 2.0 规范:
Run Code Online (Sandbox Code Playgroud)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]