1

I am trying to execute some insert queries one query per goroutine (see code from emulating multiple requests to sqlite database as goroutine causes random panic) but most of failed with error: The database file is locked.

I found following from 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.

I inserted following code:

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

but it returned sqlite3.BusyFunc(func literal) evaluated but not used. Am I missing something?

1 Answer 1

1

sqlite3.BusyFunc is a type. What you're doing is converting a function into that type, as a result you get a function of that type. Instead, you have to register your function with:

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

Basically changing "sqlite3" for the name of the conn handle should do the job, just grab the return value.

Sign up to request clarification or add additional context in comments.

1 Comment

i forgot about func (c *Conn) BusyTimeout(d time.Duration) (prev BusyFunc) too, but it must be before BusyFunc statement. Changing sqlite to connection handle solves problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.