在没有 fetchall() 的情况下迭代 PyoDBC 结果 [英] Iterating over PyoDBC result without fetchall()

查看:80
本文介绍了在没有 fetchall() 的情况下迭代 PyoDBC 结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 pyodbc 处理一个非常大的查询,我需要遍历行而不使用 fetchall() 一次加载它们.

I'm trying to process a very large query with pyodbc and I need to iterate over the rows without loading them all at once with fetchall().

有没有好的和有原则的方法来做到这一点?

Is there a good and principled way to do this?

推荐答案

当然 - 使用 while 循环和 fetchone.

Sure - use a while loop with fetchone.

http://code.google.com/p/pyodbc/wiki/光标#fetchone

row = cursor.fetchone()
while row is not None:
    # do something
    row = cursor.fetchone()

这篇关于在没有 fetchall() 的情况下迭代 PyoDBC 结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆