コード例 #1
0
        protected override Expression VisitDeclaration(DbDeclarationCommand decl)
        {
            if (decl.Source != null)
            {
                this.Visit(decl.Source);

                return(decl);
            }

            return(base.VisitDeclaration(decl));
        }
コード例 #2
0
        protected override Expression VisitDeclaration(DbDeclarationCommand decl)
        {
            if (this.Language.AllowsMultipleCommands == false)
            {
                return(base.VisitDeclaration(decl));
            }

            for (int i = 0, n = decl.Variables.Count; i < n; i++)
            {
                var v = decl.Variables[i];

                if (i > 0)
                {
                    this.WriteLine(Indentation.Same);
                }

                this.Write("DECLARE @");
                this.Write(v.Name);
                this.Write(" ");
                this.Write(this.Language.TypeSystem.GetVariableDeclaration(v.QueryType, false));
            }

            if (decl.Source != null)
            {
                this.WriteLine(Indentation.Same);
                this.Write("SELECT ");

                for (int i = 0, n = decl.Variables.Count; i < n; i++)
                {
                    if (i > 0)
                    {
                        this.Write(", ");
                    }

                    this.Write("@");
                    this.Write(decl.Variables[i].Name);
                    this.Write(" = ");
                    this.Visit(decl.Source.Columns[i].Expression);
                }

                if (decl.Source.From != null)
                {
                    this.WriteLine(Indentation.Same);
                    this.Write("FROM ");
                    this.VisitSource(decl.Source.From);
                }

                if (decl.Source.Where != null)
                {
                    this.WriteLine(Indentation.Same);
                    this.Write("WHERE ");
                    this.Visit(decl.Source.Where);
                }
            }
            else
            {
                for (int i = 0, n = decl.Variables.Count; i < n; i++)
                {
                    var v = decl.Variables[i];

                    if (v.Expression != null)
                    {
                        this.WriteLine(Indentation.Same);
                        this.Write("SET @");
                        this.Write(v.Name);
                        this.Write(" = ");
                        this.Visit(v.Expression);
                    }
                }
            }

            return(decl);
        }