void CRUSimpleRefreshSQLComposer::AddDeltaDefListClause()
{
	RUASSERT(GetRefreshTask().GetDeltaDefList().GetCount() > 0);

	sql_ += "\n FROM ";
	sql_ += (TRUE == GetRefreshTask().IsSingleDeltaRefresh()) ? 
		"SINGLEDELTA " : "MULTIDELTA ";

	DSListPosition pos = GetRefreshTask().GetDeltaDefList().GetHeadPosition();

	for (;;)
	{
		CRUDeltaDef *pDdef = GetRefreshTask().GetDeltaDefList().GetNext(pos);

		CDSString fromEpoch(TInt32ToStr(pDdef->fromEpoch_)) ;
		CDSString toEpoch(TInt32ToStr(pDdef->toEpoch_));

		AddDeltaDefClause(pDdef,fromEpoch,toEpoch);

		if (NULL == pos)
		{
			break;	// The last clause
		}
		else
		{
			sql_ += ", ";
		}
	}	
	if (FALSE == GetRefreshTask().IsSingleDeltaRefresh())
	{
		AddPhaseParam();
	}
}
Example #2
0
// Parse cmd line args
NoteStat::NoteStat(int argc,char **argv) :
  startTime_(0), endTime_(0), hours_(0), count_(false),
  tf_(UPDATE_FILE), sortField_(kFldSTime)
{
  //cout << "DEBUG: Into NoteStat";
  //cout << "DEBUG: NoteStat:: loaded tailfile pos = " <<  tf_.pos_ << endl;

  for(int c = 1; c < argc; c++) {

    char *ch = argv[c];
    //cout << "\nDEBUG: cmd arg is " << ch << endl;
    if(*ch != '-') {

      usage();
      string err = "Invalid command line args: "; 
      throw err + argv[c];;

    }

    ch++;
    if(*ch != 'c' && *ch != 'C') {

      if(c == argc) {

        usage();
        string err = "Invalid command line args: "; 
        throw err + argv[c];;

      }

    }

    switch(*ch) {

      case 's':
      case 'S':
        ch = argv[++c];
        if (!toEpoch(ch, &startTime_)) {
          usage();
          throw string("Wrong time format in startTime");
        }
        break;

      case 'e':
      case 'E':
        ch = argv[++c];
        if (!toEpoch(ch, &endTime_)) {
          usage();
          throw string("Wrong time format in endTime");
        }
        break;

      case 'h':
      case 'H':
        ch = argv[++c];
        hours_ = atoi(ch);
        break;

      case 'c':
      case 'C':
        count_ = true;
        break;

      case 'm':
      case 'M':
        while (((ch = argv[++c]) != NULL ) && *ch != '-') {
          module_.push_back(ch);
        }
        if((ch != NULL) && (*ch == '-')) { c--; }
        break;

      case 'o':
      case 'O':
        while ((ch = argv[++c]) != NULL && *ch != '-') {
          string status(ch);
          transform (status.begin(), status.end(),
              status.begin(), ::toupper);
          statusList_.push_back(status);
        }
        if((ch != NULL) && (*ch == '-')) { c--; }
        break;

      case 'u':
      case 'U':
        ch = argv[++c];
        if (strchr(ch, '@')) {
          // List of email ids
          do {
            userList_.insert(ch);
          } while ((ch = argv[++c]) != NULL && *ch != '-');
          if (ch != NULL && *ch == '-') {
            --c;
          }
        }
        else {
          // User file 
          fillUserList(ch);
        }
        /*
           cout << "DEBUG: userList_ contents:" << endl;
           copy( userList_.begin(), userList_.end(),
           ostream_iterator<string>(cout, " "));
           cout << endl;
           */
        break;

      case 'g':
      case 'G':
        ch = argv[++c];
        setSortField (ch);
        uicp_.reset (new UserInfoContainer(UserInfoSort(sortField_)));
        break;

      case 'f':
      case 'F':
        faultStr_ = argv[++c]; 
        transform (faultStr_.begin(), faultStr_.end(),
            faultStr_.begin(), ::tolower);
        break;

      default:
        usage();
        string err = "Invalid command line args: "; 
        throw err + argv[c];
    }
  } // end for

  if (startTime_ == 0 && hours_ == 0) {
    usage();
    throw string("Invalid command line args: startTime missing");
  }
  else if (startTime_ != 0 && hours_ != 0) {
    usage();
    throw string("Invalid command line args: Cannot specify hours along with startTime");
  }
  else if (startTime_ == 0 && hours_ != 0) {
    if (endTime_ == 0) {
      time_t now;
      time (&now);
      if (now == -1) {
        throw string("Cannot find current time: system has no time");
      }
      endTime_ = now;
    }

    // set proper start time
    struct tm t;
    localtime_r (&endTime_, &t);
    t.tm_isdst = -1;
    // subtract the hours from end time
    t.tm_hour -= hours_;

    startTime_ = mktime (&t);
  }
}