Unclear behavior
First of all, there is really big chance that i didn`t understand something. But i have problem with testing my code using this library. So, I have db users which I clean at the beginning of every test with code like this:
users, err := sql.Open("sqlite3", "users.db")
if err != nil{
log.Panic(err)
}
statement, err := users.Prepare("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, login TEXT, password TEXT, privateRSAKey TEXT, recordIDs TEXT)")
if err != nil{
log.Panic(err)
}
statement.Exec()
statement, err = users.Prepare("DROP TABLE users")
if err != nil{
log.Panic(err)
}
statement.Exec()
users.Close()
When I run every test manually everything is ok, tests pass. But when I start tests with
go test
then the database is not cleared. I had idea that tests runs concurrently by default, but it is not true as i understood. And one more question about this lib : is it supposed to have 2 connections to db at the same time? For example, I open connection, write something, then in other place I open another connection and write something. Does it considered as multithreaded writing? Does lib flush data instantly?
please check all errors.
@mattn thank you, but i have no errors at all during execution and and every error is handled in project. Or did you said about some other errors?
the code that you provided above seems not handle errors.
statement.Exec()
right?
Oh, damn. Sorry, I've missed that this method returns something.
So I checked and my error is
panic : database is locked[recovered]
panic: database is locked
So you should add mutex as err says. Or add query parameter _busy_timeout for connection string.
Thank you, i got it.