Example #1
0
        private SQConditionBase GetCondition(ORMCondBase cond, ORMSelect select)
        {
            if (cond != null)
            {
                SQConditionBase res = null;
                if (cond is ORMCond)
                {
                    ORMCond cnd      = (ORMCond)cond;
                    string  operandA = GetPropertyChainColumn(cnd.PropertyChain, select);
                    string  operandB = null;
                    if (cnd.Value is ORMPropertyChain)
                    {
                        operandB = GetPropertyChainColumn(((ORMPropertyChain)cnd.Value).Chain, select);
                    }
                    else if (cnd.Value == ORMCond.NullOperand)
                    {
                        operandB = "NULL";
                    }
                    else
                    {
                        operandB = GetNextParam();
                        Query.Parameters.Add(new SQParameter((string)operandB, cnd.Value));
                    }
                    res = new SQCondition(operandA, cnd.Operator, operandB, cnd.InvertMeaning);
                }
                else if (cond is ORMCondSQL)
                {
                    ORMCondSQL cnd = (ORMCondSQL)cond;
                    res = cnd.Cond;

                    foreach (SQParameter prm in cnd.Parameters)
                    {
                        Query.Parameters.Add(prm);
                    }
                }
                else if (cond is ORMCondGroup)
                {
                    ORMCondGroup grp = (ORMCondGroup)cond;
                    res = new SQConditionGroup(grp.InvertMeaning, GetCondition(grp.InnerCondition, select));
                }

                if (cond.NextCondition != null)
                {
                    if (cond.Connective == SQLogicOperators.AND)
                    {
                        res.And(GetCondition(cond.NextCondition, select));
                    }
                    else
                    {
                        res.Or(GetCondition(cond.NextCondition, select));
                    }
                }

                return(res);
            }

            return(null);
        }
Example #2
0
        public virtual string Write(SQConditionBase condition)
        {
            string res = string.Empty;

            if (condition is SQCondition)
            {
                SQCondition con = (SQCondition)condition;
                res = string.Format("{0} {1} {2}", Write(con.OperandA), GetOperatorText(con.Operator), Write(con.OperandB));
                res = string.Format("{0}({1})", condition.InvertMeaning ? "NOT" : "", res);
            }
            else if (condition is SQConditionGroup)
            {
                SQConditionGroup con = (SQConditionGroup)condition;
                res = (condition.InvertMeaning ? "NOT" : "") + "(" + Write(con.InnerCondition) + ")";
            }

            if (condition.NextCondition != null)
            {
                res += string.Format(" {0} {1}", condition.Connective, Write(condition.NextCondition));
            }
            return(res);
        }
Example #3
0
 public ORMCondSQL(SQCondition cond, params SQParameter[] sqParams)
 {
     this.Cond = cond;
     this.Parameters.AddRange(sqParams);
 }