Example #1
0
 formula_kind get_formula_kind(expr_ref& f) {
     expr_ref tmp(f);
     normalize(tmp);
     ast_mark mark;
     expr_ref_vector args(m), body(m);
     expr_ref head(m);
     expr* a = 0, *a1 = 0;
     qe::flatten_or(tmp, args);
     for (unsigned i = 0; i < args.size(); ++i) {
         a = args[i].get(); 
         check_predicate(mark, a);
         if (m.is_not(a, a1)) {
             body.push_back(a1);
         }
         else if (is_predicate(a)) {
             if (head) {
                 return IS_NONE;
             }
             head = a;
         }
         else {
             body.push_back(m.mk_not(a));
         }
     }
     if (head) {
         if (!is_implication(f)) {
             f = m.mk_and(body.size(), body.c_ptr());
             f = m.mk_implies(f, head);
         }
         return IS_RULE;
     }
     else {
         f = m.mk_and(body.size(), body.c_ptr());
         return IS_QUERY;
     }
 }
Example #2
0
int DB_query (struct database *db, char *tablename, char *predicates, char *returnString)
{
    	struct Table *t = DB_getTable(db, tablename);
    	if(t == NULL) 
    	{
		strcpy(returnString, "E TABLE");
		return -1;
    	}

	int predicate_cnt = 0;
	int col_per_table = 0;
	int stat;
    	while(1)
    	{
		// parse predicate string and store in a data structure
		char predicate_col_name[MAX_COLUMNS_PER_TABLE][MAX_COLNAME_LEN+1];
		char operator[MAX_COLUMNS_PER_TABLE];
		char predicate_col_value[MAX_COLUMNS_PER_TABLE][MAX_STRTYPE_SIZE+1];

		// initialize to NULL
		int init2 = 0;
		while(init2 < MAX_COLUMNS_PER_TABLE)
		{
			memset(predicate_col_name[init2], '\0', sizeof(predicate_col_name[init2]));
			memset(predicate_col_value[init2], '\0', sizeof(predicate_col_value[init2]));
			init2++;
		}
		memset(operator, '\0', sizeof(operator));

		// the bulk
		//bool invalid_predicate = true;
		while(predicates[predicate_cnt] != '\0')
		{
			int col_name_cnt = 0;
			int col_value_cnt = 0;
			while(predicates[predicate_cnt] == ' ')
			{
				predicate_cnt++;
			}
			while((predicates[predicate_cnt] != '<')&&(predicates[predicate_cnt] != '>')&&(predicates[predicate_cnt] != '=')&&(predicates[predicate_cnt] != '\0'))
			{	
				if(isalnum(predicates[predicate_cnt]) == 0)
				{
					if(predicates[predicate_cnt] != ' ')
					{
						strcpy(returnString, "E INVALID_PARAM");
						return -3;
					}
				}			
				predicate_col_name[col_per_table][col_name_cnt] = predicates[predicate_cnt];
				predicate_cnt++;
				col_name_cnt++;
			}
			
			//delete trailing spaces
			int length = (strlen(predicate_col_name[col_per_table])-1);
			while(predicate_col_name[col_per_table][length] == ' ')
			{
				predicate_col_name[col_per_table][length] = '\0';
				length -= 1;
			}
		
			operator[col_per_table] = predicates[predicate_cnt];
			predicate_cnt++;
			while(predicates[predicate_cnt] == ' ')
			{
				predicate_cnt++;
			}
			while((predicates[predicate_cnt] != ',')&&(predicates[predicate_cnt] != '\0'))
			{
				if(predicates[predicate_cnt] == '+') 
				{
					predicate_cnt++;
				}
				if(predicates[predicate_cnt] == '-')
				{
					;
				}
				else if(isalnum(predicates[predicate_cnt]) == 0)
				{
					if(predicates[predicate_cnt] != ' ')
					{
						strcpy(returnString, "E INVALID_PARAM");
						return -3;
					}
					strcpy(returnString, "E INVALID_PARAM");
					return -3;
				}				
				predicate_col_value[col_per_table][col_value_cnt] = predicates[predicate_cnt];
				predicate_cnt++;
				col_value_cnt++;
			}

			//delete trailing spaces
			int length2 = (strlen(predicate_col_value[col_per_table])-1);
			while(predicate_col_value[col_per_table][length2] == ' ')
			{
				predicate_col_value[col_per_table][length2] = '\0';
				length2 -= 1;
			}

			if(predicates[predicate_cnt] == ',')
			{
				predicate_cnt++;
			}
			col_per_table++;
		}

int i = 0;
while(predicate_col_name[i][0] != '\0')
{
	printf("Column %d: %s\n Operator %d: %c\n Value %d: %s\n", i, predicate_col_name[i], i, operator[i], i, predicate_col_value[i]);
	i++;
}		

		// check for matching cases
		stat = check_predicate(t, predicate_col_name, operator, predicate_col_value, returnString);
		return stat;
		
	}
}