Inheritance: SqlErrorException
        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();
        }
示例#2
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());
        }