本文整理汇总了C++中PropertiesPtr::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ PropertiesPtr::insert方法的具体用法?C++ PropertiesPtr::insert怎么用?C++ PropertiesPtr::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertiesPtr
的用法示例。
在下文中一共展示了PropertiesPtr::insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findAllProtocols
/**
* @brief gateway class for protocol table
*/
bool Protocol::findAllProtocols(DataSet<TextSerializer> & ds)
{
//Response should be :
//LEN REQUEST { REQUESTID=1 METHOD=getProtocol ARGS{PROTOCOLID=ALL} STATUS= [STATMESSAGE=]
// [RESULTSET { R1=(ID NAME TYPE VERSION ) R2=(ID NAME TYPE VERSION ) ... }] }
std::cout << "Entered findAllProtocols";
Connection* conn=Connection::getInstance();
ConnPtr dbHandle=conn->getConnection();
// execute the transaction
try {
// giving it a scope
{
if(! dbHandle)
{
ds.add<std::string>(req_, stat_, "false");
std::ostringstream oss;
oss << "Database connection not successful" <<std::endl;
ds.add<std::string>(req_, msg_, oss.str());
LOG_ERROR(oss.str());
return false;
}
pqxx::work w(*dbHandle);
pqxx::result R = w.exec("SELECT protocol_id,name,type,version FROM dbo.protocol where status=1 and rec_act=1 order by protocol_id");
//Check whether result is empty
if(R.empty())
{
ds.add<std::string>(req_, stat_, "true");
return true;
}
PropertiesPtr resultSet (new Properties());
int i=1;
for (pqxx::result::const_iterator r = R.begin();
r != R.end();
++r)
{
//name
StringsPtr record(new Strings());
record->push_back(r[1].c_str());
//type
record->push_back(r[2].c_str());
//version
record->push_back(r[3].c_str());
//ID
record->push_back(r[0].c_str());
std::ostringstream ostr;
ostr << "r" << i;
resultSet->insert(std::make_pair(ostr.str(), record));
i++;
}
ds.add<PropertiesPtr>("REQUEST", "RESULTSET", resultSet);
}
ds.add<std::string>(req_, stat_, "true");
return true;
}
catch(pqxx::broken_connection& e)
{
std::ostringstream oss;
oss << "Connection to database broken try again" <<std::endl;
ds.add<std::string>(req_, stat_, "false");
ds.add<std::string>(req_, msg_, oss.str());
LOG_ERROR(oss.str());
return false;
}
catch(pqxx::sql_error& e)
{
std::ostringstream oss;
oss << e.what() << std::endl;
ds.add<std::string>(req_, stat_, "false");
ds.add<std::string>(req_, msg_, std::string(e.what()));
LOG_ERROR(oss.str());
return false;
}
catch(...)
{
std::ostringstream oss;
oss << "Unknown error while inserting"
<< std::endl;
ds.add<std::string>(req_, stat_, "false");
ds.add<std::string>(req_, msg_, oss.str());
LOG_ERROR(oss.str());
return false;
}
//.........这里部分代码省略.........
示例2: w
bool Message :: findAllMessages(DataSet<TextSerializer> &ds)
{
//Response should be :
//LEN REQUEST { REQUESTID=1 METHOD=getMessage ARGS{PROTOCOLID=ALL MESSAGEID=ALL} STATUS= [STATMESSAGE=]
// [RESULTSET { R1=(PROTOCOLID MESSAGEID PROTOCOL MDESCRIPTION ) R2=(PROTOCOLID MESSAGEID PROTOCOL MDESCRIPTION ) ... }] }
std::cout << "Entered findAllMessages";
// extract pertinent values from Dataset
std::string query;
std::string* protId = NULL;
protId = ds.get<std::string>(args_, protocolId_);
if(! protId)
{
ds.add<std::string>(req_, stat_, "false");
std::ostringstream oss;
oss << "PROTOCOLID not found in the request" <<std::endl;
ds.add<std::string>(req_, statMsg_, oss.str());
LOG_ERROR(oss.str());
return false;
}
else
{
/* If ProtocolID is "ALL" then fetch all the messages of ALL the protocols*/
if( strcmp((*protId).c_str(), "ALL") == 0 )
{
query = "SELECT M.protocol_msg_id, M.protocol_id, P.name, M.name, M.descr From dbo.protocol_message M, dbo.protocol P"
" WHERE M.protocol_id = P.Protocol_id"
" AND M.rec_act = 1 AND M.status = 1"
" Order by P.name, M.name";
}
/* If ProtocolID is not "ALL" then fetch all the messages for the particular protocol */
else
{
query = "SELECT M.protocol_msg_id, M.protocol_id, P.name, M.name, M.descr From dbo.protocol_message M, dbo.protocol P"
" WHERE M.protocol_id = P.Protocol_id"
" AND P.Protocol_id = '" + *protId +
"' AND M.rec_act = 1 AND M.status = 1"
" Order by P.name, M.name";
}
}
std::cout << "query = "<< query << std::endl;
Connection* conn=Connection::getInstance();
ConnPtr dbHandle=conn->getConnection();
// execute the transaction
try {
// giving it a scope
{
if(! dbHandle)
{
ds.add<std::string>(req_, stat_, "false");
std::ostringstream oss;
oss << "Database connection not successful" <<std::endl;
ds.add<std::string>(req_, statMsg_, oss.str());
LOG_ERROR(oss.str());
return false;
}
pqxx::work w(*dbHandle);
pqxx::result R = w.exec(query);
//Check whether result is empty
if(R.empty())
{
ds.add<std::string>(req_, stat_, "true");
return true;
}
PropertiesPtr resultSet (new Properties());
int i=1;
for (pqxx::result::const_iterator r = R.begin();
r != R.end();
++r)
{
StringsPtr record(new Strings());
record->push_back(r[2].c_str());
record->push_back(r[0].c_str());
record->push_back(r[1].c_str());
record->push_back(r[3].c_str());
record->push_back(r[4].c_str());
std::ostringstream ostr;
ostr << "r" << i;
resultSet->insert(std::make_pair(ostr.str(), record));
i++;
}
ds.add<PropertiesPtr>("REQUEST", "RESULTSET", resultSet);
}
//.........这里部分代码省略.........