QSqlQuery next大数据崩溃

QSqlQuery的查询结果遍历时需要缓存数据用于seek操作,大数据时会出现数据访问越界崩溃。

setForwardOnly(true)后可以禁用缓存。setForwardOnly(true) 要在执行exec()之前调用。

void QSqlQuery::setForwardOnly(bool forward)

Sets forward only mode to forward. If forward is true, only next() and seek() with positive values, are allowed for navigating the results.

Forward only mode can be (depending on the driver) more memory efficient since results do not need to be cached. It will also improve performance on some databases. For this to be true, you must call setForwardOnly() before the query is prepared or executed. Note that the constructor that takes a query and a database may execute the query.

Forward only mode is off by default.

Setting forward only to false is a suggestion to the database engine, which has the final say on whether a result set is forward only or scrollable. isForwardOnly() will always return the correct status of the result set.

Note: Calling setForwardOnly after execution of the query will result in unexpected results at best, and crashes at worst.

Note: To make sure the forward-only query completed successfully, the application should check lastError() for an error not only after executing the query, but also after navigating the query results.

Warning: PostgreSQL: While navigating the query results in forward-only mode, do not execute any other SQL command on the same database connection. This will cause the query results to be lost.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值