Beispiel #1
0
        public override DbExpression Visit(DbUpdateExpression exp)
        {
            this.SqlBuilder.Append("UPDATE ");
            this.AppendTable(exp.Table);
            this.SqlBuilder.Append(" SET ");

            bool first = true;

            foreach (var item in exp.UpdateColumns)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    this.SqlBuilder.Append(",");
                }

                this.QuoteName(item.Key.Name);
                this.SqlBuilder.Append("=");

                DbExpression valExp = item.Value.StripInvalidConvert();
                AmendDbInfo(item.Key, valExp);
                DbValueExpressionTransformer.Transform(valExp).Accept(this);
            }

            this.BuildWhereState(exp.Condition);

            return(exp);
        }
Beispiel #2
0
 void AppendColumnSegment(DbColumnSegment seg)
 {
     DbValueExpressionTransformer.Transform(seg.Body).Accept(this);
     this.SqlBuilder.Append(" AS ");
     this.QuoteName(seg.Alias);
 }
Beispiel #3
0
        public override DbExpression Visit(DbInsertExpression exp)
        {
            this.SqlBuilder.Append("INSERT INTO ");
            this.AppendTable(exp.Table);
            this.SqlBuilder.Append("(");

            bool first = true;

            foreach (var item in exp.InsertColumns)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    this.SqlBuilder.Append(",");
                }

                this.QuoteName(item.Key.Name);
            }

            this.SqlBuilder.Append(")");

            this.SqlBuilder.Append(" VALUES(");
            first = true;
            foreach (var item in exp.InsertColumns)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    this.SqlBuilder.Append(",");
                }

                DbExpression valExp = item.Value.StripInvalidConvert();
                AmendDbInfo(item.Key, valExp);
                DbValueExpressionTransformer.Transform(valExp).Accept(this);
            }

            this.SqlBuilder.Append(")");

            if (exp.Returns.Count > 0)
            {
                this.SqlBuilder.Append(" RETURNING ");

                string outputParamNames = "";
                for (int i = 0; i < exp.Returns.Count; i++)
                {
                    if (i > 0)
                    {
                        this.SqlBuilder.Append(",");
                        outputParamNames = outputParamNames + ",";
                    }

                    DbColumn outputColumn = exp.Returns[i];
                    string   paramName    = Utils.GenOutputColumnParameterName(outputColumn.Name);
                    DbParam  outputParam  = new DbParam()
                    {
                        Name = paramName, DbType = outputColumn.DbType, Precision = outputColumn.Precision, Scale = outputColumn.Scale, Size = outputColumn.Size, Value = DBNull.Value, Direction = ParamDirection.Output
                    };
                    outputParam.Type = outputColumn.Type;

                    this.QuoteName(outputColumn.Name);
                    outputParamNames = outputParamNames + paramName;

                    this._parameters.Add(outputParam);
                }

                this.SqlBuilder.Append(" INTO ", outputParamNames);
            }

            return(exp);
        }
Beispiel #4
0
 static DbExpression EnsureDbExpressionReturnCSharpBoolean(DbExpression exp)
 {
     return(DbValueExpressionTransformer.Transform(exp));
 }