当前位置: 首页>>代码示例>>C++>>正文


C++ Ptr::saveToAnswer方法代码示例

本文整理汇总了C++中table::Ptr::saveToAnswer方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::saveToAnswer方法的具体用法?C++ Ptr::saveToAnswer怎么用?C++ Ptr::saveToAnswer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在table::Ptr的用法示例。


在下文中一共展示了Ptr::saveToAnswer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: processSQL

void Session::processSQL(std::string& sqlQuery)
{
	std::ostringstream oss;
	if (this->m_current_db_cfg)
	{

		boost::posix_time::ptime begin(boost::posix_time::microsec_clock::local_time());

		try
		{

			tnode	*pNode  = NULL;
			int	nRet;

			//
			// Prepare
			TProjectSettings settings(*m_current_db_cfg->settings);
			std::string displayFile;

			//
			// generate ident and ini file
			std::string queryIdentStr = "";
			boost::uuids::uuid queryIdent = boost::uuids::random_generator()();
			std::ostringstream queryIdentOSS;
			queryIdentOSS << queryIdent;
			queryIdentStr = queryIdentOSS.str();
			settings.changeIdent(queryIdentOSS.str());

			//
			// create directories
			std::list<fs::path> lpaths;
			lpaths.push_back(fs::path(settings.szRootPath + "/calculus/" + queryIdentOSS.str()));
			lpaths.push_back(fs::path(settings.szTempPath1));
			lpaths.push_back(fs::path(settings.szTempPath2));
			for (std::list<fs::path>::const_iterator dir = lpaths.begin(); dir != lpaths.end(); ++dir)
			{
				std::ostringstream ossDirName;
				ossDirName << *dir;
				aq::Logger::getInstance().log(AQ_DEBUG, "create directory '%s'\n", ossDirName.str().c_str());

				if (fs::exists(*dir))
				{
					aq::Logger::getInstance().log(AQ_ERROR, "directory already exist '%s'\n", ossDirName.str().c_str());
					return;
				}

				if (!fs::create_directory(*dir))
				{
					aq::Logger::getInstance().log(AQ_ERROR, "cannot create directory '%s'\n", ossDirName.str().c_str());
					return;
				}

				aq::Logger::getInstance().log(AQ_DEBUG, "directory '%s' created\n", ossDirName.str().c_str());
			}

			//
			// write ini file (it is needed for now by AQEngine)
			std::ofstream iniFile(settings.iniFile.c_str());
			settings.writeAQEngineIni(iniFile);
			iniFile.close();

			// generate answer file
			displayFile = settings.szRootPath + "/calculus/" + queryIdentStr + "/display.txt"; // TODO
			aq::Logger::getInstance().log(AQ_INFO, "save answer to %s\n", displayFile.c_str());


			//
			// Parse SQL request
			aq::Logger::getInstance().log(AQ_INFO, "parse sql request %s\n", sqlQuery.c_str());
			if ((nRet = SQLParse(sqlQuery.c_str(), &pNode)) != 0 ) 
			{
				oss << "error parsing sql query '" << sqlQuery << "'" << std::endl;
				aq::Logger::getInstance().log(AQ_ERROR, oss.str().c_str());
				throw generic_error(generic_error::INVALID_QUERY, oss.str());
			}

			//
			// Transform SQL request in prefix form
			unsigned int id = 1;
      QueryResolver queryResolver(pNode, &settings, this->m_current_db_cfg->m_aq_engine, *this->m_current_db_cfg->baseDesc.get(), id);
			aq::Logger::getInstance().log(AQ_INFO, "execute query %s\n", sqlQuery.c_str());
			queryResolver.solve();

      //
      // Generate result file
      Table::Ptr result = queryResolver.getResult();
      if (result)
      {
        aq::Timer timer;
        result->saveToAnswer(settings.szAnswerFN, settings.fieldSeparator);
        aq::Logger::getInstance().log(AQ_INFO, "Save Answer: Time Elapsed = %s\n", aq::Timer::getString(timer.getTimeElapsed()).c_str());
        std::ofstream fresult(settings.szAnswerFN, std::ios::app);
        fresult << "EOS";
        fresult.close();
      }

			//
			// read result file and deliver on the socket
			aq::Logger::getInstance().log(AQ_DEBUG, "read answer file %s\n", settings.szAnswerFN);
			std::ifstream answerFile(settings.szAnswerFN);
//.........这里部分代码省略.........
开发者ID:TMA-AQ,项目名称:AlgoQuest,代码行数:101,代码来源:SyncSession.cpp


注:本文中的table::Ptr::saveToAnswer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。