Esempio n. 1
0
        string WhereString(OqlExpression thisExpression)
        {
            StringBuilder sb = new StringBuilder();

            if (thisExpression.IsTerminating || thisExpression is IdentifierExpression)
            {
                if (thisExpression.UnaryOp != null)
                {
                    sb.Append(thisExpression.UnaryOp);
                    sb.Append(' ');
                }
                if (thisExpression.Value.GetType().IsPrimitive)
                {
                    sb.Append(Convert.ToString(thisExpression.Value, CultureInfo.InvariantCulture));
                }
                else
                {
                    IdentifierExpression iexp = thisExpression as IdentifierExpression;
                    if (iexp != null)
                    {
                        sb.Append(iexp.GetAnnotation <string>(anKey));
                    }
                    else
                    {
                        sb.Append(thisExpression.Value.ToString());
                    }
                }
            }
            else
            {
                if (thisExpression.UnaryOp != null)
                {
                    sb.Append(thisExpression.UnaryOp);
                    sb.Append(' ');
                }
                if (thisExpression is FunctionExpression)
                {
                    sb.Append(thisExpression.Value);
                }
                if (thisExpression.HasBrackets)
                {
                    sb.Append('(');
                }
                string op1 = thisExpression.Operator;

                int childExpEndIndex = thisExpression.Children.Count - 1;
                for (int i = 0; i <= childExpEndIndex; i++)
                {
                    OqlExpression child = thisExpression.Children[i];
                    sb.Append(WhereString(child));
                    if (i < childExpEndIndex)
                    {
                        if (op1 != ",")
                        {
                            sb.Append(' ');
                        }
                        sb.Append(op1);
                        if (op1 == "BETWEEN")
                        {
                            op1 = "AND";
                        }
                        sb.Append(' ');
                    }
                }

                if (thisExpression.HasBrackets)
                {
                    sb.Append(')');
                }
            }
            return(sb.ToString());
        }