python - Sqlite3 中的 cursor.fechtmany(size=cursor.arraysize)

标签 python sqlite fetch

我想检索我的 Sqlite3 数据库的前 100 行:

connection = sqlite3.connect('aktua.db')
cursor = connection.cursor()

print('Actual \tCliente \tHistórica')
cursor.execute("SELECT * FROM Referencias WHERE r_aktua LIKE '%K'").fetchmany(size=100)

for row in cursor:
    print('%s \t%s \t%s' % row)

cursor.close()
connection.close()

我的代码检索数据库的所有行 (+4000)。
我读过 sqlite3.Cursor.fetchmany DocsSQLite Python Tutorial .

怎么了?

最佳答案

用这个来限制sql选择:

"SELECT * FROM Referencias WHERE r_aktua LIKE '%K' LIMIT 100"

或者将您的代码更改为:

rows = cursor.execute("SELECT * FROM Referencias WHERE r_aktua LIKE '%K'").fetchmany(size=100)

for row in rows:
    print('%s \t%s \t%s' % row)

关于python - Sqlite3 中的 cursor.fechtmany(size=cursor.arraysize),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22299793/

相关文章:

python - 像 MVC 3 这样的 flask 部分 View

python - 在具有数值的列上的 pandas 数据框中逐行应用函数

python - 如何获取列表中两个特定符号之间的项目

c++ - 插入两个相互引用的 SQL 表而无需执行单独的查询?

python - GitPython 创建和推送标签

php - 如何将 MySQL 数据库文件 (.sql) 转换为 PHP 中的 SQLite 文件?

sql - 如何格式化数据库中的许多值?

javascript - Promise.all 中获取失败,未捕获错误

javascript - 如何获取 javascript 文件内容并解析它以使用它的变量

javascript - 发送/接收图像以响应 http