0
点赞
收藏
分享

微信扫一扫

SQLite3 使用容器vector批量插入记录

登高且赋 2022-09-19 阅读 44


int SQL_EXE(std::vector<std::string> vtExeSql)
{
if (NULL == m_pDB)
{
return -1;
}

char* pErrMsg = NULL;
int iRet = SQLITE_OK;

iRet = sqlite3_exec(m_pDB, "BEGIN", NULL, NULL, &pErrMsg);
if (SQLITE_OK != iRet)
{
if (NULL != pErrMsg)
{
sqlite3_free(pErrMsg);
}

return -1;
}

std::vector<std::string>::const_iterator iter = vtExeSql.begin();
for (; iter != vtExeSql.end(); ++iter)
{
std::string strSql = *iter;
if (!(strSql.empty()))
{
iRet = sqlite3_exec(m_pDB, strSql.c_str(), NULL, NULL, &pErrMsg);
if (SQLITE_OK != iRet)
{
continue;
}
}
}

iRet = sqlite3_exec(m_pDB, "COMMIT", NULL, NULL, &pErrMsg);
if (SQLITE_OK != iRet)
{
iRet = -1;
}

if (NULL != pErrMsg)
{
sqlite3_free(pErrMsg);
}

return iRet;
}

 

举报

相关推荐

0 条评论