Exemple #1
0
        IStatement IPreparableStatement.Prepare(IRequest request)
        {
            var tableName = request.Query.ResolveTableName(TableName);

            if (!request.Query.TableExists(tableName))
            {
                throw new ObjectNotFoundException(tableName);
            }

            var queryExp = new SqlQueryExpression(new SelectColumn[] { SelectColumn.Glob("*") });

            queryExp.FromClause.AddTable(tableName.FullName);
            queryExp.WhereExpression = WhereExpression;

            var queryInfo = new QueryInfo(request, queryExp);

            if (Limit > 0)
            {
                queryInfo.Limit = new QueryLimit(Limit);
            }

            var queryPlan = request.Query.Context.QueryPlanner().PlanQuery(queryInfo);

            return(new Prepared(tableName, queryPlan));
        }
        protected override SqlStatement PrepareStatement(IRequest context)
        {
            var tableName = context.Access().ResolveTableName(TableName);

            if (!context.Access().TableExists(tableName))
            {
                throw new ObjectNotFoundException(tableName);
            }

            var queryExpression = new SqlQueryExpression(new[] { SelectColumn.Glob("*") });

            queryExpression.FromClause.AddTable(tableName.FullName);
            queryExpression.WhereExpression = WherExpression;

            var queryFrom = QueryExpressionFrom.Create(context, queryExpression);
            var queryPlan = context.Query.Context.QueryPlanner().PlanQuery(new QueryInfo(context, queryExpression));

            var columns = new List <SqlAssignExpression>();

            foreach (var assignment in Assignments)
            {
                var columnName = ObjectName.Parse(assignment.ColumnName);

                var refName    = queryFrom.ResolveReference(columnName);
                var expression = assignment.Expression.Prepare(queryFrom.ExpressionPreparer);

                var assign = SqlExpression.Assign(SqlExpression.Reference(refName), expression);
                columns.Add(assign);
            }

            return(new Prepared(tableName, queryPlan, columns.ToArray(), Limit));
        }
        public static int DeleteFrom(this IQuery context, ObjectName tableName, SqlExpression expression, int limit)
        {
            if (expression is SqlQueryExpression)
            {
                return(context.DeleteFrom(tableName, (SqlQueryExpression)expression, limit));
            }

            var table = context.GetMutableTable(tableName);

            if (table == null)
            {
                throw new ObjectNotFoundException(tableName);
            }

            var queryExpression = new SqlQueryExpression(new List <SelectColumn> {
                SelectColumn.Glob("*")
            });

            queryExpression.FromClause.AddTable(tableName.Name);
            queryExpression.WhereExpression = expression;

            var planExpression = queryExpression.Evaluate(context, null);
            var plan           = (SqlQueryObject)((SqlConstantExpression)planExpression).Value.Value;
            var deleteSet      = plan.QueryPlan.Evaluate(context);

            return(context.DeleteFrom(tableName, deleteSet, limit));
        }
Exemple #4
0
        protected override SqlStatement PrepareStatement(IRequest context)
        {
            var tableName = context.Access().ResolveTableName(TableName);

            if (!context.Access().TableExists(tableName))
            {
                throw new ObjectNotFoundException(tableName);
            }

            var queryExp = new SqlQueryExpression(new SelectColumn[] { SelectColumn.Glob("*") });

            queryExp.FromClause.AddTable(tableName.FullName);
            queryExp.WhereExpression = WhereExpression;

            var queryInfo = new QueryInfo(context, queryExp);

            if (Limit > 0)
            {
                queryInfo.Limit = new QueryLimit(Limit);
            }

            var queryPlan = context.Query.Context.QueryPlanner().PlanQuery(queryInfo);

            return(new Prepared(tableName, queryPlan));
        }