Why do you need to create a cursor when querying a sqlite database?

前端 未结 5 1049
無奈伤痛
無奈伤痛 2020-12-04 05:22

I\'m completely new to Python\'s sqlite3 module (and SQL in general for that matter), and this just completely stumps me. The abundant lack of descriptions of cursor objects

5条回答
  •  无人及你
    2020-12-04 05:51

    You need a cursor object to fetch results. Your example works because it's an INSERT and thus you aren't trying to get any rows back from it, but if you look at the sqlite3 docs, you'll notice that there aren't any .fetchXXXX methods on connection objects, so if you tried to do a SELECT without a cursor, you'd have no way to get the resulting data.

    Cursor objects allow you to keep track of which result set is which, since it's possible to run multiple queries before you're done fetching the results of the first.

提交回复
热议问题