Пример #1
0
        public virtual object Execute()
        {
            SQLCeVisitor <T> visitor = new SQLCeVisitor <T>();

            visitor.Visite(ContentQuery.Expression);

            switch (visitor.CallType)
            {
            case Kooboo.CMS.Content.Query.Expressions.CallType.Count:
                return(Count(visitor));

            case Kooboo.CMS.Content.Query.Expressions.CallType.First:
                return(First(visitor));

            case Kooboo.CMS.Content.Query.Expressions.CallType.LastOrDefault:
                return(LastOrDefault(visitor));

            case Kooboo.CMS.Content.Query.Expressions.CallType.FirstOrDefault:
                return(FirstOrDefault(visitor));

            case Kooboo.CMS.Content.Query.Expressions.CallType.Last:
                return(Last(visitor));

            case Kooboo.CMS.Content.Query.Expressions.CallType.Unspecified:
            default:
                return(List(visitor));
            }
        }
Пример #2
0
        private SQLCeVisitor <T> VisitInner(IExpression expression)
        {
            SQLCeVisitor <T> visitor = new SQLCeVisitor <T>(this.Parameters);

            visitor.Visite(expression);

            //combine the order expressions.
            this.OrderClauses.AddRange(visitor.OrderClauses);

            this.CategoryQueries = this.CategoryQueries.Concat(visitor.CategoryQueries);

            return(visitor);
        }
Пример #3
0
        public override string BuildQuerySQL(SQLCeVisitor <Models.TextContent> visitor, out IEnumerable <Parameter> parameters)
        {
            var innerVisitor = new SQLCeVisitor <Models.TextContent>(visitor.Parameters);

            innerVisitor.Visite(childrenQuery.ParentQuery.Expression);
            var innerExecutor = (new TextContentTranslator()).Translate(childrenQuery.ParentQuery);
            var innerQuerySQL = innerExecutor.BuildQuerySQL(innerVisitor, out parameters);

            string selectClause = "*";

            if (visitor.SelectFields != null && visitor.SelectFields.Length > 0)
            {
                selectClause = string.Join(",", visitor.SelectFields);
            }

            string whereClause = visitor.WhereClause;

            if (childrenQuery.EmbeddedFolder != null)
            {
                var paraName = visitor.AppendParameter(childrenQuery.EmbeddedFolder.FullName);
                whereClause = whereClause + " AND FolderName=" + paraName;
            }
            //var paraName = visitor.AppendParameter(parentQuery.ChildrenQuery.FullName);
            //whereClause = whereClause + "AND FolderName=" + paraName;

            string sql = string.Format(@"
            SELECT {0} FROM [{1}] children                            
               WHERE  EXISTS(
                        SELECT UUID
                            FROM ({2})parent
                            WHERE parent.UUID = children.ParentUUID 
                      ) AND {3}", selectClause
                                       , childrenQuery.ChildSchema.GetTableName()
                                       , innerQuerySQL
                                       , whereClause);

            return(sql);
        }
Пример #4
0
        public override string BuildQuerySQL(SQLCeVisitor <TextContent> visitor, out IEnumerable <Parameter> parameters)
        {
            var innerVisitor = new SQLCeVisitor <Models.TextContent>(visitor.Parameters);

            innerVisitor.Visite(categoriesQuery.InnerQuery.Expression);
            var innerExecutor = (new TextContentTranslator()).Translate(categoriesQuery.InnerQuery);
            var innerQuerySQL = innerExecutor.BuildQuerySQL(innerVisitor, out parameters);

            string selectClause = "*";

            if (visitor.SelectFields != null && visitor.SelectFields.Length > 0)
            {
                selectClause = string.Join(",", visitor.SelectFields);
            }

            string whereClause = visitor.WhereClause;

            var paraName = visitor.AppendParameter(categoriesQuery.CategoryFolder.FullName);

            whereClause = whereClause + " AND FolderName=" + paraName;


            string sql = string.Format(@"
            SELECT {0} FROM [{1}] category
               WHERE  EXISTS(
                        SELECT ContentCategory.CategoryUUID 
                            FROM [{2}] ContentCategory,
                                ({3})content
                            WHERE content.UUID = ContentCategory.UUID AND ContentCategory.CategoryUUID = category.UUID 
                      ) AND {4}", selectClause
                                       , categoriesQuery.CategoryFolder.GetSchema().GetTableName()
                                       , categoriesQuery.Repository.GetCategoryTableName()
                                       , innerQuerySQL
                                       , whereClause);

            return(sql);
        }
Пример #5
0
        private IEnumerable <string> GetCategoryClause(Repository repository, IEnumerable <IContentQuery <TextContent> > categoryQueries, List <Parameter> parameters)
        {
            TextContentTranslator translator        = new TextContentTranslator();
            List <string>         categoryQueryList = new List <string>();

            foreach (var categoryQuery in categoryQueries)
            {
                var executor        = translator.Translate(categoryQuery);
                var categoryVisitor = new SQLCeVisitor <TextContent>(parameters);
                categoryVisitor.Visite(categoryQuery.Expression);

                IEnumerable <Parameter> outParameters;
                var categoryQuerySQL = executor.BuildQuerySQL(categoryVisitor, out outParameters);

                categoryQueryList.Add(string.Format(@"EXISTS(
                        SELECT ContentCategory.CategoryUUID 
                            FROM [{0}] ContentCategory,
                                ({1})category
                            WHERE content.UUID = ContentCategory.UUID AND ContentCategory.CategoryUUID = category.UUID 
                      )", repository.GetCategoryTableName()
                                                    , categoryQuerySQL));
            }
            return(categoryQueryList);
        }