Beispiel #1
0
int main(int argc, char **argv)
{
    DBConnection connection;
    string input = "select * from emp;";
    connection.executeYourQuery(input);
    return 0;
}
void ModelExportHelper::undoDBMSExport(DatabaseModel *db_model, DBConnection &conn)
{
 QString drop_cmd=QString("DROP %1 %2;");
 ObjectType types[]={OBJ_ROLE, OBJ_TABLESPACE};
 int type_id;
 BaseObject *object=nullptr;

 //In case of error during the export all created object are removed
 if(db_created || created_objs[OBJ_ROLE] >= 0 || created_objs[OBJ_TABLESPACE] >= 0)
 {
	 //Dropping the database
	 if(db_created)
		 conn.executeDDLCommand(drop_cmd.arg(db_model->getSQLName()).arg(db_model->getName(true)));

	 //Drop the roles / tablespaces created
	 for(type_id=1; type_id >=0; type_id--)
	 {
		 while(created_objs[types[type_id]] >= 0)
		 {
			 object=db_model->getObject(created_objs[types[type_id]], types[type_id]);

			 try
			 {
				 conn.executeDDLCommand(drop_cmd.arg(object->getSQLName()).arg(object->getName(true)));
			 }
			 catch(Exception &e){}

			 created_objs[types[type_id]]--;
		 }
	 }
 }
}
int main()
{
	try
	{
		clock_t tStart = clock();

		readConfFile();
		cout<<"Started the program\n";
		//cout<<tabIndex;

		DBConnection *squidLog = new DBConnection();
		squidLog->dbConnOpen("127.0.0.1","3306","root","simple","squid");

		string logReadQuery = "select * from access_log_new where id > ?;";
		PreparedStatement *pstm = squidLog->conn->prepareStatement(logReadQuery);
		pstm->setInt(1,tabIndex);
		squidLog->res = pstm->executeQuery();


	/*DBConnection *squidLog = new DBConnection();
	squidLog->dbConnOpen("127.0.0.1","3306","root","simple","squid");

	squidLog->tableName = "access_log";
	squidLog->setReadPstmt(1,squidLog->tableName,"","");
	squidLog->readTable();*/


		statLog = new DBConnection();
		createStatistics(squidLog,statLog);


	/*grossStatisticsAcc(statLog->tableNameAcc);
	grossStatisticsDen(statLog->tableNameDen);
	createDomainStatisticsAcc(statLog->tableNameAcc);
	createUserStatisticsAcc(statLog->tableNameAcc);
	createDomainStatisticsDen(statLog->tableNameDen);
	createUserStatisticsDen(statLog->tableNameDen);*/

		writeConfFile();
		printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
		cout<<"End Of program \n";

	}
	catch (sql::SQLException &e)
	{
		cout << "# ERR: SQLException in " << __FILE__;
		cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
		cout << "# ERR: " << e.what();
		cout << " (MySQL error code: " << e.getErrorCode();
		cout << ", SQLState: " << e.getSQLState() << " )" << endl;
	}
	catch (exception& e)
	{
		cout << "# ERR File: " << __FILE__;
		cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
	    cout << e.what() << '\n';
	}
		return 0;
}
Beispiel #4
0
QSqlDatabase* DBAcccessSafe::getDB()
{
    ConnectionManager& manager = ConnectionManager::getInstance();
    if ( manager.getManagerStatus() == ConnectionManager::STATE_OK )
    {
        DBConnection* conn = manager.getDB(m_iDBID);
        return conn->get();
    };
    //
    return NULL;
};
Beispiel #5
0
common::Error CommandsApi::Merge(internal::CommandHandler* handler, commands_args_t argv, FastoObject* out) {
  DBConnection* rocks = static_cast<DBConnection*>(handler);
  common::Error err = rocks->Merge(argv[0], argv[1]);
  if (err) {
    return err;
  }

  common::StringValue* val = common::Value::CreateStringValue("OK");
  FastoObject* child = new FastoObject(out, val, rocks->GetDelimiter());
  out->AddChildren(child);
  return common::Error();
}
Beispiel #6
0
  ExitCodes main_(int, const char **)
  {

    //-------------------------------------------------------------
    // parameter handling
    //-------------------------------------------------------------

    //varaibles
    String db, user, password, host, in;
    Int port;

    bool init = getFlag_("init");
    if (!init)
    {
      in = getStringOption_("in");
    }

    db = getStringOption_("db");
    user = getStringOption_("user");
    password = getStringOption_("password");
    host = getStringOption_("host");
    port = getIntOption_("port");

    //-------------------------------------------------------------
    // reading input
    //-------------------------------------------------------------
    DBConnection con;
    con.connect(db, user, password, host, port);
    DBAdapter a(con);

    if (init)
    {
      a.createDB();
    }
    else
    {
      //load input file data
      MSExperiment<Peak1D> exp;
      MzMLFile f;
      f.setLogType(log_type_);
      f.load(in, exp);

      //annotate output with data processing info
      addDataProcessing_(exp, getProcessingInfo_(DataProcessing::FORMAT_CONVERSION));

      //store data
      a.storeExperiment(exp);

      writeLog_(String(" written file to DB (id: ") + (double)(exp.getPersistenceId()) + ")");
    }

    return EXECUTION_OK;
  }
Beispiel #7
0
common::Error CommandsApi::Info(internal::CommandHandler* handler, commands_args_t argv, FastoObject* out) {
  DBConnection* mdb = static_cast<DBConnection*>(handler);
  ServerInfo::Stats statsout;
  common::Error err = mdb->Info(argv.size() == 1 ? argv[0] : std::string(), &statsout);
  if (err) {
    return err;
  }

  common::StringValue* val = common::Value::CreateStringValue(ServerInfo(statsout).ToString());
  FastoObject* child = new FastoObject(out, val, mdb->GetDelimiter());
  out->AddChildren(child);
  return common::Error();
}
Beispiel #8
0
common::Error CommandsApi::DropDatabase(internal::CommandHandler* handler, commands_args_t argv, FastoObject* out) {
  UNUSED(argv);
  DBConnection* mdb = static_cast<DBConnection*>(handler);
  ServerInfo::Stats statsout;
  common::Error err = mdb->DropDatabase();
  if (err) {
    return err;
  }

  common::StringValue* val = common::Value::CreateStringValue("OK");
  FastoObject* child = new FastoObject(out, val, mdb->GetDelimiter());
  out->AddChildren(child);
  return common::Error();
}
void ConnectionsConfigWidget::testConnection(void)
{
	DBConnection conn;
	MessageBox msg_box;

	try
	{
		this->configurarConexao(&conn);
		conn.connect();
		msg_box.show(trUtf8("Success"), trUtf8("Connection successfuly stablished!"), MessageBox::INFO_ICON);
	}
	catch(Exception &e)
	{
		throw Exception(e.getErrorMessage(),e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
	}
}
Beispiel #10
0
common::Error CommandsApi::Info(internal::CommandHandler* handler,
                                int argc,
                                const char** argv,
                                FastoObject* out) {
  DBConnection* mdb = static_cast<DBConnection*>(handler);
  ServerInfo::Stats statsout;
  common::Error err = mdb->Info(argc == 1 ? argv[0] : nullptr, &statsout);
  if (err && err->isError()) {
    return err;
  }

  common::StringValue* val = common::Value::createStringValue(ServerInfo(statsout).ToString());
  FastoObject* child = new FastoObject(out, val, mdb->Delimiter());
  out->AddChildren(child);
  return common::Error();
}
// transact with the current active account and profile
void TransactionMenu(){
	
	if(ActiveAccountID < 1){
		cout << "No active account has been selected.";
		return;
	}

	if(ActiveUserID < 1){
		cout << "No active profile has been selected.";
		return;
	}

	stringstream AAID(""); // active account id
	stringstream AUID(""); // active user id

	AAID << ActiveAccountID;
	AUID << ActiveUserID;

	if(DB.FieldExists(USER_TABLE, "UserID", (char*)AUID.str().c_str()) == false){
		ActiveUserID = -1;
		cout << "User ID selected does not exist.";
		return;
	}
	else if(DB.FieldExists(ACCOUNT_TABLE, "AcctID", (char*)AAID.str().c_str()) == false){
		ActiveAccountID = -1;
		cout << "Account ID selected does not exist.";
		return;
	}

	string MenuOptions[] = {
		"exit this menu",
		"add money",
		"withdraw money",
		"view transactions"
	};

	switch(Menu(MenuOptions, "Transactions Menu")){
		case 0: return;
		case 1:  TransactAmount(true); break;
		case 2:  TransactAmount(false); break;
		case 3:  ViewTransactions(); break;
		default: return;
	}
}
void ReportMenu(){
	if(ActiveAccountID < 1){
		cout << "No active account has been selected.";
		return;
	}

	if(ActiveUserID < 1){
		cout << "No active profile has been selected.";
		return;
	}

	stringstream AAID(""); // active account id
	stringstream AUID(""); // active user id

	AAID << ActiveAccountID;
	AUID << ActiveUserID;

	if(DB.FieldExists(USER_TABLE, "UserID", (char*)AUID.str().c_str()) == false){
		ActiveUserID = -1;
		cout << "User ID selected does not exist.";
		return;
	}
	else if(DB.FieldExists(ACCOUNT_TABLE, "AcctID", (char*)AAID.str().c_str()) == false){
		ActiveAccountID = -1;
		cout << "Account ID selected does not exist.";
		return;
	}

	string MenuOptions[] = {
		"exit this menu",
		"view all",
		"view last 24 hours",
		"view last 7 days"
	};

	switch(Menu(MenuOptions, "Transactions Menu")){
		case 0: return;
		case 1:  ViewReport(); break;
		case 2:  ViewReport(86400); break;
		case 3:  ViewReport(604800); break;
		default: return;
	}
}
// delete a profile
void DeleteProfile(){
	TableDataSet NewDataSet;
	
	stringstream is("");
	ViewProfiles();
	
	is << GetUserInput("Select an ID to delete", DB.GetMaxField(USER_TABLE, "UserID"));
	
	if(!validate::string::numeric(is.str())){
		cout << "invalid id";
		return;
	}

	NewDataSet.push_back(make_pair("UserID", is.str().c_str()));
	
	DB.Delete(USER_TABLE, NewDataSet);
	
	ActiveUserID=-1;
}
Beispiel #14
0
void test2()
{
    DBMysqlConnectionPool pool("mysql://*****:*****@localhost:3306/test");
    //DBMysqlConnectionPool pool("mysql://*****:*****@172.16.5.1:3306/test");
    if (!pool.init())
        return;

    DBConnection* conn = pool.get(DBCS_PREPARING);
    if (!conn)
        return;

    DBObject a;
    //conn->prepare("select * from one", a);
    conn->prepare("select * from one", a);
    while (!conn->next())
    {
        printf("%d\n", a.c);
    }

    printf("---------------------------------\n");
    pool.put(conn);
}
// delete an account
void DeleteAccount(){
	
	TableDataSet NewDataSet;
	
	stringstream is("");
	
	ViewAccounts();
	
	is << GetUserInput("Select an ID to delete", DB.GetMaxField(ACCOUNT_TABLE, "AcctID"));
	
	NewDataSet.push_back(make_pair("AcctID", is.str()));
	DB.Delete(ACCOUNT_TABLE, NewDataSet);
	
	// delete transactions matching this user and account id
	TableDataSet TransactionTableDataSet;
	stringstream AAID(""); // active account id
	stringstream AUID(""); // active user id

	AAID << ActiveAccountID;
	AUID << ActiveUserID;

	if(DB.FieldExists(USER_TABLE, "UserID", (char*)AUID.str().c_str()) == false){
		ActiveUserID = -1;
		cout << "User ID selected does not exist.";
		return;
	}
	else if(DB.FieldExists(ACCOUNT_TABLE, "AcctID", (char*)AAID.str().c_str()) == false){
		ActiveAccountID = -1;
		cout << "Account ID selected does not exist.";
		return;
	}
	
	TransactionTableDataSet.push_back(make_pair("AcctID", AAID.str().c_str()));
	TransactionTableDataSet.push_back(make_pair("UserID", AUID.str().c_str()));

	DB.Delete(TRANSACTION_TABLE, TransactionTableDataSet);

	ActiveAccountID = -1;
}
Beispiel #16
0
common::Error CommandsApi::Mget(internal::CommandHandler* handler, commands_args_t argv, FastoObject* out) {
  DBConnection* rocks = static_cast<DBConnection*>(handler);
  std::vector<std::string> keysget;
  for (size_t i = 0; i < argv.size(); ++i) {
    keysget.push_back(argv[i]);
  }

  std::vector<std::string> keysout;
  common::Error err = rocks->Mget(keysget, &keysout);
  if (err) {
    return err;
  }

  common::ArrayValue* ar = common::Value::CreateArrayValue();
  for (size_t i = 0; i < keysout.size(); ++i) {
    common::StringValue* val = common::Value::CreateStringValue(keysout[i]);
    ar->Append(val);
  }
  FastoObject* child = new FastoObject(out, ar, rocks->GetDelimiter());
  out->AddChildren(child);
  return common::Error();
}
// select an account to be the active account
void SelectActiveAccount(){
	ViewAccounts();
	int maxID = DB.GetMaxField(ACCOUNT_TABLE, "AcctID");
	int selID = GetUserInput("Select an account ID", maxID);
	stringstream is("");
	is<<selID;
	if(!validate::string::numeric(is.str())){
		cout << "invalid id";
		return;
	}
	ActiveAccountID=selID;
	cout << "Active account selected.";
	return;
}
// select the profile to be the active profile
void SelectActiveProfile(){
	ViewProfiles(); 
	int maxID = DB.GetMaxField(USER_TABLE, "UserID");
	int selID = GetUserInput("Select a profile ID", maxID);
	stringstream is("");
	is<<selID;
	if(!validate::string::numeric(is.str())){
		cout << "invalid id";
		return;
	}
	ActiveUserID=selID;
	cout << "Active profile selected.";
	return;
}
// view transactions for the current account id and user id
void ViewTransactions(){

	TableDataSet TransactionTableDataSet;
	stringstream AAID(""); // active account id
	stringstream AUID(""); // active user id

	AAID << ActiveAccountID;
	AUID << ActiveUserID;

	if(!validate::string::numeric(AAID.str())){
		cout << "invalid  account id";
		return;
	}

	if(!validate::string::numeric(AUID.str())){
		cout << "invalid user id";
		return;
	}

	if(DB.FieldExists(USER_TABLE, "UserID", (char*)AUID.str().c_str()) == false){
		ActiveUserID = -1;
		cout << "User ID selected does not exist.";
		return;
	}
	else if(DB.FieldExists(ACCOUNT_TABLE, "AcctID", (char*)AAID.str().c_str()) == false){
		ActiveAccountID = -1;
		cout << "Account ID selected does not exist.";
		return;
	}

	
	TransactionTableDataSet.push_back(make_pair("AcctID", AAID.str().c_str()));
	TransactionTableDataSet.push_back(make_pair("UserID", AUID.str().c_str()));

	DB.ShowTable(TRANSACTION_TABLE, TransactionTableDataSet, 2);
}
int main() {
  DBConnection<Countable>* db =
    DBConnection<Countable>::create("MyDatabase");
  assert(db->refCount() == 1);
  DBClient c1(db);
  assert(db->refCount() == 2);
  DBClient c2(db);
  assert(db->refCount() == 3);
  db->detach();
  assert(db->refCount() == 2);
} ///:~
Beispiel #21
0
int main() {
  DBConnection* db = DBConnection::create("MyDatabase");
  assert(db->refCount() == 1);
  DBClient c1(db);
  assert(db->refCount() == 2);
  DBClient c2(db);
  assert(db->refCount() == 3);
  // Use database, then release attach from original create
  db->detach();
  assert(db->refCount() == 2);
} ///:~
void ViewReport(int seconds){
	
	TableDataSet TransactionTableDataSet;
	
	stringstream AAID(""); // active account id
	stringstream AUID(""); // active user id
	stringstream  SECS("");

	AAID << ActiveAccountID;
	AUID << ActiveUserID;
	SECS << (time(0)-seconds);

	TransactionTableDataSet.push_back(make_pair("AcctID", AAID.str().c_str()));
	TransactionTableDataSet.push_back(make_pair("UserID", AUID.str().c_str()));
	TransactionTableDataSet.push_back(make_pair(" TransDate >", SECS.str().c_str())); 

	DB.ShowTable(TRANSACTION_TABLE, TransactionTableDataSet, 2);
}
// get user prompts for table fields and add a new row
// to a table, with an auto-incremented id. 
void CreateInTable(TableDefinition Def, char* Table, char* key){
	
	string name, val;
	
	DB.UseTableDefinition(Def);
	//cout << "key: " << key;

	TableRow Columns = DB.GetColumnsForTable(Table); // get all the columns
	TableDataSet NewDataSet;

	for(unsigned int i=0; i<Columns.size(); i++){

		if(Columns[i] == key){
		 
			 int maxID = DB.GetMaxField(Table, key);
			 int newID = maxID+1;

			 stringstream ID("");
			 ID << newID;

			 NewDataSet.push_back(make_pair(key, (char*)ID.str().c_str()));
		}
		else{

			cout << Columns[i] << ": ";
		
			getline(cin, val);
		
			FieldDefinition WorkingFieldDefinition = DB.GetFieldDefinition((char*)Columns[i].c_str());

			if((WorkingFieldDefinition.getLength() > 0) && (WorkingFieldDefinition.Validate((char*)val.c_str()))){
				NewDataSet.push_back(make_pair(Columns[i],val));
			}
			else{
				cout << "validation failed for the field " << WorkingFieldDefinition.getName();
				return;
			}
		}
	}

	DB.Create(Table, NewDataSet);
	DB.ShowTable(Table, NewDataSet);
	return;
}
Beispiel #24
0
void test3()
{
    DBMysqlConnectionPool pool("mysql://*****:*****@localhost:3306/test");
    if (!pool.init())
        return;

    DBConnection* conn = pool.get(DBCS_PREPARING);
    if (!conn)
        return;

    DBObject14 a;
    if (!conn->prepare("select *,unix_timestamp(t) from test", a))
    {
        while (!conn->next())
        {
            //printf("a.m.size(): %lu\n", a.m.size());
            //printf("a.n.rsize(): %d\n", a.n.rsize());
            printf("%lu,%d,%d,%d,%d,%d,%d,%lld,%lld,%f,%f,%f,%s,%s(%d)\n", a.tt,a.c,a.d,a.e,a.f,a.g,a.h,a.i,a.j,a.k,a.kk,a.l,&a.m[0],a.n.rbuf(),a.n.rsize());
        }
    }

    printf("---------------------------------\n");
#if 1
    conn->finish();
    DBObject14 b;
    if (!conn->prepare("select *,unix_timestamp(t) from test", b))
    {
        while (!conn->next())
        {
            printf("%lu,%d,%d,%d,%d,%d,%d,%lld,%lld,%f,%f,%f,%s,%s(%d)\n", b.tt,b.c,b.d,b.e,b.f,b.g,b.h,b.i,b.j,b.k,b.kk,b.l,&b.m[0],b.n.rbuf(),b.n.rsize());
        }
    }
#endif

    conn->finish();
    pool.put(conn);


}
Beispiel #25
0
void main()
{
	odbcConf* oc = new odbcConf("config.txt");
	oc->configRead();
	DBConnection::connect_option co;
	co.connection_autocommt = SQL_AUTOCOMMIT_OFF;
	co.connection_timeout = 10000;
	co.login_timeout = 10000;
	DBConnection::stmt_option so;
	so.async_enable = SQL_ASYNC_ENABLE_OFF;
	so.cusor_type = SQL_CURSOR_FORWARD_ONLY;
	so.query_timeout = 10000;
	DBConnection* dbc = new DBConnection(oc->getConnStr().c_str(), so,co);
	//std::cout<<dbc->checkConnectionState()<<std::endl;
	OdbcDataMap* dm = new OdbcDataMap();
    dbc->executeQuery("select * from t1",dm);
	dbc->close();
	delete(oc);
	delete(dbc);
	while (dm->hasNext())
	{
		std::cout<<dm->getString("name")<<" "<<dm->getString("birthday")<<std::endl;
		TIME_STRUCT time = dm->getTime("birthday");
		DATE_STRUCT date = dm->getDate("birthday");
        int age = dm->getInt("age");
		std::string name = dm->getString("name");
		dm->next();
	}
	delete(dm);
	DBCPool* pool = new DBCPool("config.txt");
	DBConnection* c = pool->getConnection();
	OdbcDataMap* dm2 = new OdbcDataMap();
	c->executeQuery("select * from t2",dm2);
	c->close();
	while (dm2->hasNext())
	{
		std::cout<<dm2->getString("name")<<" "<<dm2->getString("tdate")<<std::endl;
		dm2->next();
	}
	
	system("pause");
}
// add a transaction to the table.
void TransactAmount(bool isCredit){

	if(isCredit){
		cout << "Deposit" << endl;
	}
	else{
		cout << "Withdraw" << endl;
	}

	stringstream AAID(""); // active account id
	stringstream AUID(""); // active user id
	stringstream TNUM(""); // transaction number
	stringstream TAMT(""); // transaction amount
	stringstream DATE(""); // timestamp
	stringstream NBAL(""); // updated balance

	// create a new transaction id
	int TransNum = DB.GetMaxField(TRANSACTION_TABLE, "TransNum");
	int newTransNum = TransNum+1;

	// get the transaction amount
	double transAmt = GetUserInput("Enter Transaction Amount", INT_MAX);

	stringstream sM("");
	sM << transAmt;

	// validation. Minimal validation. Better than nothing.

	if(!validate::string::money(sM.str())){
		cout << "that does not appear to be a valid monetary amount.";
		return;
	}
	
	AAID << ActiveAccountID;
	AUID << ActiveUserID;

	if(!validate::string::numeric(AAID.str())){
		ActiveAccountID = -1;
		cout << "The account id is invalid. " << endl;
		return;
	}

	if(!validate::string::numeric(AUID.str())){
		ActiveUserID = -1;
		cout << "the user id is invalid. " << endl;
		return;
	}

	stringstream clause("");
	
	// this is terrible, but it works. 
	clause << " UserID = '" << ActiveUserID << "' and AcctID = '" << ActiveAccountID << "' ";
	
	double exSum = DB.GetSumField(TRANSACTION_TABLE, "TransAmount", (char*)clause.str().c_str());
	
	TNUM << newTransNum;
	
	DATE << time(0);

	if(isCredit){
		TAMT << transAmt;
		NBAL << (exSum+transAmt);
	}
	else{
		TAMT << "-" << transAmt;
		NBAL << (exSum-transAmt);
	}
	
	TableDataSet NewDataSet;
	NewDataSet.push_back(make_pair("AcctID",      AAID.str().c_str()));
	NewDataSet.push_back(make_pair("UserID",      AUID.str().c_str()));
	NewDataSet.push_back(make_pair("TransNum",    TNUM.str().c_str()));
	NewDataSet.push_back(make_pair("TransAmount", TAMT.str().c_str()));
	NewDataSet.push_back(make_pair("TransDate",   DATE.str().c_str()));
	NewDataSet.push_back(make_pair("Balance",     NBAL.str().c_str()));
	
	DB.Create(TRANSACTION_TABLE, NewDataSet);
	DB.ShowTable(TRANSACTION_TABLE, NewDataSet, 2); 
} 
void ViewAccounts(){
	DB.ShowTable(ACCOUNT_TABLE,  DB.GetColumnsForTable(ACCOUNT_TABLE));
	cout << endl;
}
void ViewProfiles(){
	DB.ShowTable(USER_TABLE,  DB.GetColumnsForTable(USER_TABLE));
	cout << endl;
}
bool StartLineProcessCollector::collect(MONITORING::leaseProcessStart *sample, StartLineProcessConnector *conn) {

    if (NULL == sample) {
        g_cSystemLogger.LogMessage("(%s:%s:%d):: sample is NULL \n  \n ", LOG_LOCATION);
        return false;
    }
    
    int i=0;
    ItrServerDetails  serIter;
    lineDetails ld;
    g_cSystemLogger.LogMessage("(%s:%s:%d)::cancelid %d \n ", LOG_LOCATION,sample->ip_info[i].CancelOrderId);
    if(sample->ip_info[i].CancelOrderId!=0)
    {
    char buf[50]={0};
    char recvbuf[512]={0};
    int recvLen;
    g_cSystemLogger.LogMessage("(%s:%s:%d):: size of order vector %d \n ",LOG_LOCATION,conn->orderIds.size());
    for(i=0;i<conn->orderIds.size();i++)
    {
   
	//g_cSystemLogger.LogMessage("(%s:%s(:%d)::Inside CancelOrder %d \n", LOG_LOCATION,sample->ip_info[i].CancelOrderId);
        int pos;
        int j;
	pos+=sprintf(buf+5,"%s%d%s","#",conn->orderIds[i],"#");
        g_cSystemLogger.LogMessage("(%s:%s(:%d)::order length %d buf %s \n", LOG_LOCATION,pos,buf);
        char c='0';
        for(j=0;j<=3;j++)
        {
        buf[j]=c;
	//g_cSystemLogger.LogMessage("(%s:%s(:%d)::Inside CancelOrder buf %c \n", LOG_LOCATION,buf[j]);
        }
	char p=(char)(((int)'0')+pos);
        buf[j]=p;
        g_cSystemLogger.LogMessage("(%s:%s(:%d)::Inside CancelOrder buf %s socketId %d \n", LOG_LOCATION,buf,CControllerThread::getInstance()->socketId);
        if(recvLen==write(CControllerThread::getInstance()->socketId,buf,sizeof(buf)))
        {
	   g_cSystemLogger.LogMessage("(%s:%s(:%d)::writeLen %d \n", LOG_LOCATION,recvLen);
           //CControllerThread::getInstance()->makeSocketConnection();
        }
        g_cSystemLogger.LogMessage("(%s:%s(:%d)::write sucessfull writeLen %d \n", LOG_LOCATION,recvLen);

	if(recvLen=recv(CControllerThread::getInstance()->socketId,recvbuf,sizeof(recvbuf),0)<0)
        {
	 g_cSystemLogger.LogMessage("(%s:%s(:%d)::Recv Error \n", LOG_LOCATION);
	}
	g_cSystemLogger.LogMessage("(%s:%s(:%d)::RecvLen %d recvbuf %s \n", LOG_LOCATION,recvLen,recvbuf);
        strncpy(ld.CancelOrderStatus,recvbuf,sizeof(recvbuf)); 
	CcopyStructure::copyCommandData(ld, ld.line_count);
	memset(buf,0,sizeof(buf));
        pos=0;
	sleep(1);
    }
    return true;

   }

else
{
    for(i=0;i<sample->ip_info.length();i++)
{ 
    if(strcmp(sample->ip_info[i].ipadress,"")==0)
 	break;
    LIBSSH2_CHANNEL *channel2;
    LIBSSH2_SESSION *session;
    char* userName;
    char* passWord;
    struct sockaddr_in sin;
    int rc, sock, auth_pw = 0;
    char *exitsignal = (char *) "none";
    size_t lnReturnCode;
    char command[12324] = {0};
    char processes[8024] = {0};

    char *lpUserAuthList;
    g_cSystemLogger.LogMessage("(%s:%s:%d):: Debug", LOG_LOCATION);
    rc = libssh2_init(0);
    
    strcpy(ld.ipadress,sample->ip_info[i].ipadress);
    g_cSystemLogger.LogMessage("(%s:%s:%d)::Sequence Length %d ipadress %s,and psl %s  cancelOrderId %d value of i %d \n", LOG_LOCATION, sample->ip_info._length,sample->ip_info[i].ipadress,sample->ip_info[i].psl,sample->ip_info[i].CancelOrderId,i);
    sock = socket(AF_INET, SOCK_STREAM, 0);

    sin.sin_family = AF_INET;
    sin.sin_port = htons(22);
    sin.sin_addr.s_addr = inet_addr(sample->ip_info[i].ipadress);
    if (connect(sock, (struct sockaddr*) (&sin),
            sizeof (struct sockaddr_in)) != 0) {
        g_cSystemLogger.LogMessage("(%s:%s(:%d)::failure establishing ssh", LOG_LOCATION);
        return -1;
    }

    session = libssh2_session_init();
    if (libssh2_session_handshake(session, sock)) {
        g_cSystemLogger.LogMessage("(%s:%s(:%d):: failure ssh session initiation", LOG_LOCATION);


    }
   /* if((strcmp(sample->ip_info[i].ipadress,"192.168.30.32")==0)|| (strcmp(sample->ip_info[i].psl,"192.168.30.231")==0))
    {
        userName = "******";
        passWord = "******"; 
    }
    else*/
    
         userName = "******";
         passWord = "******"; 
    
    lpUserAuthList = libssh2_userauth_list(session, userName, strlen(userName));

    if (NULL == lpUserAuthList) {
        g_cSystemLogger.LogMessage("(%s:%s(:%d):: get user auth list failed", LOG_LOCATION);

    }
    char lcPreferredAuthMethod[20] = "password";
    g_cSystemLogger.LogMessage("(%s:%s(:%d)::authentication methods(%s)", LOG_LOCATION, lpUserAuthList);
    if (strstr(lpUserAuthList, lcPreferredAuthMethod) != NULL) {
        auth_pw |= 1;
        g_cSystemLogger.LogMessage("(%s:%s(:%d)::authentication methods(%d)", LOG_LOCATION, auth_pw);
    }
    if (auth_pw & 1) {
        if (libssh2_userauth_password(session, userName, passWord)) {
            g_cSystemLogger.LogMessage("(%s:%s(:%d)::Authentation by password failed\n", LOG_LOCATION);
        }

        else {
            g_cSystemLogger.LogMessage("(%s:%s(:%d)::Authentation by mint succesded\n", LOG_LOCATION);
        }

    }

    while ((channel2 = libssh2_channel_open_session(session)) == NULL &&
            libssh2_session_last_error(session, NULL, NULL, 0) == LIBSSH2_ERROR_EAGAIN) {
        waitsocket(sock, session);
    }

    if (channel2 == NULL) {
        g_cSystemLogger.LogMessage("(%s:%s(:%d))ssh channel opening fail", LOG_LOCATION);
    }
   
    if(strcmp(sample->ip_info[i].psl,"Process")==0)
    {
       
    g_cSystemLogger.LogMessage("(%s:%s(:%d)) Inside Process", LOG_LOCATION);
    for(serIter=conn->getServerInfo().begin();serIter!=conn->getServerInfo().end();serIter++)
    {  
        g_cSystemLogger.LogMessage("(%s:%s(:%d)) ipadress from iter %s", LOG_LOCATION,serIter->ipAdress);
        tagServerInfo &tagServ = *serIter;
        g_cSystemLogger.LogMessage("(%s:%s(:%d)) ipadress from tagserver %s sampeip %s \n", LOG_LOCATION,tagServ.ipAdress,sample->ip_info[i].ipadress);

        if(strcmp(tagServ.ipAdress,sample->ip_info[i].ipadress)==0)
        {
            int pos=0;
            g_cSystemLogger.LogMessage("(%s:%s(:%d)) tagServ %s sample %s processLen %d \n", LOG_LOCATION,tagServ.ipAdress,sample->ip_info[i].ipadress,tagServ.noOfProcess);
            for(int j=1;j<tagServ.noOfProcess;j++)
            {
            g_cSystemLogger.LogMessage("(%s:%s(:%d)) Process %s \n", LOG_LOCATION,tagServ.processes[j].name);
            if(j==(tagServ.noOfProcess-1))
            {
            sprintf(processes+pos,tagServ.processes[j].name);
            }
            else
            {
            pos+=sprintf(processes+pos,"%s%s",tagServ.processes[j].name,"|");
          
            }
            }
            sprintf(command,"%s %s%s%s%s %s%s%s%s","ps -ef | egrep -v ","\"", "egrep|vi|tail|cat|emacs|more|nohup","\"" ,"| egrep","\"",processes,"\"","| grep -v daemon");
            g_cSystemLogger.LogMessage("(%s:%s(:%d)) command %s", LOG_LOCATION,command);
            
            while ((rc = libssh2_channel_exec(channel2, command)) == LIBSSH2_ERROR_EAGAIN) {
            waitsocket(sock, session);
            
            
        }
           lnReturnCode = libssh2_channel_read(channel2, command, sizeof (command));
           g_cSystemLogger.LogMessage("(%s:%s(:%d)) lnReturnCode %d command %s", LOG_LOCATION,lnReturnCode,command);
           strncpy(ld.processInfo,command,sizeof(command));
            memset(command, 0, sizeof (command));
            libssh2_channel_free(channel2);
            channel2 = NULL; 
        }     
    }
    }
    
    else if((strcmp(sample->ip_info[i].psl,"Space"))==0)
    {
       while ((rc = libssh2_channel_exec(channel2, "df -kh |grep -v grep")) == LIBSSH2_ERROR_EAGAIN) {
            waitsocket(sock, session);
            
        }
        lnReturnCode = libssh2_channel_read(channel2, command, sizeof (command));
        g_cSystemLogger.LogMessage("(%s:%s(:%d)lnReturnCode %d command after executing %s\n", LOG_LOCATION, lnReturnCode, command);
        strcpy(ld.spaceInfo,command);
        memset(command, 0, sizeof (command));
        libssh2_channel_free(channel2);
        channel2 = NULL;
    }
    
    else if((strcmp(sample->ip_info[i].psl,"Line"))==0)
    {
        
        DBConnection lDBConnectionObject;
        char* dbUserName = "******";
        char* dbPassWord = "******";
        char* dbName = "mani";
        char* dbPort = "5432";
        if(0==lDBConnectionObject.getFoPiQueryResult(dbUserName,dbPassWord,dbName,dbPort,sample->ip_info[i].ipadress,ld))
        {
            g_cSystemLogger.LogMessage("(%s:%s(:%d) Failed DB query \n", LOG_LOCATION);
        }
        
        g_cSystemLogger.LogMessage("(%s:%s(:%d) LineId %d Product details %s line count %d\n", LOG_LOCATION,ld.ld[0].fo_id,ld.ld[0].product_details,ld.line_count);
        lDBConnectionObject.Close();
    }
    
    
    iterMap = conn->getPath().find(sample->ip_info[i].ipadress);
    g_cSystemLogger.LogMessage("(%s:%s(:%d))Path %s \n", LOG_LOCATION,iterMap->second.c_str());

    if (sample->ip_info[i].status == true) 
    {

        sprintf(command, "%s%s",iterMap->second.c_str(),"/clear_server.sh >> /tmp/LOGS/cronlog 2>&1 &");

        while ((rc = libssh2_channel_exec(channel2, command)) == LIBSSH2_ERROR_EAGAIN) {
            waitsocket(sock, session);
        }
        lnReturnCode = libssh2_channel_read(channel2, command, sizeof (command));
        g_cSystemLogger.LogMessage("(%s:%s(:%d)lnReturnCode %d command after executing %s\n", LOG_LOCATION, lnReturnCode, command);
        memset(command, 0, sizeof (command));
        libssh2_channel_free(channel2);
        channel2 = NULL;
    }
        
    else if((sample->ip_info[i].status==false) && ((strcmp(sample->ip_info[i].psl,""))==0) && (sample->ip_info[i].CancelOrderId==0))
    {
        sprintf(command, "%s", "cd /home/mint/ga/bin; nohup ./shutdownall.sh >> /tmp/LOGS/cronlog1 2>&1 &");

        g_cSystemLogger.LogMessage("(%s:%s(:%d)%s\n", LOG_LOCATION, command);
        while ((rc = libssh2_channel_exec(channel2, command)) == LIBSSH2_ERROR_EAGAIN) {
            g_cSystemLogger.LogMessage("(%s:%s(:%d) ERROR Running command %d\n", LOG_LOCATION, rc);
            waitsocket(sock, session);
        }

        size_t lnReturnCode;
        lnReturnCode = libssh2_channel_read(channel2, command, sizeof (command));

        g_cSystemLogger.LogMessage("(%s:%s(:%d)lnReturnCode %d commandBuffer %s\n", LOG_LOCATION, lnReturnCode, command);
        memset(command, 0, sizeof (command));
        libssh2_channel_free(channel2);
        channel2 = NULL;
    }
    g_cSystemLogger.LogMessage("(%s:%s(:%d)space %s\n", LOG_LOCATION,ld.spaceInfo);
     CcopyStructure::copyCommandData(ld, ld.line_count);
    }
}
   
       
    return true;
}
//void *grossStatisticsAcc(void *tbNa)
void grossStatisticsAcc(string tbNa)
{
	string tName = tbNa;

	cout<<"";


	try
	{
	/*	ifstream confFile("/home/sivaprakash/workspace/StatisticsDataFromDB/src/tabAcc.conf");
		confFile>>tName;
		confFile.close();
		cout<<"start of Acc thread for table:"<<tName<<endl;*/

		PreparedStatement *readPstmt,*inPstmt,*upPstmt;
		ResultSet *dailyRes,*ymRes;

		string year = tName.substr(13,4);
		string month = tName.substr(10,2);
		string day = tName.substr(7,2);

		string yearStatisticstable = "ud_acc_"+year;
		string monthStatisticstable = "ud_acc_"+month;
		string schema = "squidStatistics_"+year;

		DBConnection *grossLog = new DBConnection();
		grossLog->dbConnOpen("127.0.0.1","3306","root","simple",schema);

		Statement *stmt = grossLog->conn->createStatement();

		checkPresenecOfGrossStatisticsTableAcc(stmt,yearStatisticstable);
		checkPresenecOfGrossStatisticsTableAcc(stmt,monthStatisticstable);

		string searchQueryMonth = "select * from "+ monthStatisticstable +"  where user=? and domain=? ;";
		string searchQueryYear = "select * from "+ yearStatisticstable +"  where user=? and domain=?;";

		string insertMonth = "insert into " + monthStatisticstable + "(user,domain,size,connection,hit,miss,response_time) values(?,?,?,?,?,?,?);";
		string updateMonth = "update " + monthStatisticstable + " set size=?,connection=?,hit=?,miss=?,response_time=? where user=? and domain=?;";

		string insertYear = "insert into " + yearStatisticstable + "(user,domain,size,connection,hit,miss,response_time) values(?,?,?,?,?,?,?);";
		string updateYear = "update " + yearStatisticstable + " set size=?,connection=?,hit=?,miss=?,response_time=? where user=? and domain=?;";

		string selectQuery = "select * from " + tName +";";
		readPstmt = grossLog->conn->prepareStatement(selectQuery);
		dailyRes = readPstmt->executeQuery();

		while(dailyRes->next())
		{
	//		cout<<dailyRes->getInt(4)<<"\tstart\n";
			for(int i=0;i<2;i++)
			{
				if(i ==  0)  //updating monthly gross statistics
				{
					readPstmt = grossLog->conn->prepareStatement(searchQueryMonth);
					inPstmt =  grossLog->conn->prepareStatement(insertMonth);
					upPstmt = grossLog->conn->prepareStatement(updateMonth);
				}
				else
				{
					readPstmt = grossLog->conn->prepareStatement(searchQueryYear);
					inPstmt =  grossLog->conn->prepareStatement(insertYear);
					upPstmt = grossLog->conn->prepareStatement(updateYear);
				}

				readPstmt->setString(1,dailyRes->getString(1));
				readPstmt->setString(2,dailyRes->getString(2));
				ymRes = readPstmt->executeQuery();

				if(ymRes->next())
				{
					updateRowDataAcc(dailyRes,ymRes,upPstmt);
				}
				else
				{
					//	cout<<dailyRes->getInt(4)<<endl;
					insertRowDataAcc(dailyRes,inPstmt);
				}
			}
		}
		createUserStatisticsAcc(tName);
		createDomainStatisticsAcc(tName);
	}
	catch (sql::SQLException &e)
	{
		cout << "# ERR: SQLException in " << __FILE__;
		cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
		cout << "# ERR: " << e.what();
		cout << " (MySQL error code: " << e.getErrorCode();
		cout << ", SQLState: " << e.getSQLState() << " )" << endl;
	}
	catch (exception& e)
	{
		cout << "# ERR File: " << __FILE__;
		cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
	    cout << e.what() << '\n';
	}

}