// builds predicate group internal static string Build(this PredicateGroup predicateGroup, PredicateGroupType callerGroupType, string callerKeyword) { if (predicateGroup == null) { return(callerKeyword); } var sql = Text.GenerateSql(30); // .End() if (callerGroupType == PredicateGroupType.End && (predicateGroup.PredicateGroupType == PredicateGroupType.End || predicateGroup.PredicateGroupType == PredicateGroupType.BeginEnd)) { sql.NewLine(Text.RightBracket); } // .Begin() else if (callerGroupType == PredicateGroupType.Begin && (predicateGroup.PredicateGroupType == PredicateGroupType.Begin || predicateGroup.PredicateGroupType == PredicateGroupType.BeginEnd)) { switch (predicateGroup.LogicalOperator) { case Wall.LogicalOperator.None: sql.Append(Text.Where); break; case Wall.LogicalOperator.And: sql.Append(Text.And); break; case Wall.LogicalOperator.Or: sql.Append(Text.Or); break; } if (!predicateGroup.Sign) { sql.S().Append(Text.Not); } sql.S().Append(Text.LeftBracket); } // predicate group is BeginEnd (single predicate inside the group) => return caller's default keyword (no brackets) else { sql.Append(callerKeyword); } return(sql.ToString()); }
void IPredicate.SetPredicateGroup(PredicateGroupType predicateGroupType) { PredicateGroup.SetPredicateGroup(this, predicateGroupType); }
internal static void SetPredicateGroup(IPredicate node, PredicateGroupType predicateGroupType) { if (predicateGroupType == PredicateGroupType.Begin) { ++node.PredicateGroupLevel; } else { --node.PredicateGroupLevel; } if (node.PredicateGroup != null) { if (node.PredicateGroup.PredicateGroupType == predicateGroupType) { ThrowInvalidPredicateGroupingException((DbNode)node); } else { node.ResetPredicateGroup(); return; } } else if (node.PredicateGroupLevel > 1) { ThrowInvalidPredicateGroupingException((DbNode)node); } LogicalOperator op = node.HasPredicate ? LogicalOperator.And : LogicalOperator.None; // default bool sign = true; if (node.HasOr) { op = Wall.LogicalOperator.Or; node.HasOr = false; // reset } if (node.HasNot) { sign = false; node.HasNot = false; // reset } node.PredicateGroup = new PredicateGroup(predicateGroupType, op, sign); if (predicateGroupType == PredicateGroupType.End) { if (node.HasPredicate) { if (node.Predicates[node.Predicates.Count - 1].PredicateGroup != null) { node.Predicates[node.Predicates.Count - 1].PredicateGroup.PredicateGroupType = PredicateGroupType.BeginEnd; } else { // non-first predicate takes the node's predicate ending group node.Predicates[node.Predicates.Count - 1].SetPredicateGroup(node.PredicateGroup); } } node.ResetPredicateGroup(); } }
internal PredicateGroup(PredicateGroupType predicateGroupType, LogicalOperator logicalOperator, bool sign) { PredicateGroupType = predicateGroupType; LogicalOperator = logicalOperator; Sign = sign; }