gpt4 book ai didi

sqlite - 您是否需要完成失败的准备语句?

转载 作者:行者123 更新时间:2023-12-03 15:57:19 31 4
gpt4 key购买 nike

使用sqlite3_prepare_v2时,是每条路径都调用sqlite3_finalize,还是只有成功时才调用?例如,这是我在 Swift 方法中使用的代码:

let prepare = sqlite3_prepare_v2(db!, SQLString, -1, &delete, nil)
if (prepare == SQLITE_OK){
if !(sqlite3_step(delete) == SQLITE_DONE){
sqlite3_finalize(delete) // *
sqlite3_close(db)
return
}
} else {
// **
sqlite3_close(db)
return
}
sqlite3_finalize(delete)
sqlite3_close(db)

// rest of method continues if it didn't fail

* 我假设我需要在这里调用它,因为即使它没有成功运行,语句也已成功准备好

** 但我需要在这里调用它吗?

最佳答案

如果 sqlite3_prepare_v2 失败,则无需调用 sqlite3_finalize

参见 here :

*ppStmt is left pointing to a compiled prepared statement that can be executed using sqlite3_step(). If there is an error, *ppStmt is set to NULL.

不过,用 NULL 调用 sqlite3_finalize 没有坏处。

参见 here :

Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.

关于sqlite - 您是否需要完成失败的准备语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42636516/

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