Skip to content

Instantly share code, notes, and snippets.

@gastonfeng
Last active April 22, 2019 10:09
Show Gist options
  • Save gastonfeng/21b92b2cad1f71d595d3f41b92560847 to your computer and use it in GitHub Desktop.
Save gastonfeng/21b92b2cad1f71d595d3f41b92560847 to your computer and use it in GitHub Desktop.
SQLite
SQLite写是锁整个数据库的,在写着数据库的时候,不能进行其它操作,同时读没有问题。
Sqlite 插入速度慢,平均插入一条速度在110ms左右,所以需要优化:
法1)
//提升读写速度
m_database.exec("PRAGMA synchronous = OFF");
m_database.exec("PRAGMA journal_mode = MEMORY");
1
2
3
法2)
手动开启事务,多条日志同时提交,如子线程代码所示。
bool ok = query.exec("begin");
while (logList.size() > 0) {
插入日志 ...
}
ok = query.exec("commit");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment