gpt4 book ai didi

python - QSqlRelationalTableModel 仅填充前 256 条记录

转载 作者:行者123 更新时间:2023-12-03 19:30:07 25 4
gpt4 key购买 nike

我有以下使用 PyQt5、sqlite3 和 python3.5.2 的简单模型。

class choicesModel(QDialog):
def __init__(self, parent=None):
super(choicesModel, self).__init__()

query = QSqlQuery()
query.prepare("SELECT COUNT(*) FROM resident_choices")
query.exec_()
query.next()
dbrows = query.value(0)
print("rows in db: ", dbrows)

self.choicesModel = QSqlRelationalTableModel(self)
self.choicesModel.setEditStrategy(QSqlTableModel.OnManualSubmit)
self.choicesModel.setTable("resident_choices")
self.choicesModel.select()
rows = self.choicesModel.rowCount()
print("rows returned by model.select(): ", rows)

执行模型会产生以下输出:

rows in db: 831

rows after model.select(): 256



最初的选择似乎只填充了前 256 条记录。这是一个 sqlite3 问题吗?如果是,我该如何填充所有记录(数据库总共只有大约 850 条记录)。如果不是,我如何强制加载所有记录?

结果是,在我更改代理过滤条件之前,使用代理模型和代理 View 最初不会显示所有记录——也就是说,我必须触发其余记录的加载。

最佳答案

记录数硬编码为 #define QSQL_PREFETCH 255QSqlQueryModel类(class)。要覆盖它,您必须自己显式获取所有行:

while self.choicesModel.canFetchMore():
self.choicesModel.fetchMore()

每次更新模型时,您可能都需要运行这样的代码,因此最好创建自己的子类并重新实现 fetchMore .

关于python - QSqlRelationalTableModel 仅填充前 256 条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42286016/

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