Exemplo n.º 1
0
        protected string ParameterListToString(string indent)
        {
            if (Parameters == null || Parameters.Count == 0)
            {
                return("");
            }

            var sb = new StringBuilder(1024);

            var i = 0;

            while (Parameters != null && i < Parameters.Count)
            {
                sb.AppendFormat("{0}{1} {2}", indent, Parameters[i].VariableName.Value,
                                TsqlFragmentToString.DataType(Parameters[i].DataType));

                if (i < Parameters.Count - 1)
                {
                    sb.Append(",\r\n");
                }

                i++;
            }

            return(sb.ToString());
        }
Exemplo n.º 2
0
        internal override string ToString(string indent)
        {
            var sb = new StringBuilder(32);

            sb.Append(FirstTableRef.ToString(indent) + "\n");

            sb.AppendFormat(" {1}{0}\n ", TsqlFragmentToString.JoinType(QualifiedJoinType, JoinHint), indent);

            //if (SecondTableRef.OneLine())
            //{
            //    sb.Append(SecondTableRef.ToString());
            //}
            //else
            //{
            //sb.Append("\r\n");
            sb.Append(SecondTableRef.ToString(indent));
            //}

            sb.Append("\n" + indent + "ON ");

            //if (JoinCondition.OneLine())
            //{
            //    sb.Append(JoinCondition.ToString());
            //}
            //else
            //{
            //sb.Append("\r\n");
            sb.Append(JoinCondition.ToString(""));
            //}

            return(sb.ToString());
        }
Exemplo n.º 3
0
        internal override string ToString(string indent)
        {
            var sb = new StringBuilder(32);

            if (OneLine())
            {
                if (FirstTableRef != null)
                {
                    sb.AppendFormat("{0}{1} ", indent, FirstTableRef.ToString(""));
                }
                sb.Append(TsqlFragmentToString.JoinType(UnqualifiedJoinType));
                sb.AppendFormat(" {0}", SecondTableRef.ToString(""));
            }
            else
            {
                if (FirstTableRef != null)
                {
                    sb.Append(FirstTableRef.ToString(indent + "  "));
                    sb.Append("\r\n");
                }
                sb.AppendFormat("{0}  {1}\r\n", indent, TsqlFragmentToString.JoinType(UnqualifiedJoinType));
                sb.Append(SecondTableRef.ToString(indent + "  "));
            }

            return(sb.ToString());
        }
Exemplo n.º 4
0
        public override void Visit(WUnaryExpression node)
        {
            node.Expression.Accept(this);
            string expr = this.dfsStack.Pop();

            string nodeStr = $"{TsqlFragmentToString.UnaryExpressionType(node.ExpressionType)}{expr}";

            this.dfsStack.Push(nodeStr);
        }
        internal override string ToString(string indent)
        {
            var sb = new StringBuilder();

            sb.Append(Expression.ToString(indent));
            sb.AppendFormat(" {0} \r\n", TsqlFragmentToString.BooleanComparisonType(ComparisonType));
            sb.Append(Subquery.ToString(indent + " "));

            return(sb.ToString());
        }
Exemplo n.º 6
0
 internal override string ToString(string indent)
 {
     if (OneLine())
     {
         return(string.Format(CultureInfo.InvariantCulture, "{0}{1} {2} {3}", indent, VariableName,
                              TsqlFragmentToString.AssignmentType(AssignmentType),
                              Expression.ToString("")));
     }
     return(string.Format(CultureInfo.InvariantCulture, "{0}{1} {2}\r\n", indent, VariableName,
                          TsqlFragmentToString.AssignmentType(AssignmentType)) + Expression.ToString(indent + " "));
 }
Exemplo n.º 7
0
        // WBooleanExpression
        public override void Visit(WBooleanBinaryExpression node)
        {
            node.FirstExpr.Accept(this);
            string left = this.dfsStack.Pop();

            node.SecondExpr.Accept(this);
            string right = this.dfsStack.Pop();

            string nodeStr = $"{left} {TsqlFragmentToString.BooleanExpressionType(node.BooleanExpressionType)} {right}";

            this.dfsStack.Push(nodeStr);
        }
Exemplo n.º 8
0
        internal override string ToString(string indent)
        {
            var sb = new StringBuilder(1024);

            sb.AppendFormat("{0}\r\n", FirstQueryExpr.ToString(indent));

            sb.AppendFormat(All ? "{0}{1} ALL\r\n" : "{0}{1}\r\n", indent,
                            TsqlFragmentToString.BinaryQueryExpressionType(BinaryQueryExprType));

            sb.AppendFormat("{0}", SecondQueryExpr.ToString(indent));

            return(sb.ToString());
        }
Exemplo n.º 9
0
 internal override string ToString(string indent)
 {
     if (SortOrder == SortOrder.NotSpecified)
     {
         return(ScalarExpr.ToString(indent));
     }
     else
     {
         return(string.Format(CultureInfo.CurrentCulture, "{0} {1}",
                              ScalarExpr.ToString(indent),
                              TsqlFragmentToString.SortOrder(SortOrder)));
     }
 }
Exemplo n.º 10
0
 internal override string ToString(string indent)
 {
     if (OneLine())
     {
         return(string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", indent,
                              TsqlFragmentToString.UnaryExpressionType(ExpressionType), Expression.ToString("")));
     }
     else
     {
         return(string.Format(CultureInfo.CurrentCulture, "{0}{1}\r\n{2}", indent,
                              TsqlFragmentToString.UnaryExpressionType(ExpressionType), Expression.ToString(indent)));
     }
 }
Exemplo n.º 11
0
        public override void Visit(WBooleanComparisonExpression node)
        {
            node.FirstExpr.Accept(this);
            string left = this.dfsStack.Pop();

            node.SecondExpr.Accept(this);
            string right = this.dfsStack.Pop();

            // TODO: Consider to ues ISNULLExpression
            string nodeStr = right == "null"
                ? $"{left} IS {right}"
                : $"{left} {TsqlFragmentToString.BooleanComparisonType(node.ComparisonType)} {right}";

            this.dfsStack.Push(nodeStr);
        }
Exemplo n.º 12
0
        internal override string ToString(string indent)
        {
            var sb = new StringBuilder(512);

            sb.Append(FirstExpr.ToString(indent));
            sb.AppendFormat(" {0} ", TsqlFragmentToString.BinaryExpressionType(ExpressionType));

            if (SecondExpr.OneLine())
            {
                sb.Append(SecondExpr.ToString(""));
            }
            else
            {
                sb.Append("\r\n");
                sb.Append(SecondExpr.ToString(indent));
            }

            return(sb.ToString());
        }
Exemplo n.º 13
0
        internal override string ToString(string indent)
        {
            var sb = new StringBuilder(32);

            sb.Append(FirstTableRef.ToString(indent) + "\n");

            sb.AppendFormat(" {1}\t{0} ", TsqlFragmentToString.JoinType(UnqualifiedJoinType), indent);

            //if (SecondTableRef.OneLine())
            //{
            //    sb.Append(SecondTableRef);
            //}
            //else
            {
                //sb.Append("\r\n");
                sb.Append(SecondTableRef.ToString(""));
            }

            return(sb.ToString());
        }
Exemplo n.º 14
0
        internal override string ToString(string indent, bool useSquareBracket)
        {
            var sb = new StringBuilder(512);

            sb.Append(FirstExpr.ToString(indent, useSquareBracket));

            sb.AppendFormat(" {0} ", TsqlFragmentToString.BooleanComparisonType(ComparisonType));

            if (SecondExpr.OneLine())
            {
                sb.Append(SecondExpr.ToString("", useSquareBracket));
            }
            else
            {
                sb.Append("\r\n");
                sb.Append(SecondExpr.ToString(indent + "    ", useSquareBracket));
            }

            return(sb.ToString());
        }
Exemplo n.º 15
0
        protected string FunctionBodyToString(string indent)
        {
            var sb = new StringBuilder();

            switch (ReturnType.GetType().Name)
            {
            case "WScalarFunctionReturnType":
            {
                var sftype = ReturnType as WScalarFunctionReturnType;

                sb.AppendFormat("{0}RETURNS {1}\r\n", indent, TsqlFragmentToString.DataType(sftype.DataType));
                sb.AppendFormat("{0}AS\r\n", indent);
                sb.Append(StatementListToString(StatementList, indent));

                break;
            }

            case "WSelectFunctionReturnType":
            {
                sb.AppendFormat("{0}RETURNS TABLE\r\n", indent);
                sb.AppendFormat("{0}RETURN (\r\n", indent);
                sb.AppendFormat(CultureInfo.CurrentCulture, StatementListToString(StatementList, indent));
                sb.Append("\r\n");
                sb.AppendFormat("{0});", indent);

                break;
            }

            case "WTableValuedFunctionReturnType":
            {
                break;
            }

            default:
                break;
            }

            return(sb.ToString());
        }
Exemplo n.º 16
0
        public override void Visit(WBooleanComparisonExpression node)
        {
            node.FirstExpr.Accept(this);
            string left = this.dfsStack.Pop();

            node.SecondExpr.Accept(this);
            string right = this.dfsStack.Pop();

            string nodeStr;

            if (node.ComparisonType == BooleanComparisonType.Equals && right == "null")
            {
                // IS_DEFINED(N_18._isEdgeDoc) = false
                nodeStr = $"IS_DEFINED({left}) = false";
            }
            else
            {
                nodeStr = $"{left} {TsqlFragmentToString.BooleanComparisonType(node.ComparisonType)} {right}";
            }

            this.dfsStack.Push(nodeStr);
        }
Exemplo n.º 17
0
        internal override string ToString(string indent)
        {
            string str = null;

            if (Column != null)
            {
                str = string.Format(CultureInfo.CurrentCulture, "{0} {1} ", Column.ToString(indent), TsqlFragmentToString.AssignmentType(AssignmentKind));

                if (OneLine())
                {
                    if (NewValue != null)
                    {
                        str += NewValue.ToString("");
                    }
                    else if (Variable != null)
                    {
                        str += Variable;
                    }
                }
                else
                {
                    if (NewValue != null)
                    {
                        str = string.Format(CultureInfo.CurrentCulture, "{0}\r\n{1}", str, NewValue.ToString(indent + " "));
                    }
                    else if (Variable != null)
                    {
                        str = string.Format(CultureInfo.CurrentCulture, "{0}\r\n{1}{2}", str, indent, Variable);
                    }
                }
            }
            else
            {
                str = string.Format(CultureInfo.CurrentCulture, "{0} {1} ", Variable, TsqlFragmentToString.AssignmentType(AssignmentKind));

                str = str + NewValue.ToString(indent);
            }
            return(str);
        }
Exemplo n.º 18
0
        // Turns T-SQL OptimizerHint into string
        internal static string OptimizerHintToString(OptimizerHint hint)
        {
            var sb = new StringBuilder(1024);

            // Literal hint
            if (hint is LiteralOptimizerHint)
            {
                sb.Append(TsqlFragmentToString.OptimizerHintKind(hint.HintKind));
                var loh = hint as LiteralOptimizerHint;

                // TODO: Only support numeric literal
                sb.AppendFormat(" {0}", loh.Value.Value);
            }
            // OptimizeFor hint
            else if (hint is OptimizeForOptimizerHint)
            {
                var ooh = hint as OptimizeForOptimizerHint;
                sb.AppendFormat("OPTIMIZE FOR ");
                if (ooh.IsForUnknown)
                {
                    sb.Append("UNKNOWN");
                }
                else
                {
                    sb.Append("(");
                    for (int i = 0; i < ooh.Pairs.Count; i++)
                    {
                        if (i > 0)
                        {
                            sb.Append(", ");
                        }
                        sb.Append(ooh.Pairs[i].Variable.Name);

                        // TODO: Only support value expression
                        if (ooh.Pairs[i].Value != null && ooh.Pairs[i].Value is Literal)
                        {
                            if (ooh.Pairs[i].Value is StringLiteral)
                            {
                                sb.AppendFormat(" = '{0}'", ((Literal)ooh.Pairs[i].Value).Value);
                            }
                            else
                            {
                                sb.AppendFormat(" = {0}", ((Literal)ooh.Pairs[i].Value).Value);
                            }
                        }
                        else
                        {
                            sb.Append(" UNKNOWN");
                        }
                    }
                    sb.Append(")");
                }
            }
            // Table hint
            else if (hint is TableHintsOptimizerHint)
            {
                var toh = hint as TableHintsOptimizerHint;
                sb.Append("TABLE HINT ");
                sb.Append("(");
                // sb.Append(TsqlFragmentToString.WSchemaObjectName(toh.ObjectName));
                for (int i = 0; i < toh.TableHints.Count; i++)
                {
                    if (i > 0)
                    {
                        sb.Append(", ");
                    }
                    // TODO: Table hint in WSQL Syntax tree is incomplete
                    sb.AppendFormat("@{0}", toh.TableHints[i].HintKind.ToString());
                }
                sb.Append(")");
            }
            // Regular hint
            else
            {
                sb.Append(TsqlFragmentToString.OptimizerHintKind(hint.HintKind));
            }
            return(sb.ToString());
        }