gpt4 book ai didi

sqlite - 使用 go 正确使用 sqlite3.BusyFunc?

转载 作者:IT王子 更新时间:2023-10-29 02:17:21 24 4
gpt4 key购买 nike

我正在尝试对每个 goroutine 执行一些插入查询一个查询(请参阅 emulating multiple requests to sqlite database as goroutine causes random panic 中的代码)但大多数失败并出现错误:数据库文件已锁定。

我从 http://godoc.org/code.google.com/p/go-sqlite/go1/sqlite3#BusyFunc 中找到以下内容:

type BusyFunc func(count int) (retry bool)
BusyFunc is a callback function invoked by SQLite when it is unable to acquire a lock on a table. Count is the number of times that the callback has been invoked for this locking event so far. If the function returns false, then the operation is aborted. Otherwise, the function should block for a while before returning true and letting SQLite make another locking attempt.

我插入了以下代码:

sqlite3.BusyFunc(func(counted int) (bool) { 
if counted > 10 {
return false
} else {
return true
}
})

但它返回了 sqlite3.BusyFunc(func literal) 已评估但未使用。我错过了什么吗?

最佳答案

sqlite3.BusyFunc 是一种类型。您正在做的是将函数转换为该类型,结果您获得了该类型的函数。相反,您必须通过以下方式注册您的功能:

func (c *Conn) BusyFunc(f BusyFunc) (prev BusyFunc)

基本上更改“sqlite3”作为连接句柄的名称应该可以完成工作,只需获取返回值即可。

关于sqlite - 使用 go 正确使用 sqlite3.BusyFunc?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23277678/

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