Beispiel #1
0
MojErr MojDbQuery::addClause(WhereMap& map, const MojChar* propName, CompOp op, const MojObject& val, MojDbCollationStrength coll)
{
	MojAssert(propName);

	// only allow valid ops
    if (!(op >= OpEq && op <= OpSubString))
		MojErrThrowMsg(MojErrDbInvalidQuery, _T("db: invalid query op"));
    // only allow array values for = or % or %% ops
    if (val.type() == MojObject::TypeArray && op != OpEq && op != OpPrefix && op != OpSubString)
		MojErrThrowMsg(MojErrDbInvalidQuery, _T("db: query contains array value for non-eq op"));

	// check to see if the prop is referenced in a prior clause
	WhereMap::Iterator iter;
	MojErr err = map.find(propName, iter);
	MojErrCheck(err);
	if (iter == map.end()) {
		// create new clause
		err = createClause(map, propName, op, val, coll);
		MojErrCheck(err);
	} else {
		// add clause to previously referenced prop.
		err = updateClause(iter.value(), op, val, coll);
		MojErrCheck(err);
	}
	return MojErrNone;
}
/**
 * Generate and print a random clause with nbLiterals literals
 * @param f the formula
 * @param clauseNumber : the clause to generate
 * @param : the number of literals that contain the clause
	
 */
void generateClause(Formula * f, int nbLiterals) {
  Clause * c;
    createClause(&c);
    addClause(f,c);
  for(int i = 0;i<nbLiterals;i++) {
    int sign = rand()%2 ? 1 : -1;
    Literal l = sign*(rand()%f->nbVariables+1);
      
    addLiteralInClause(*f,c,l);
   
  }
}