Example #1
0
        public string BuildWhereStatement()
        {
            string Result = "";

            int PreviousLevel = 0;

            foreach (WhereClause Clause in this) // Loop through all conditions, AND them together
            {
                string WhereClause = "";

                if (Clause is GeneralWhereClause)
                {
                    GeneralWhereClause gClause = (GeneralWhereClause)Clause;
                    WhereClause = CreateComparisonClause(gClause.LogicalOperator, SelectQueryBuilder.getColumnPartQuery(gClause.FieldName), gClause.ComparisonOperator, gClause.Value, gClause.Level, PreviousLevel);
                }
                else if (Clause is BetweenWhereClause)
                {
                    BetweenWhereClause bClause = (BetweenWhereClause)Clause;
                    WhereClause = CreateBetweenClause(bClause.LogicalOperator, SelectQueryBuilder.getColumnPartQuery(bClause.FieldName), bClause.FromValue, bClause.ToValue, bClause.Level, PreviousLevel);
                }

                Result       += WhereClause + " ";
                PreviousLevel = Clause.Level;
            }

            String RemainingParenthesis = "";

            while (PreviousLevel > 0)
            {
                RemainingParenthesis += ")";
                PreviousLevel--;
            }
            Result += RemainingParenthesis;
            return(Result);
        }
Example #2
0
        public WhereClause Add(LogicOperator logicalOperator, string field, Comparison @operator, object compareValue, int level)
        {
            GeneralWhereClause NewWhereClause = new GeneralWhereClause(logicalOperator, field, @operator, compareValue, level);

            this.Add(NewWhereClause);
            return(NewWhereClause);
        }
Example #3
0
        /// <summary>
        /// This static method combines 2 where statements with eachother to form a new statement
        /// </summary>
        /// <param name="statement1"></param>
        /// <param name="statement2"></param>
        /// <returns></returns>
        //public static WhereStatement CombineStatements(WhereStatement statement1, WhereStatement statement2)
        //{
        //    // statement1: {Level1}((Age<15 OR Age>=20) AND (strEmail LIKE 'e%') OR {Level2}(Age BETWEEN 15 AND 20))
        //    // Statement2: {Level1}((Name = 'Peter'))
        //    // Return statement: {Level1}((Age<15 or Age>=20) AND (strEmail like 'e%') AND (Name = 'Peter'))

        //    // Make a copy of statement1
        //    WhereStatement result = WhereStatement.Copy(statement1);

        //    // Add all clauses of statement2 to result
        //    for (int i = 0; i < statement2.ClauseLevels; i++) // for each clause level in statement2
        //    {
        //        List<WhereClause> level = statement2[i];
        //        foreach (WhereClause clause in level) // for each clause in level i
        //        {
        //            for (int j = 0; j < result.ClauseLevels; j++)  // for each level in result, add the clause
        //            {
        //                result.AddWhereClauseToLevel(clause, j);
        //            }
        //        }
        //    }

        //    return result;
        //}

        public static WhereStatement Copy(WhereStatement statement)
        {
            WhereStatement result = new WhereStatement();

            foreach (WhereClause clause in statement)
            {
                WhereClause clauseCopy = null;
                if (clause is GeneralWhereClause)
                {
                    GeneralWhereClause gClause = (GeneralWhereClause)clause;
                    clauseCopy = new GeneralWhereClause(gClause.LogicalOperator, gClause.FieldName, gClause.ComparisonOperator, gClause.Value, gClause.Level);
                }
                else if (clause is BetweenWhereClause)
                {
                    BetweenWhereClause bClause = (BetweenWhereClause)clause;
                    clauseCopy = new BetweenWhereClause(bClause.LogicalOperator, bClause.FieldName, bClause.FromValue, bClause.ToValue, bClause.Level);
                }
                //foreach (WhereClause.SubClause subClause in clause.SubClauses)
                //{
                //    WhereClause.SubClause subClauseCopy = new WhereClause.SubClause(subClause.LogicOperator, subClause.ComparisonOperator, subClause.Value);
                //    clauseCopy.SubClauses.Add(subClauseCopy);
                //}
                result.Add(clauseCopy);
            }
            return(result);
        }
Example #4
0
        public WhereClause Add(LogicOperator logicalOperator, string field, Comparison @operator, object compareValue, int level, int index)
        {
            GeneralWhereClause NewWhereClause = new GeneralWhereClause(logicalOperator, field, @operator, compareValue, level);

            this.Insert(index, NewWhereClause);
            //this.AddWhereClauseToLevel(NewWhereClause, level);
            return(NewWhereClause);
        }
 //public WhereClause AddHaving(string field, Comparison @operator, object compareValue) { return AddHaving(field, @operator, compareValue); }
 //public WhereClause AddHaving(Enum field, Comparison @operator, object compareValue) { return AddHaving(field.ToString(), @operator, compareValue, 1); }
 public WhereClause AddHaving(string field, Comparison @operator, object compareValue)
 {
     WhereClause NewWhereClause = new GeneralWhereClause(LogicOperator.None, field, @operator, compareValue, 0);
     _havingStatement.Add(NewWhereClause);
     return NewWhereClause;
 }
 //public WhereClause AddWhere(Enum field, Comparison @operator, object compareValue) { return AddWhere(logicalOperator, field.ToString(), @operator, compareValue, 1); }
 public WhereClause AddWhere(LogicOperator logicalOperator, string field, Comparison @operator, object compareValue, int level)
 {
     WhereClause NewWhereClause = new GeneralWhereClause(logicalOperator, field, @operator, compareValue, level);
     _whereStatement.Add(NewWhereClause);
     return NewWhereClause;
 }