Пример #1
0
 public void SetResult(Field value)
 {
     if (IsInSession)
     {
         SetResult(FunctionTable.ResultTable(Request, value));
     }
 }
Пример #2
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);
        }
Пример #3
0
        internal void Return(SqlExpression value)
        {
            AssertNotFinished();

            if (value != null)
            {
                SetResult(FunctionTable.ResultTable(Request, value));
            }

            Terminate();
        }
Пример #4
0
        public static ITable[] ExecuteStatements(this IRequest request, params IStatement[] statements)
        {
            if (statements == null)
            {
                throw new ArgumentNullException("statements");
            }
            if (statements.Length == 0)
            {
                throw new ArgumentException();
            }

            var results = new ITable[statements.Length];

            for (int i = 0; i < statements.Length; i++)
            {
                var statement = statements[i];

                var context = new ExecutionContext(request);

                if (statement is IPreparableStatement)
                {
                    statement = ((IPreparableStatement)statement).Prepare(request);
                }

                statement.Execute(context);

                ITable result;
                if (context.HasResult)
                {
                    result = context.Result;
                }
                else
                {
                    result = FunctionTable.ResultTable(request, 0);
                }

                results[i] = result;
            }

            return(results);
        }
Пример #5
0
        public static ITable[] Execute(this IRequest request, SqlQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            var sqlSouce = query.Text;

            // TODO: find it from the cache...

            var statements = SqlStatement.Parse(sqlSouce);

            // TODO: set it in cache ...

            var preparer = new QueryPreparer(query);

            bool statementSeen = false;

            var results = new List <ITable>();

            foreach (var statement in statements)
            {
                // TODO: query.RegisterQuery(statement);

                // TODO: Invoke diagnostics for the preparation...

                var prepared = statement.Prepare(preparer, request);

                ITable result;

                try {
                    var exeContext = new ExecutionContext(request);
                    prepared.Execute(exeContext);
                    if (exeContext.HasResult)
                    {
                        result = exeContext.Result;
                    }
                    else
                    {
                        result = FunctionTable.ResultTable(request, 0);
                    }
                } catch (StatementException ex) {
                    request.OnError(ex);
                    throw;
                } catch (Exception ex) {
                    var sex = new StatementException("An unhanded error occurred while executing the statement.", ex);
                    request.OnError(sex);
                    throw sex;
                } finally {
                    statementSeen = true;
                }

                results.Add(result);
            }

            if (!statementSeen)
            {
                throw new SqlParseException("The input query was not parsed in any statements that could be executed.");
            }

            return(results.ToArray());
        }
Пример #6
0
 public void SetResult(int value)
 {
     SetResult(FunctionTable.ResultTable(Request, value));
 }
        public static StatementResult[] ExecuteStatements(this IRequest request, IExpressionPreparer preparer,
                                                          params SqlStatement[] statements)
        {
            if (statements == null)
            {
                throw new ArgumentNullException("statements");
            }
            if (statements.Length == 0)
            {
                throw new ArgumentException("No statements provided for execution", "statements");
            }

            var results = new StatementResult[statements.Length];

            for (int i = 0; i < statements.Length; i++)
            {
                var statement = statements[i];

                var             context = new ExecutionContext(request, statement);
                StatementResult result;

                try {
                    var prepared = statement.Prepare(request, preparer);

                    if (prepared == null)
                    {
                        throw new InvalidOperationException(String.Format(
                                                                "The preparation of the statement '{0}' returned a null instance", statement.GetType()));
                    }

                    prepared.Execute(context);


                    if (context.HasResult)
                    {
                        var constraints = FindConstraintsFor(request, context.Result);

                        result = new StatementResult(context.Result, constraints);
                    }
                    else if (context.HasCursor)
                    {
                        // TODO: we should find a way to project the source info of the cursor without executing it
                        var constraints = FindConstraintsFor(request, context.Cursor.Source);
                        context.Cursor.Reset();
                        result = new StatementResult(context.Cursor, constraints);
                    }
                    else if (context.IsInSession)
                    {
                        result = new StatementResult(FunctionTable.ResultTable(request, 0));
                    }
                    else
                    {
                        result = new StatementResult();
                    }
                } catch (Exception ex) {
                    result = new StatementResult(ex);
                }

                results[i] = result;
            }

            return(results);
        }