Exemplo n.º 1
0
        protected sealed override string OnParseInsert()
        {
            var builder = new StringBuilder();

            builder.AppendFormat("Insert Into {0} (", MsSqlHelper.FormatSymbolName(Name));
            var retriever = new SqlMemberExpressionRetriever();

            foreach (var column in Columns)
            {
                column.Accept(retriever);
            }
            using (var e = retriever.Members.GetEnumerator())
            {
                if (Parameters.Count == 0)
                {
                    throw new InvalidOperationException("parameter count is zero");
                }

                if (e.MoveNext())
                {
                    builder.AppendFormat("[{0}]", e.Current.Name);
                    while (e.MoveNext())
                    {
                        builder.AppendLine();
                        builder.AppendFormat(", [{0}]", e.Current.Name);
                    }
                }
            }

            builder.Append(") Values (");
            using (var e = retriever.Members.GetEnumerator())
            {
                if (e.MoveNext())
                {
                    builder.AppendFormat("@{0}", e.Current.Name);
                    while (e.MoveNext())
                    {
                        builder.AppendLine();
                        builder.AppendFormat(", @{0}", e.Current.Name);
                    }
                }
            }

            builder.AppendFormat(")");
            return(builder.ToString());
        }
Exemplo n.º 2
0
        protected sealed override string OnParseUpdate()
        {
            var builder = new StringBuilder();

            builder.AppendFormat("Update {0}", MsSqlHelper.FormatSymbolName(Name)).AppendLine();
            var retriever = new SqlMemberExpressionRetriever();

            foreach (var column in Columns)
            {
                column.Accept(retriever);
            }
            using (var e = retriever.Members.GetEnumerator())
            {
                if (!e.MoveNext())
                {
                    throw new InvalidOperationException("parameter count is zero");
                }

                builder.AppendFormat("Set [{0}] = @{0}", e.Current.Name).AppendLine();
                while (e.MoveNext())
                {
                    builder.AppendFormat(", [{0}] = @{0}", e.Current.Name).AppendLine();
                }
            }
            builder.AppendFormat("From {0}", MsSqlHelper.FormatSymbolName(Name));
            //foreach (var inner in _inners)
            //{
            //    builder.AppendLine();
            //    inner.Parser();
            //    builder.Append(inner.Sql);
            //}
            if (Condition != null)
            {
                builder.AppendLine();
                builder.Append("Where ");
                var visitor = new MsSqlExpressionVisitor();
                var expre   = MsSqlExpressionVisitor.LogicExpression(Condition);
                expre.Accept(visitor);
                builder.Append(visitor.Complier());
            }

            return(builder.ToString());
        }