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::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;	
}
Beispiel #3
0
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;
}