After some study, I saw that SQLite will handle concurrent read . But after I try to create multi-thread and read the SQLite simultaneously, it will crash on sqlite3_get_table. But if I use serialized mode, it will be totally fine. Why this happened? Did I misunderstand something?
And here is how I read the data:
ret = sqlite3_get_table(db, sql, &results, &rows, &columns, &err_msg);
if (ret != SQLITE_OK) {
// error handling
}
if (rows < 1) {
// error handling
}
else {
// reading data
}
sqlite3_free_table(results);
I could also add lock/unlock around sqlite3_get_table to solve the problem. But why I can't just call this function without locking?