gpt4 book ai didi

python - 获取 APSW 中的所有内容

转载 作者:太空宇宙 更新时间:2023-11-03 19:30:55 25 4
gpt4 key购买 nike

您知道 APSW 没有任何“fetchall”方法。我们只能使用.next()方法。那么如何将带有选择查询的执行命令的结果放入列表中?

最佳答案

apsw 3.6.22 版本允许我使用 cursor.fetchall() 检索列表中的所有行:

import apsw

conn = apsw.Connection(':memory:')
curs = conn.cursor()
curs.execute("CREATE TABLE foo (id INTEGER, name VARCHAR(255))")
curs.executemany("INSERT INTO foo VALUES (?, ?)", [(1, 'bar'),(2, 'baz')])
print curs.execute("SELECT * FROM foo").fetchall()

[(1, u'bar'), (2, u'baz')]

如果您的版本不支持此功能,但支持.next(),您可以将光标包装在列表中(迭代光标)吗?这对我有用:

curs.execute("SELECT * FROM foo")
print list(curs)

[(1, u'bar'), (2, u'baz')]

关于python - 获取 APSW 中的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5911825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com