sqlite的事务

时间:2022-07-09 12:56:40

好久没用数据库,知识都忘了,之前用sqlite 逐行insert数据,发现这性能实在是太坑,10w条数据,插入大约花了100来分钟.

后来发现还有事务这么一个东西,可以大幅度降低对io的操作,测试插入40w数据,大约花了5分钟左右,比之前的逐条插入可是666

	WCHAR szBuffer[MAX_PATH] = { 0 };
WCHAR szBuffer2[1024] = { 0 };
for (int i = 0; i < 500000; i+=100)
{
wstring strSql;
strSql += L"begin;\n";
for (int index = 0; index < 100;++index)
{
swprintf_s(szBuffer, MAX_PATH, L"xxxxxxxxx.yyyyy.%d", i+index);
swprintf_s(szBuffer2, 1024, INSERT_FILEINFO_TABLE, szBuffer, TRUE, 0.0f, TRUE);
strSql += szBuffer2;
strSql += L";\n";
}
strSql += L"commit;";
fileinfo.Execute(strSql.c_str());
}