将sql语句用paraset中的值给填充一下!

int CSQLMake::DoSqlFit(std::string &strSql, CParaSet &oInPara)
{

    int iRet = 0;
    // 拆分sql
    std::vector<std::string> vctSql;
    SplitSql(strSql, vctSql);

    // 循环处理sql
    std::vector<std::string> vctSqlFit;
    std::vector<std::string>::iterator itr;
    for (itr=vctSql.begin(); itr!=vctSql.end(); itr++)
    {
        //std::cout << "=====>" << *itr << std::endl;
        MakeSqlFit(*itr, oInPara);
        //std::cout << "--------->" << *itr << std::endl;
        vctSqlFit.push_back(*itr);
    }

    // 合并sql
    MergeSql(strSql, vctSqlFit);

    // 最后处理一下排序字段 order by
    //需要排序,需要把原来的过滤条件给去掉。
    std::string::size_type iOrderpos = strSql.find(" order ");
    if (std::string::npos == iOrderpos)
    {
        ;//没有order排序,直接过。
    }
    else
    {
        strSql = strSql.substr(0,iOrderpos);
    }
    if ( oInPara["sort.strFild"].isNull() || oInPara["sort.iOrder"].isNull() )
    {
        return iRet;
    }
    int iOrder = oInPara["sort.iOrder"].asInt();
    std::string strSortField = oInPara["sort.strFild"].asString();
    strSql = strSql + " order by " + strSortField;
    if (2 == iOrder)
    {
        strSql = strSql + " ASC";
    }
    else
    {
        strSql = strSql + " DESC";
    }

    return iRet;
}

你可能感兴趣的:(sql语句)