示例#1
0
        public override string ToSql(ExpressionSqlBuilder builder)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("update ");
            if (builder.DbType == DriverType.PostgreSQL)
            {
                sb.Append(TableClause.ToSql(builder));
                writeSET(sb, builder);
            }
            if (builder.DbType == DriverType.SqlServer)
            {
                if (string.IsNullOrEmpty(TableClause.Alias))
                {
                    sb.Append(TableClause.ToSql(builder));
                    writeSET(sb, builder);
                }
                else
                {
                    sb.Append(builder.EncodeTable(TableClause.Alias) + " ");
                    writeSET(sb, builder);
                    sb.Append(" from ").Append(TableClause.ToSql(builder)).Append(" ");
                }
            }

            AddReturningToSql1(builder, sb);
            if (Where != null)
            {
                sb.Append(" where ").Append(Where.ToSql(builder));
            }
            AddReturningToSql2(builder, sb);
            return(sb.ToString());
        }
示例#2
0
        public override string ToSql(ExpressionSqlBuilder builder)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("insert into ").Append(TableClause.ToSql(builder));
            if (DefaultValues)
            {
                sb.Append(" DEFAULT VALUES");
                AddReturningToSql1(builder, sb);
            }
            else
            {
                if (ColumnOfValues.Count > 0)
                {
                    sb.Append(" ( ");
                    for (int i = 0; i < ColumnOfValues.Count; i++)
                    {
                        var sc = ColumnOfValues[i];
                        if (i > 0)
                        {
                            sb.Append(", ");
                        }

                        if (!(sc is FieldExpr))
                        {
                            throw new Exception("В перечне колонок INSERT INTO () должны быть простые имена колонок");
                        }
                        FieldExpr fe = sc as FieldExpr;
                        sb.Append(fe.ToSqlShort(builder));
                    }
                    sb.Append(")");
                }
                AddReturningToSql1(builder, sb);
                if (Values != null && Values.Count > 0)
                {
                    sb.Append(" values");
                    for (int i = 0; i < Values.Count; i++)
                    {
                        var sc = Values[i];
                        if (i > 0)
                        {
                            sb.Append(", ");
                        }
                        sb.Append(sc.ToSql(builder));
                    }
                }
                else
                {
                    sb.Append(" ").Append(Select.ToSql(builder));
                }
            }
            AddReturningToSql2(builder, sb);
            return(sb.ToString());
        }
示例#3
0
        public override string ToSql(ExpressionSqlBuilder builder)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("delete ");
            if (builder.DbType == DriverType.SqlServer)
            {
                if (!string.IsNullOrEmpty(TableClause.Alias))
                {
                    sb.Append(builder.EncodeTable(TableClause.Alias)).Append(" ");
                }
            }
            sb.Append("from ");
            sb.Append(TableClause.ToSql(builder)).Append(" ");
            AddReturningToSql1(builder, sb);
            if (Where != null)
            {
                sb.Append(" where ").Append(Where.ToSql(builder));
            }
            AddReturningToSql2(builder, sb);
            return(sb.ToString());
        }