int CSQLMake::MergeSql(std::string &strSql, std::vector<std::string> &vctSql)
{
int iRet = 0;
boost::regex regEx("@@([\\d]+)");
boost::match_flag_type flags = boost::match_default;
std::vector<std::string>::iterator itr;
std::string strTemp;
std::string::const_iterator start, end;
int iCount = 0;
for (itr=vctSql.begin(); itr!=vctSql.end(); itr++)
{
boost::match_results<std::string::const_iterator> what;
strTemp = *itr;
while (boost::regex_search(strTemp, what, regEx, flags))
{
std::string str(what[1].first, what[1].second);
int iIndex = ACE_OS::atoi(str.c_str());
std::string::size_type stPos = strTemp.find(what[0]);
std::string strLeft = strTemp.substr(0, stPos);
std::string strRight = strTemp.substr(stPos + (what[0].second - what[0].first));
strTemp = strLeft + vctSql[iIndex] + strRight;
}
vctSql[iCount] = strTemp;
iCount ++;
}
strSql = strTemp;
return iRet;
}
将多个sql语句给合并成一个sql
最新推荐文章于 2025-07-10 15:28:05 发布
本文详细阐述了使用正则表达式对SQL语句进行合并和替换的操作过程,包括匹配特定模式并根据索引获取相应SQL片段,最终整合成统一的SQL语句。

3932

被折叠的 条评论
为什么被折叠?



