int CGenerateSQLFile::_CheckLine( VrtLinesConT& vrtAllLines ) { int nFunRes = 0; VrtLinesConIterT iterAllLine; std::string strOneLineTmp; iterAllLine = vrtAllLines.begin(); while ( iterAllLine != vrtAllLines.end() ) { strOneLineTmp.clear(); strOneLineTmp = *iterAllLine; if (!strOneLineTmp.empty() &&std::string::npos == strOneLineTmp.find(";") && std::string::npos == strOneLineTmp.find("+") && std::string::npos == strOneLineTmp.find("=") && std::string::npos == strOneLineTmp.find("[") && std::string::npos == strOneLineTmp.find("[[") && std::string::npos == strOneLineTmp.find("AQ")) { _SysLog(SourceFLInfo, DebugError, "inVaild Line:%s", strOneLineTmp.c_str()); nFunRes = -1; break; }//if iterAllLine++; }//while return nFunRes; }
int CGenerateSQLFile::_ParseCmdLine(const VrtLinesConT& vecArgs) { int nFunRes = 0; unsigned int nIndex = 0; std::string strDefInputFile = def_Str_Argv_inputfile; std::string strDefOutPath = def_Str_Argv_outpath; std::string strParamName; std::string strParamValue; const char* str = NULL; // First arg is USUALLY the program name if (vecArgs.size() > 0) { if (vecArgs[0].size() > 0) { if (vecArgs[0][0] != '-') { m_strParamProgName = vecArgs[0]; nIndex = 1; } } } //defualt value m_strParamInputFile = defSQLFileName_IN_SQLCODETXT; m_strParamOutpath = "./"; // The rest should be standard parameters for (; nIndex < vecArgs.size(); nIndex++) { str = vecArgs[nIndex].c_str(); if (!_ExtractArg(str, strParamName, strParamValue)) { _SysLog(SourceFLInfo, DebugError, "Err: _ExtractArg() %s", str); nFunRes = -1; return nFunRes; } if (!strParamName.empty()) { if (0 == CUtilityFun::getInstance().sysStricmp(strDefInputFile.c_str(), strParamName.c_str())) { m_strParamInputFile = strParamValue; } else if (0 == CUtilityFun::getInstance().sysStricmp(strDefOutPath.c_str(), strParamName.c_str())) { m_strParamOutpath = strParamValue; } } }//for return nFunRes; }
int CGenerateSQLFile::_TrimLines( VrtLinesConT& vrtAllLines ) { int nFunRet = 0; VrtLinesConIterT iterAllLine; iterAllLine = vrtAllLines.begin(); while ( iterAllLine != vrtAllLines.end() ) { CUtilityFun::getInstance().trim(*iterAllLine); iterAllLine++; }//while return nFunRet; }
int CGenerateSQLFile::setParam(int argc, char *argv[]) { int nFunRes = 0; VrtLinesConT vecArgs; std::string strLogError; if (1 == argc || argc > 3) { nFunRes = -1; return nFunRes; } for (int nIndex = 0; nIndex < argc; nIndex++) { vecArgs.push_back(argv[nIndex]); } nFunRes = _ParseCmdLine(vecArgs); vecArgs.clear(); m_strDirSqlCodeTxt = defSQLFileName_IN_SQLCODETXT; m_strDirSqlH = defSQLFileName_Out_SQLH; m_strDirSqlMacrodefH = defSQLFileName_Out_SQLMACRODEFH; m_strDirErrorReport = defSQLFilename_OUT_ERRORREPORT; m_strDirErrorReportReserve = defSQLFilename_OUT_ERRORREPORT; if (false == m_strParamInputFile.empty()) { m_strDirSqlCodeTxt = m_strParamInputFile; } if (false == m_strParamOutpath.empty()) { m_strDirSqlH = m_strParamOutpath + "/"; m_strDirSqlH += defSQLFileName_Out_SQLH; m_strDirSqlMacrodefH = m_strParamOutpath + "/"; m_strDirSqlMacrodefH += defSQLFileName_Out_SQLMACRODEFH; // /u02/tabuild/3001_MYSQL/C955_Build/Base_3001/Base/SqlGenErrorReport.log m_strDirErrorReport = "../../../../"; m_strDirErrorReport += defSQLFilename_OUT_ERRORREPORT; // /u02/tabuild/3001_MYSQL/C955_Build/Base_3001/Base/code/transactive/core/data_access_interface/src/SqlGenErrorReport.log m_strDirErrorReportReserve = m_strParamOutpath + "/"; m_strDirErrorReportReserve += defSQLFilename_OUT_ERRORREPORT; } return nFunRes; }
int CGenerateSQLFile::_ReadFile( const std::string& strFileName, VrtLinesConT& vrtAllLines ) { int nFunRet = 0; std::ifstream IfstreamSrcFile; char* pszInBuff = NULL; int nFilelines = 0; if (strFileName.empty()) { nFunRet = -1; return nFunRet; } IfstreamSrcFile.open(strFileName.c_str()); if (IfstreamSrcFile.fail()) { _SysLog(SourceFLInfo, DebugError, "error! open file error. FileName=%s", strFileName.c_str()); nFunRet = -1; return nFunRet; } pszInBuff = new char[DEF_INT_MAXLINELEN]; memset(pszInBuff, 0, DEF_INT_MAXLINELEN); // Read in all lines and add them to a vector while ( IfstreamSrcFile.getline ( pszInBuff, DEF_INT_MAXLINELEN ) ) { nFilelines++; if (LINE_COMMONT != pszInBuff[0]) { std::string strLine = pszInBuff; CUtilityFun::getInstance().removeUnVisableStr(strLine); CUtilityFun::getInstance().trim(strLine); //check line is not empty or commont line if (false == strLine.empty() && ';' != strLine[0]) { vrtAllLines.push_back( strLine ); } } memset(pszInBuff, 0, DEF_INT_MAXLINELEN); }//while // close file if (IfstreamSrcFile.is_open()) { IfstreamSrcFile.close(); } if (NULL != pszInBuff) { delete []pszInBuff; pszInBuff = NULL; } nFunRet = 0; return nFunRet; }
int CGenerateSQLFile::_RemoveBlackLine( VrtLinesConT& vrtAllLines ) { int nFunRet = 0; VrtLinesConIterT vtrLineIter; _TrimLines(vrtAllLines); vtrLineIter = vrtAllLines.begin(); while (vtrLineIter != vrtAllLines.end()) { if ( (*vtrLineIter).empty()) { vrtAllLines.erase(vtrLineIter); vtrLineIter = vrtAllLines.begin(); } else { vtrLineIter++; } }//while return nFunRet; }
int CGenerateSQLFile::_MutiLinesToSingleLine( VrtLinesConT& vrtAllLines ) { int nFunRet = 0; std::string strGetLine; std::string strTmp; VrtLinesConIterT iterAllLine = vrtAllLines.begin(); VrtLinesConIterT iterTmp = vrtAllLines.begin(); bool bFindJia = false; strGetLine.clear(); strTmp.clear(); while ( iterAllLine != vrtAllLines.end() ) { strGetLine.clear(); strGetLine = (*iterAllLine); if (!strGetLine.empty()) { bFindJia = false; if (LINE_ADD == strGetLine[0]) { bFindJia = true; } if (bFindJia) { strTmp += "\\"; strTmp += "\n"; strTmp +=strGetLine.substr(1); //'+' -- '\' '\r\n' (*iterAllLine) = ""; } else { if (!strTmp.empty()) { //strTmp += "\r\n"; (*iterTmp) = strTmp; strTmp.clear(); } iterTmp = iterAllLine; strTmp +=strGetLine; } }//if iterAllLine++; }//while //last one line if ((iterAllLine == vrtAllLines.end()) && (iterTmp != vrtAllLines.end())) { if (!strTmp.empty()) { //strTmp += "\r\n"; (*iterTmp) = strTmp; strTmp.clear(); strGetLine.clear(); } } nFunRet = 0; return nFunRet; }
int CTableInfo::analyzeData(VrtLinesConT& VtrOneTable) { int nFunRes = 0; VrtLinesConIterT VtrIterTable; VrtLinesConT VtrOneDb; if (VtrOneTable.empty()) { nFunRes = -1; return nFunRes; } VtrIterTable = VtrOneTable.begin(); while (VtrIterTable != VtrOneTable.end()) { std::string strLineTmp = (*VtrIterTable); //check this line is [TABLE] if (std::string::npos != strLineTmp.find("[") && std::string::npos == strLineTmp.find("[[")) {//[] m_strTableName = strLineTmp; VtrIterTable++; continue; } //check this line is [[DB]] if (std::string::npos != strLineTmp.find("[") && std::string::npos != strLineTmp.find("[[")) { //[[]] if (VtrOneDb.size() > 0) { CSQLType* pNewSQLType = new CSQLType(); nFunRes = pNewSQLType->analyzeData(VtrOneDb); VtrOneDb.clear(); m_LstDBInfo.push_back(pNewSQLType); pNewSQLType = NULL; } } VtrOneDb.push_back(strLineTmp); VtrIterTable++; if (VtrOneTable.end() == VtrIterTable) { CSQLType* pNewSQLType = new CSQLType(); nFunRes = pNewSQLType->analyzeData(VtrOneDb); VtrOneDb.clear(); m_LstDBInfo.push_back(pNewSQLType); pNewSQLType = NULL; } if (0 != nFunRes) { nFunRes = -1; return nFunRes; } }//while return nFunRes; }