Exemple #1
0
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var reference = Reference.Prepare(preparer);
            var query     = (SqlQueryExpression)QueryExpression.Prepare(preparer);

            return(new SelectIntoStatement(query, reference));
        }
Exemple #2
0
        protected override SqlPreparedStatement PrepareStatement(IExpressionPreparer preparer, IQueryContext context)
        {
            var tableName = context.ResolveTableName(TableName);
            if (!context.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.DatabaseContext().QueryPlanner().PlanQuery(context, queryExpression, null);

            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);
        }
		protected override AlterTableAction PrepareExpressions(IExpressionPreparer preparer) {
			var defaultExp = DefaultExpression;
			if (defaultExp != null)
				defaultExp = defaultExp.Prepare(preparer);

			return new SetDefaultAction(ColumnName, defaultExp);
		}
Exemple #4
0
        private ITable PrepareAndExecute(IExpressionPreparer preparer, IRequest context)
        {
            IExecutable prepared;

            try {
                prepared = this.Prepare(preparer, context);
            } catch (Exception ex) {
                throw new InvalidOperationException("Unable to prepare the statement for execution.", ex);
            }

            if (prepared == null)
            {
                throw new InvalidOperationException();
            }

            var exeContext = new ExecutionContext(context);

            prepared.Execute(exeContext);
            if (!exeContext.HasResult)
            {
                return(FunctionTable.ResultTable(context, 0));
            }

            return(exeContext.Result);
        }
        public static IStatement Prepare(this IStatement statement, IExpressionPreparer preparer)
        {
            if (statement is IPreparable)
                statement = ((IPreparable) statement).Prepare(preparer) as IStatement;

            return statement;
        }
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            ConstraintInfo constraint;

            if (Constraint.ConstraintType == ConstraintType.Check) {
                var exp = Constraint.CheckExpression;
                if (exp != null)
                    exp = exp.Prepare(preparer);

                constraint = ConstraintInfo.Check(Constraint.ConstraintName, Constraint.TableName, exp, Constraint.ColumnNames);
            } else if (Constraint.ConstraintType == ConstraintType.Unique) {
                constraint = ConstraintInfo.Unique(Constraint.ConstraintName, Constraint.TableName, Constraint.ColumnNames);
            } else if (Constraint.ConstraintType == ConstraintType.PrimaryKey) {
                constraint = ConstraintInfo.PrimaryKey(Constraint.ConstraintName, Constraint.TableName, Constraint.ColumnNames);
            } else if (Constraint.ConstraintType == ConstraintType.ForeignKey) {
                constraint = ConstraintInfo.ForeignKey(Constraint.ConstraintName, Constraint.TableName, Constraint.ColumnNames,
                    Constraint.ForeignTable, Constraint.ForeignColumnNames);
                constraint.OnDelete = Constraint.OnDelete;
                constraint.OnUpdate = Constraint.OnUpdate;
            } else {
                throw new InvalidOperationException();
            }

            return new AddConstraintAction(constraint);
        }
Exemple #7
0
 public ByColumn Prepare(IExpressionPreparer preparer)
 {
     var exp = Expression;
     if (exp != null)
         exp = exp.Prepare(preparer);
     return new ByColumn(exp, Ascending);
 }
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var reference = Reference.Prepare(preparer);
            var query = (SqlQueryExpression) QueryExpression.Prepare(preparer);

            return new SelectIntoStatement(query, reference);
        }
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var varRef = VariableReference.Prepare(preparer);
            var value  = ValueExpression.Prepare(preparer);

            return(new AssignVariableStatement(varRef, value));
        }
Exemple #10
0
        public MemberEmitter(IExpressionPreparer expressionPreparer, IILGeneratorFactory ilGeneratorFactory)
        {
            ArgumentUtility.CheckNotNull("expressionPreparer", expressionPreparer);
            ArgumentUtility.CheckNotNull("ilGeneratorFactory", ilGeneratorFactory);

            _expressionPreparer = expressionPreparer;
            _ilGeneratorFactory = ilGeneratorFactory;
        }
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var action = Action;
            if (action is IPreparable)
                action = (IAlterTableAction)(action as IPreparable).Prepare(preparer);

            return new AlterTableStatement(TableName, action);
        }
Exemple #12
0
        protected override AlterTableAction PrepareExpressions(IExpressionPreparer preparer)
        {
            var defaultExp = DefaultExpression;
            if (defaultExp != null)
                defaultExp = defaultExp.Prepare(preparer);

            return new SetDefaultAction(ColumnName, defaultExp);
        }
Exemple #13
0
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var action = AlterAction;
            if (action is IPreparable)
                action = ((IPreparable)action).Prepare(preparer) as IAlterUserAction;

            return new AlterUserStatement(UserName, action);
        }
Exemple #14
0
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var expression = ReturnExpression;
            if (expression != null)
                expression = expression.Prepare(preparer);

            return new ReturnStatement(expression);
        }
Exemple #15
0
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var defaultExp = DefaultExpression;
            if (defaultExp != null)
                defaultExp = defaultExp.Prepare(preparer);

            return new SetDefaultAction(ColumnName, defaultExp);
        }
        protected override SqlPreparedStatement PrepareStatement(IExpressionPreparer preparer, IQueryContext context)
        {
            if (String.IsNullOrEmpty(TableName))
                throw new StatementPrepareException("The table name is required.");

            var tableName = context.ResolveTableName(TableName);
            return new Prepared(tableName, Action);
        }
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var expression = Expression;
            if (expression != null)
                expression = expression.Prepare(preparer);

            return new SqlColumnAssignment(ColumnName, expression);
        }
        public static IStatement Prepare(this IStatement statement, IExpressionPreparer preparer)
        {
            if (statement is IPreparable)
            {
                statement = ((IPreparable)statement).Prepare(preparer) as IStatement;
            }

            return(statement);
        }
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var body = (PlSqlBlockStatement)Body.Prepare(preparer);

            return(new CreateFunctionStatement(FunctionName, ReturnType, Parameters, body)
            {
                ReplaceIfExists = ReplaceIfExists
            });
        }
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var statement = new DeclareVariableStatement(VariableName, VariableType);
            if (DefaultExpression != null)
                statement.DefaultExpression = DefaultExpression.Prepare(preparer);

            statement.IsConstant = IsConstant;
            return statement;
        }
Exemple #21
0
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var column = new SqlTableColumn(ColumnName, ColumnType);
            if (DefaultExpression != null)
                column.DefaultExpression = DefaultExpression.Prepare(preparer);

            column.IsNotNull = IsNotNull;
            return column;
        }
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var label = Label;
            var whenExp = WhenExpression;
            if (whenExp != null)
                whenExp = whenExp.Prepare(preparer);

            return new LoopControlStatement(ControlType, label, whenExp);
        }
Exemple #23
0
        public ByColumn Prepare(IExpressionPreparer preparer)
        {
            var exp = Expression;

            if (exp != null)
            {
                exp = exp.Prepare(preparer);
            }
            return(new ByColumn(exp, Ascending));
        }
Exemple #24
0
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var offset = OffsetExpression;

            if (offset != null)
            {
                offset = offset.Prepare(preparer);
            }

            return(new FetchStatement(CursorName, Direction, offset));
        }
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var action = AlterAction;

            if (action is IPreparable)
            {
                action = ((IPreparable)action).Prepare(preparer) as IAlterUserAction;
            }

            return(new AlterUserStatement(UserName, action));
        }
Exemple #26
0
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var body = Body;

            if (body != null)
            {
                body = (PlSqlBlockStatement)body.Prepare(preparer);
            }

            return(new CreateTriggerStatement(TriggerName, TableName, body, EventTime, EventType));
        }
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var subQuery = SubQuery;

            if (subQuery != null)
            {
                subQuery = (SqlQueryExpression)subQuery.Prepare(preparer);
            }

            return(new FromTable(Name, subQuery, Alias));
        }
Exemple #28
0
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var exp = Expression;

            if (exp != null)
            {
                exp = exp.Prepare(preparer);
            }

            return(new SortColumn(exp, Ascending));
        }
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var action = Action;

            if (action is IPreparable)
            {
                action = (IAlterTableAction)(action as IPreparable).Prepare(preparer);
            }

            return(new AlterTableStatement(TableName, action));
        }
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var action = Action;

            if (action is IPreparable)
            {
                action = (IAlterTableAction)(action as IPreparable).Prepare(preparer);
            }

            return(new AlterTableStatement(TableName, action));
        }
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var expression = Expression;

            if (expression != null)
            {
                expression = expression.Prepare(preparer);
            }

            return(new SqlColumnAssignment(ColumnName, expression));
        }
Exemple #32
0
        /// <inheritdoc/>
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var exp = Expression;

            if (exp != null)
            {
                exp = exp.Prepare(preparer);
            }

            return(new SelectColumn(exp, Alias));
        }
Exemple #33
0
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var defaultExp = DefaultExpression;

            if (defaultExp != null)
            {
                defaultExp = defaultExp.Prepare(preparer);
            }

            return(new SetDefaultAction(ColumnName, defaultExp));
        }
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var expression = ReturnExpression;

            if (expression != null)
            {
                expression = expression.Prepare(preparer);
            }

            return(new ReturnStatement(expression));
        }
Exemple #35
0
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var statement = new DeclareVariableStatement(VariableName, VariableType);

            if (DefaultExpression != null)
            {
                statement.DefaultExpression = DefaultExpression.Prepare(preparer);
            }

            statement.IsConstant = IsConstant;
            return(statement);
        }
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var label   = Label;
            var whenExp = WhenExpression;

            if (whenExp != null)
            {
                whenExp = whenExp.Prepare(preparer);
            }

            return(new LoopControlStatement(ControlType, label, whenExp));
        }
Exemple #37
0
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var label   = Label;
            var whenExp = WhenExpression;

            if (whenExp != null)
            {
                whenExp = whenExp.Prepare(preparer);
            }

            return(new LoopControlStatement(ControlType, label, whenExp));
        }
Exemple #38
0
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var column = new SqlTableColumn(ColumnName, ColumnType);

            if (DefaultExpression != null)
            {
                column.DefaultExpression = DefaultExpression.Prepare(preparer);
            }

            column.IsNotNull = IsNotNull;
            return(column);
        }
Exemple #39
0
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var statement = new DeclareVariableStatement(VariableName, VariableType);

            if (DefaultExpression != null)
            {
                statement.DefaultExpression = DefaultExpression.Prepare(preparer);
            }

            statement.IsConstant = IsConstant;
            return(statement);
        }
Exemple #40
0
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var newColumn = new SqlTableColumn(Column.ColumnName, Column.ColumnType) {
                IsNotNull = Column.IsNotNull
            };

            var defaultExp = Column.DefaultExpression;
            if (defaultExp != null)
                newColumn.DefaultExpression = defaultExp.Prepare(preparer);

            return new AddColumnAction(newColumn);
        }
        /// <summary>
        /// Prepares this statement and returns an object that can be executed
        /// within a given context.
        /// </summary>
        /// <param name="statement"></param>
        /// <param name="preparer">An object used to prepare the expressions contained in the statement.</param>
        /// <param name="context">The execution context used to prepare the statement properties.</param>
        /// <returns>
        /// Returns an instance of <see cref="SqlStatement"/> that represents the
        /// prepared version of this statement and that will be executed in a later moment.
        /// </returns>
        /// <exception cref="StatementPrepareException">
        /// Thrown if an error occurred while preparing the statement.
        /// </exception>
        public static IStatement Prepare(this IStatement statement, IExpressionPreparer preparer, IRequest context)
        {
            if (statement is IPreparable)
                statement = ((IPreparable) statement).Prepare(preparer) as IStatement;

            if (statement == null)
                return null;

            if (statement is IPreparableStatement)
                statement = ((IPreparableStatement) statement).Prepare(context);

            return statement;
        }
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            SqlExpression[] args = null;
            if (Arguments != null) {
                args = (SqlExpression[])Arguments.Clone();

                for (int i = 0; i < args.Length; i++) {
                    args[i] = args[i].Prepare(preparer);
                }
            }

            return new OpenStatement(CursorName, args);
        }
Exemple #43
0
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var offset = OffsetExpression;

            if (offset != null)
            {
                offset = offset.Prepare(preparer);
            }

            var reference = ReferenceExpression.Prepare(preparer);

            return(new FetchIntoStatement(CursorName, Direction, offset, reference));
        }
        protected override SqlPreparedStatement PrepareStatement(IExpressionPreparer preparer, IQueryContext context)
        {
            if (String.IsNullOrEmpty(TableName))
                throw new StatementPrepareException("The table name must be specified.");

            if (CreateStatement == null)
                throw new StatementPrepareException("The CREATE TABLE statement is required.");

            var tableName = context.ResolveTableName(TableName);
            var preparedCreate = (CreateTableStatement.Prepared) CreateStatement.Prepare(preparer, context);

            return new Prepared(tableName, preparedCreate);
        }
Exemple #45
0
        public FromClause Prepare(IExpressionPreparer preparer)
        {
            var clause = new FromClause();

            clause.JoinSet = JoinSet.Prepare(preparer);

            // Prepare the StatementTree sub-queries in the from tables
            foreach (FromTable table in fromTableList)
            {
                clause.fromTableList.Add(table.Prepare(preparer));
            }

            return(clause);
        }
        protected override SqlPreparedStatement PrepareStatement(IExpressionPreparer preparer, IQueryContext context)
        {
            var viewName = context.ResolveTableName(ViewName);

            var queryFrom = QueryExpressionFrom.Create(context, QueryExpression);
            var queryPlan = context.DatabaseContext().QueryPlanner().PlanQuery(context, QueryExpression, null);

            var colList = ColumnNames == null ? new string[0] : ColumnNames.ToArray();

            // Wrap the result around a SubsetNode to alias the columns in the
            // table correctly for this view.
            int sz = colList.Length;
            var originalNames = queryFrom.GetResolvedColumns();
            var newColumnNames = new ObjectName[originalNames.Length];

            if (sz > 0) {
                if (sz != originalNames.Length)
                    throw new InvalidOperationException("Column list is not the same size as the columns selected.");

                for (int i = 0; i < sz; ++i) {
                    var colName = colList[i];
                    newColumnNames[i] = new ObjectName(viewName, colName);
                }
            } else {
                sz = originalNames.Length;
                for (int i = 0; i < sz; ++i) {
                    newColumnNames[i] = new ObjectName(viewName, originalNames[i].Name);
                }
            }

            // Check there are no repeat column names in the table.
            for (int i = 0; i < sz; ++i) {
                var columnName = newColumnNames[i];
                for (int n = i + 1; n < sz; ++n) {
                    if (newColumnNames[n].Equals(columnName))
                        throw new InvalidOperationException(String.Format("Duplicate column name '{0}' in view. A view may not contain duplicate column names.", columnName));
                }
            }

            // Wrap the plan around a SubsetNode plan
            queryPlan = new SubsetNode(queryPlan, originalNames, newColumnNames);

            // We have to execute the plan to get the TableInfo that represents the
            // result of the view execution.
            var table = queryPlan.Evaluate(context);
            var tableInfo = table.TableInfo.Alias(viewName);

            return new Prepared(tableInfo, QueryExpression, queryPlan, ReplaceIfExists);
        }
Exemple #47
0
        public void SetUp()
        {
            _expressionPreparerMock = MockRepository.GenerateStrictMock <IExpressionPreparer>();
            _ilGeneratorFactoryStub = MockRepository.GenerateStub <IILGeneratorFactory>();

            _emitter = new MemberEmitter(_expressionPreparerMock, _ilGeneratorFactoryStub);

            _typeBuilderMock = MockRepository.GenerateStrictMock <ITypeBuilder>();
            _emittableOperandProviderMock = MockRepository.GenerateStrictMock <IEmittableOperandProvider>();

            _context = CodeGenerationContextObjectMother.GetSomeContext(
                typeBuilder: _typeBuilderMock, emittableOperandProvider: _emittableOperandProviderMock);

            _fakeBody = ExpressionTreeObjectMother.GetSomeExpression();
        }
Exemple #48
0
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            SqlExpression[] args = null;
            if (Arguments != null)
            {
                args = (SqlExpression[])Arguments.Clone();

                for (int i = 0; i < args.Length; i++)
                {
                    args[i] = args[i].Prepare(preparer);
                }
            }

            return(new OpenStatement(CursorName, args));
        }
        protected override SqlPreparedStatement PrepareStatement(IExpressionPreparer preparer, IQueryContext context)
        {
            var tableName = context.ResolveTableName(TableName);

            var table = context.GetTable(tableName);
            if (table == null)
                throw new InvalidOperationException();

            if (Values.Any(x => x.OfType<SqlQueryExpression>().Any()))
                throw new InvalidOperationException("Cannot set a value from a query.");

            var columnInfos = new List<ColumnInfo>();
            foreach (var name in ColumnNames) {
                var columnName = ObjectName.Parse(name);
                var colIndex = table.FindColumn(columnName);
                if (colIndex < 0)
                    throw new InvalidOperationException(String.Format("Cannot find column '{0}' in table '{1}'", columnName, table.FullName));

                columnInfos.Add(table.TableInfo[colIndex]);
            }

            var assignments = new List<SqlAssignExpression[]>();

            foreach (var valueSet in Values) {
                var valueAssign = new SqlAssignExpression[valueSet.Length];

                for (int i = 0; i < valueSet.Length; i++) {
                    var columnInfo = columnInfos[i];

                    var value = valueSet[i];
                    if (value != null) {
                        // TODO: Deference columns with a preparer
                    }

                    if (value != null) {
                        var expReturnType = value.ReturnType(context, null);
                        if (!columnInfo.ColumnType.IsComparable(expReturnType))
                            throw new InvalidOperationException();
                    }

                    valueAssign[i] = SqlExpression.Assign(SqlExpression.Reference(columnInfo.FullColumnName), value);
                }

                assignments.Add(valueAssign);
            }

            return new Prepared(tableName, assignments);
        }
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var checkExpression = CheckExpression;

            if (checkExpression != null)
            {
                checkExpression = checkExpression.Prepare(preparer);
            }

            return(new SqlTableConstraint(ConstraintName, ConstraintType, Columns)
            {
                CheckExpression = checkExpression,
                ReferenceTable = ReferenceTable,
                ReferenceColumns = ReferenceColumns
            });
        }
Exemple #51
0
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var lower = LowerBound.Prepare(preparer);
            var upper = UpperBound.Prepare(preparer);

            var loop = new ForLoopStatement(IndexName, lower, upper)
            {
                Reverse = Reverse
            };

            foreach (var statement in Statements)
            {
                loop.Statements.Add(statement);
            }
            return(loop);
        }
        protected override SqlPreparedStatement PrepareStatement(IExpressionPreparer preparer, IQueryContext context)
        {
            var queryPlan = context.DatabaseContext().QueryPlanner().PlanQuery(context, QueryExpression, null);

            if (IsObjectReference) {
                var tableRef = ((SqlReferenceExpression) Reference).ReferenceName;

                var table = context.GetMutableTable(tableRef);
                if (table == null)
                    throw new StatementPrepareException(String.Format("Referenced table of the INTO statement '{0}' was not found or is not mutable.", tableRef));

                return new Prepared(queryPlan, table);
            }
            if (IsVariableReference) {
                throw new NotImplementedException();
            }

            // Other (impossible) case...
            throw new NotSupportedException();
        }
Exemple #53
0
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var exp = Expression;
            if (exp != null) {
                exp = exp.Prepare(preparer);
            }

            return new SortColumn(exp, Ascending);
        }
Exemple #54
0
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var lower = LowerBound.Prepare(preparer);
            var upper = UpperBound.Prepare(preparer);

            var loop = new ForLoopStatement(IndexName, lower, upper) {Reverse = Reverse};
            foreach (var statement in Statements) {
                loop.Statements.Add(statement);
            }
            return loop;
        }
Exemple #55
0
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var clause = new FromClause();

            // Prepare expressions in the JoiningSet first
            int size = joinParts.Count;
            for (int i = 0; i < size; ++i) {
                var part = joinParts[i];
                var exp = part.OnExpression;
                if (exp != null) {
                    exp = exp.Prepare(preparer);
                    if (part.SubQuery != null) {
                        part = new JoinPart(part.JoinType, part.SubQuery,  exp);
                    } else {
                        part = new JoinPart(part.JoinType, part.TableName, exp);
                    }
                }

                clause.joinParts.Add(part);
            }

            // Prepare the StatementTree sub-queries in the from tables
            for (int i = 0; i < fromTables.Count; i++) {
                var table = fromTables[i];
                var preparedTable = (FromTable) ((IPreparable) table).Prepare(preparer);

                if (i < tableNames.Count) {
                    var tableAlias = tableNames[i];
                    clause.tableNames.Insert(i, tableAlias);
                }

                clause.fromTables.Insert(i, preparedTable);
            }

            return clause;
        }
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var label = Label;
            var whenExp = WhenExpression;
            if (whenExp != null)
                whenExp = whenExp.Prepare(preparer);

            return new LoopControlStatement(ControlType, label, whenExp);
        }
Exemple #57
0
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var offset = OffsetExpression;
            if (offset != null)
                offset = offset.Prepare(preparer);

            return new FetchStatement(CursorName, Direction, offset);
        }
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var args = new InvokeArgument[ProcedureArguments == null ? 0 : ProcedureArguments.Length];
            if (ProcedureArguments != null) {
                for (int i = 0; i < args.Length; i++) {
                    args[i] = (InvokeArgument) (ProcedureArguments[i] as IPreparable).Prepare(preparer);
                }
            }

            return new CreateProcedureTriggerStatement(TriggerName, TableName, ProcedureName, args, EventTime, EventType) {
                Status = Status,
                ReplaceIfExists = ReplaceIfExists
            };
        }
Exemple #59
0
 /// <summary>
 /// When overridden by an implementing class, this method generates a prepared
 /// version of this statement that can be executed.
 /// </summary>
 /// <param name="preparer">An object used to prepare the SQL expressions contained
 /// into the statement.</param>
 /// <param name="context">The executing context in used to prepare the statement
 /// properties.</param>
 /// <returns>
 /// Returns an instance of <see cref="SqlPreparedStatement"/> that represents the
 /// prepared version of this statement and that will be executed in a later moment.
 /// </returns>
 /// <seealso cref="SqlPreparedStatement"/>
 /// <seealso cref="Prepare(IExpressionPreparer, IQueryContext)"/>
 protected abstract SqlPreparedStatement PrepareStatement(IExpressionPreparer preparer, IQueryContext context);
Exemple #60
0
        /// <summary>
        /// Prepares this statement and returns an object that can be executed
        /// within a given context.
        /// </summary>
        /// <param name="preparer">An object used to prepare the expressions contained in the statement.</param>
        /// <param name="context">The execution context used to prepare the statement properties.</param>
        /// <returns>
        /// Returns an instance of <see cref="SqlPreparedStatement"/> that represents the
        /// prepared version of this statement and that will be executed in a later moment.
        /// </returns>
        /// <exception cref="StatementPrepareException">
        /// Thrown if an error occurred while preparing the statement.
        /// </exception>
        public SqlPreparedStatement Prepare(IExpressionPreparer preparer, IQueryContext context)
        {
            SqlPreparedStatement prepared;

            try {
                prepared = PrepareStatement(preparer, context);

                if (prepared == null)
                    throw new InvalidOperationException("Preparation was invalid.");

                prepared.Source = this;
            } catch(StatementPrepareException) {
                throw;
            } catch (Exception ex) {
                throw new StatementPrepareException(String.Format("An error occurred while preparing a statement of type '{0}'.", GetType()), ex);
            }

            return prepared;
        }