SHARE
TWEET

Untitled

a guest Jun 5th, 2017 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "parse.h"
  2.  
  3.  
  4. Parse::Parse()
  5. {
  6.   Mysql = new MySQL;
  7.   Mysql->host = "10.1.20.62";
  8.   Mysql->user = "secret";
  9.   Mysql->password = "secret";
  10.   Mysql->database = "work";
  11.   Mysql->connect();
  12.  
  13.   vector< vector<string> > sql_result;
  14.   vector< vector<string> >::iterator iter_ii;
  15.   vector<string>::iterator iter_jj;
  16.   sql_result = Mysql->sql_query("select werknemerid from werknemers");
  17.   int ii = 0;
  18.   int jj = 0;
  19.   vector< int >::iterator it1;
  20.   vector< User* >::iterator it2;
  21.   it1 = users_lookup.begin();
  22.   it2 = users.begin();
  23.   for (ii=0; ii<sql_result.size(); ii++)
  24.   {
  25.     User* tmpuser = new User;
  26.     int number;
  27.     istringstream ss( sql_result[ii][0] );
  28.     ss >> number;
  29.     if (! ss.good())
  30.     {
  31.       it1 = users_lookup.insert ( it1 , number );
  32.       cout << number << endl;
  33.       it2 = users.insert ( it2 , tmpuser );
  34.     }
  35.   }
  36. }
  37.  
  38. Parse::~Parse()
  39. {
  40. }
  41.  
  42. int Parse::parse(string data)
  43. {
  44.   int number;
  45.   istringstream ss( data );
  46.   ss >> number;
  47.   if (! ss.good())
  48.   {
  49.     int i = 0;
  50.     for (i = 0; i < users_lookup.size(); i++)
  51.     {
  52.       if (users_lookup[i] == number)
  53.       {
  54.         int busy = -1;
  55.         busy = users[i]->addtime();
  56.         if (busy == 2)
  57.         {
  58.           string starttime;
  59.           string endtime;
  60.           string id;
  61.           stringstream out0;
  62.           stringstream out1;
  63.           stringstream out2;
  64.           User* tmpuser = dynamic_cast<User*>( users[i] );
  65.           out0 << users_lookup[i];
  66.           id = out0.str();
  67.           out1 << tmpuser->starttime;
  68.           starttime = out1.str();
  69.           out2 << tmpuser->endtime;
  70.           endtime = out2.str();
  71.           cout << starttime << endl;
  72.           string sql_string = "insert into uren (werknemer_id, start, end) VALUES ( '";
  73.           sql_string.append( id );
  74.           sql_string.append( "', '" );
  75.           sql_string.append( starttime );
  76.           sql_string.append( "', '" );
  77.           sql_string.append( endtime );
  78.           sql_string.append( "' )" );
  79.           cout << sql_string << endl;
  80. //          const char *sql_char_ary = sql_string.c_str();
  81.           char *sql_char_ary = new char[sql_string.length()+1];
  82.           strcpy ( sql_char_ary, sql_string.c_str() ); // that is correct
  83.           Mysql->connect();
  84.           Mysql->sql_insert(sql_char_ary);
  85.           Mysql->disconnect();
  86.         }
  87.         return busy;
  88.       }
  89.     }
  90.     return -1;
  91.   }
  92.   return -2;
  93. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top