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

标签 sqlite go

我正在尝试对每个 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/

相关文章:

iphone - SQLite 中的 BLOB?

javascript - 使用sqlite3在node.js中变量的有效性

android - 如何在 Android 中从 Json 批量插入到 Sqlite

datetime - 将unix时间转换为字符串的Powershell函数?

go - 如何使用GO SDK在Couchbase文档中添加新字段

amazon-web-services - Amazon AWS S3 的 GO 脚本运行时错误

python - 存储句子中有趣的单词

go - 使用 Kite 和 Kontrol 的分布式微服务

forms - Go - 用于多个文件的 formFile

mysql - Go-MySQL-驱动程序 : Prepared Statements with Variable Query Parameters