gpt4 book ai didi

c - sqlite3_reset() 什么时候需要?

转载 作者:行者123 更新时间:2023-12-02 04:05:07 66 4
gpt4 key购买 nike

在你告诉我阅读docs之前,是的,我已经读过它们。但我自己的测试告诉我,有时我可以对某些准备好的语句重复调用 sqlite3_step() 而无需先重置它们。例如:BEGINCOMMIT。您能否告诉我何时需要重置准备好的语句,因为我希望尽可能避免进行调用?

编辑:文档说(我的粗体):

The life-cycle of a prepared statement object usually goes like this:

最佳答案

来自 sqlite 来源:

/* We used to require that sqlite3_reset() be called before retrying
** sqlite3_step() after any error or after SQLITE_DONE. But beginning
** with version 3.7.0, we changed this so that sqlite3_reset() would
** be called automatically instead of throwing the SQLITE_MISUSE error.
** This "automatic-reset" change is not technically an incompatibility,
** since any application that receives an SQLITE_MISUSE is broken by
** definition.
**
** Nevertheless, some published applications that were originally written
** for version 3.6.23 or earlier do in fact depend on SQLITE_MISUSE
** returns, and those were broken by the automatic-reset change. As a
** a work-around, the SQLITE_OMIT_AUTORESET compile-time restores the
** legacy behavior of returning SQLITE_MISUSE for cases where the
** previous sqlite3_step() returned something other than a SQLITE_LOCKED
** or SQLITE_BUSY error.
*/

因此,在版本 3.7.0 中,如果您达到 SQLITE_DONE 并想要再次单步执行,则不需要 sqlite_reset。

完成后,您需要调用 sqlite3_finalize 来释放该语句。请参阅 https://www.sqlite.org/c3ref/finalize.html

关于c - sqlite3_reset() 什么时候需要?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35741175/

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