Exemplo n.º 1
0
        public string BuildSql()
        {
            if (!String.IsNullOrEmpty(_rawSql))
            {
                return(_rawSql);
            }

            string whereClause = WhereStatement.CreateComparisonClause(FieldName, ComparisonOperator, Value);

            foreach (SubClause subWhereClause in SubClauses)
            {
                switch (subWhereClause.LogicOperator)
                {
                case LogicOperator.And:
                    whereClause += " AND ";
                    break;

                case LogicOperator.Or:
                    whereClause += " OR ";
                    break;
                }
                whereClause += WhereStatement.CreateComparisonClause(FieldName,
                                                                     subWhereClause.ComparisonOperator,
                                                                     subWhereClause.Value);
            }
            return(whereClause);
        }
Exemplo n.º 2
0
 private string BuildOnClause()
 {
     if (!String.IsNullOrEmpty(OnClause))
     {
         return(OnClause);
     }
     return(WhereStatement.CreateComparisonClause(FriendlyFromTableName + '.' + FromColumn,
                                                  ComparisonOperator,
                                                  new SqlLiteral(FriendlyToTableName + '.' +
                                                                 ToColumn)));
 }
Exemplo n.º 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 = statement1.Copy();

            // 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);
        }