Questions tagged «python-db-api»

3
Python DB-API:fetchone与fetchmany与fetchall
我今天刚刚和一些同事讨论了python的db-api fetchone vs fetchmany vs fetchall。 我确定每个应用程序的用例都取决于我正在使用的db-api的实现,但是总体而言,fetchone,fetchmany,fetchall的用例是什么? 换句话说,以下等效项是什么?还是其中有一个比其他人更受青睐?如果是这样,在哪些情况下? cursor.execute("SELECT id, name FROM `table`") for i in xrange(cursor.rowcount): id, name = cursor.fetchone() print id, name cursor.execute("SELECT id, name FROM `table`") result = cursor.fetchmany() while result: for id, name in result: print id, name result = cursor.fetchmany() cursor.execute("SELECT id, name FROM `table`") …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.