예제 #1
0
        public override object Execute(Expression inputExpression)
        {
            Stopwatch  watch = Stopwatch.StartNew();
            Expression partiallyEvaluatedExpression = PartialEvaluator.Eval(inputExpression, CanBeEvaluatedStatically);

            QueryExecutionOptions options    = new QueryExecutionOptions();
            Expression            expression = new ConvertToQueryAstVisitor(options).Visit(partiallyEvaluatedExpression);

            // options have been initialized by ConvertToQueryAstVisitor, start logging:
            if (options.HasLoggers)
            {
                options.WriteLogLine("Input expression: " + inputExpression);
                options.WriteLogLine("Partially evaluated expression: " + partiallyEvaluatedExpression);
                options.WriteLogLine("Converted to Query AST: " + expression);
            }

            expression = new OptimizeQueryExpressionVisitor().Visit(expression);
            if (options.HasLoggers)
            {
                options.WriteLogLine("Optimized Query AST: " + expression);
                options.WriteLogLine("Query preparation time: " + watch.Elapsed);
            }

            object result;
            // If the whole query was converted, execute it:
            QueryNode query = expression as QueryNode;

            if (query != null)
            {
                result = query.Execute(this, options);
            }
            else
            {
                // Query not converted completely: we have to use a LINQ-To-Objects / LINQ-To-Profiler mix
                expression = new ExecuteAllQueriesVisitor(this, options).Visit(expression);
                if (expression.Type.IsValueType)
                {
                    expression = Expression.Convert(expression, typeof(object));
                }
                var lambdaExpression = Expression.Lambda <Func <object> >(expression);
                result = lambdaExpression.Compile()();
            }
            watch.Stop();
            options.WriteLogLine("Total query execution time: " + watch.Elapsed);
            return(result);
        }
예제 #2
0
        public IQueryable <CallTreeNode> Execute(SQLiteQueryProvider provider, QueryExecutionOptions options)
        {
            StringBuilder   b       = new StringBuilder();
            SqlQueryContext context = new SqlQueryContext(provider);

            BuildSql(b, context);
            if (options.HasLoggers)
            {
                options.WriteLogLine(b.ToString());
            }
            Stopwatch            w      = Stopwatch.StartNew();
            IList <CallTreeNode> result = provider.RunSQLNodeList(b.ToString(), context.HasIDList);

            w.Stop();
            if (options.HasLoggers)
            {
                options.WriteLogLine("Query returned " + result.Count + " rows in " + w.Elapsed);
            }
            return(result.AsQueryable());
        }
예제 #3
0
 public ExecuteAllQueriesVisitor(SQLiteQueryProvider sqliteProvider, QueryExecutionOptions options)
 {
     this.sqliteProvider = sqliteProvider;
     this.options        = options;
 }
예제 #4
0
 public ConvertToQueryAstVisitor(QueryExecutionOptions options)
 {
     this.options = options;
 }
예제 #5
0
		public IQueryable<CallTreeNode> Execute(SQLiteQueryProvider provider, QueryExecutionOptions options)
		{
			StringBuilder b = new StringBuilder();
			SqlQueryContext context = new SqlQueryContext(provider);
			BuildSql(b, context);
			if (options.HasLoggers)
				options.WriteLogLine(b.ToString());
			Stopwatch w = Stopwatch.StartNew();
			IList<CallTreeNode> result = provider.RunSQLNodeList(b.ToString(), context.HasIDList);
			w.Stop();
			if (options.HasLoggers) {
				options.WriteLogLine("Query returned " + result.Count + " rows in " + w.Elapsed);
			}
			return result.AsQueryable();
		}
			public ExecuteAllQueriesVisitor(SQLiteQueryProvider sqliteProvider, QueryExecutionOptions options)
			{
				this.sqliteProvider = sqliteProvider;
				this.options = options;
			}
			public ConvertToQueryAstVisitor(QueryExecutionOptions options)
			{
				this.options = options;
			}
		public override object Execute(Expression inputExpression)
		{
			Stopwatch watch = Stopwatch.StartNew();
			Expression partiallyEvaluatedExpression = PartialEvaluator.Eval(inputExpression, CanBeEvaluatedStatically);
			
			QueryExecutionOptions options = new QueryExecutionOptions();
			Expression expression = new ConvertToQueryAstVisitor(options).Visit(partiallyEvaluatedExpression);
			// options have been initialized by ConvertToQueryAstVisitor, start logging:
			if (options.HasLoggers) {
				options.WriteLogLine("Input expression: " + inputExpression);
				options.WriteLogLine("Partially evaluated expression: " + partiallyEvaluatedExpression);
				options.WriteLogLine("Converted to Query AST: " + expression);
			}
			
			expression = new OptimizeQueryExpressionVisitor().Visit(expression);
			if (options.HasLoggers) {
				options.WriteLogLine("Optimized Query AST: " + expression);
				options.WriteLogLine("Query preparation time: " + watch.Elapsed);
			}
			
			object result;
			// If the whole query was converted, execute it:
			QueryNode query = expression as QueryNode;
			if (query != null) {
				result = query.Execute(this, options);
			} else {
				// Query not converted completely: we have to use a LINQ-To-Objects / LINQ-To-Profiler mix
				expression = new ExecuteAllQueriesVisitor(this, options).Visit(expression);
				if (expression.Type.IsValueType) {
					expression = Expression.Convert(expression, typeof(object));
				}
				var lambdaExpression = Expression.Lambda<Func<object>>(expression);
				result = lambdaExpression.Compile()();
			}
			watch.Stop();
			options.WriteLogLine("Total query execution time: " + watch.Elapsed);
			return result;
		}