コード例 #1
0
        public static string GetSqlStart(UserId requesterId, SqlQuerySource source)
        {
            bool fetchAdditionalColumns = source == SqlQuerySource.PreviewNewsfeed || source == SqlQuerySource.FullPost;

            var result = new StringBuilder();

            if (source == SqlQuerySource.FullPost)
            {
                result.Append(string.Format(
                                  "SELECT {0}, {1}, {2}, {3}, ",
                                  Post.Fields.Content,
                                  Post.Fields.PreviewText,
                                  Blog.Fields.HeaderImageFileId,
                                  Blog.Fields.Introduction));
            }
            else
            {
                result.Append(string.Format("SELECT {0},", Post.Fields.PreviewText));
            }

            result.Append(SqlSelectPartial);

            if (requesterId != null)
            {
                result.Append(SqlHasLikedSelect);

                if (fetchAdditionalColumns)
                {
                    result.Append(SqlIsFreePostSelect);
                }
            }

            if (fetchAdditionalColumns)
            {
                result.Append(SqlPreviewInformationSelect);
            }

            result.Append(SqlFromPartial);

            if (requesterId != null)
            {
                result.Append(SqlHasLikedFromClause);

                if (fetchAdditionalColumns)
                {
                    result.Append(SqlIsFreePostFromClause);
                }
            }

            if (fetchAdditionalColumns)
            {
                result.Append(SqlPreviewInformationClause);
            }

            return(result.ToString());
        }
コード例 #2
0
        private void GenerateSource(SqlGenerator sql, SqlQuerySource from)
        {
            if (from is SqlTableSource table)
            {
                sql.Add($"{table.Name} {table.Alias}");
                return;
            }
            // Select 10 as value
            if (from is SqlConstantSource constant)
            {
                sql.NewLine();
                sql.Add("SELECT ");

                GenerateCommaSep(sql, constant.ValueExpressions, false, (exp, i) => {
                    sql.Add($"{GenerateConstant(exp)} AS {constant.Columns[i].Name}");
                });

                return;
            }
            if (from is SqlSubQuerySource sub)
            {
                sql.Add("(");
                GenerateSource(sql, sub.Source);
                sql.Add($") {sub.Alias}");
                return;
            }
            if (from is SqlUnionSource union)
            {
                sql.Add("(");
                sql.Indent();
                foreach (var u in union.Sources)
                {
                    GenerateSource(sql, u);
                    if (u != union.Sources.Last())
                    {
                        sql.NewLine();
                        sql.Add(union.UnionAll ? "UNION ALL" : "UNION");
                    }
                }
                sql.UnIndent();
                sql.NewLine();
                sql.Add($") {union.Alias}");
                return;
            }
            throw new NotImplementedException($"Could not generate source from {from.GetType()}");
        }
コード例 #3
0
 public SqlSubQuerySource(SqlQuerySource source, string alias) : base(source.Columns, alias)
 {
     Source = source;
 }
コード例 #4
0
 public SqlColumnExpression(FieldType type, string name, SqlQuerySource source) : base(type)
 {
     Name   = name;
     Source = source;
 }