Пример #1
0
        private ICommandBuilder[] GetPagedQueryCommandBuilders(SimpleQuery query, Int32 bulkIndex, out IEnumerable<SimpleQueryClauseBase> unhandledClauses)
        {
            var commandBuilders = new List<ICommandBuilder>();
            var unhandledClausesList = new List<SimpleQueryClauseBase>();
            unhandledClauses = unhandledClausesList;

            IEnumerable<SimpleQueryClauseBase> unhandledClausesForPagedQuery;
            var mainCommandBuilder = new QueryBuilder(this, bulkIndex).Build(query, out unhandledClausesForPagedQuery);
            unhandledClausesList.AddRange(unhandledClausesForPagedQuery);

            const int maxInt = 2147483646;

            var skipClause = query.Clauses.OfType<SkipClause>().FirstOrDefault() ?? new SkipClause(0);
            var takeClause = query.Clauses.OfType<TakeClause>().FirstOrDefault() ?? new TakeClause(maxInt);

            if (skipClause.Count != 0 || takeClause.Count != maxInt)
            {
                var queryPager = this.ProviderHelper.GetCustomProvider<IQueryPager>(this.ConnectionProvider);
                if (queryPager == null)
                {
                    unhandledClausesList.AddRange(query.OfType<SkipClause>());
                    unhandledClausesList.AddRange(query.OfType<TakeClause>());
                }

                var commandTexts = queryPager.ApplyPaging(mainCommandBuilder.Text, skipClause.Count, takeClause.Count);

                foreach (var commandText in commandTexts)
                {
                    var commandBuilder = new CommandBuilder(commandText, this._schema, mainCommandBuilder.Parameters);
                    commandBuilders.Add(commandBuilder);
                }
            }
            return commandBuilders.ToArray();
        }
Пример #2
0
 public override IEnumerable<IEnumerable<IDictionary<string,object>>> RunQueries(SimpleQuery[] queries, List<IEnumerable<SimpleQueryClauseBase>> unhandledClauses)
 {
     if (ProviderSupportsCompoundStatements && queries.Length > 1)
     {
         var commandBuilders = new ICommandBuilder[queries.Length];
         for (int i = 0; i < queries.Length; i++)
         {
             IEnumerable<SimpleQueryClauseBase> unhandledClausesForThisQuery;
             commandBuilders[i] = new QueryBuilder(this, i).Build(queries[i], out unhandledClausesForThisQuery);
             unhandledClauses.Add(unhandledClausesForThisQuery);
         }
         var connection = _connectionProvider.CreateConnection();
         var command = CommandBuilder.CreateCommand(_providerHelper.GetCustomProvider<IDbParameterFactory>(_schema.SchemaProvider), commandBuilders, connection);
         foreach (var item in command.ToEnumerables(connection))
         {
             yield return item.ToList();
         }
     }
     else
     {
         foreach (SimpleQuery t in queries)
         {
             IEnumerable<SimpleQueryClauseBase> unhandledClausesForThisQuery;
             yield return RunQuery(t, out unhandledClausesForThisQuery);
             unhandledClauses.Add(unhandledClausesForThisQuery);
         }
     }
 }
        private ICommandBuilder[] GetPagedQueryCommandBuilders(ref SimpleQuery query, Int32 bulkIndex,
                                                               out IEnumerable<SimpleQueryClauseBase> unhandledClauses)
        {
            var commandBuilders = new List<ICommandBuilder>();
            var unhandledClausesList = new List<SimpleQueryClauseBase>();
            unhandledClauses = unhandledClausesList;

            IEnumerable<SimpleQueryClauseBase> unhandledClausesForPagedQuery;
            ICommandBuilder mainCommandBuilder = new QueryBuilder(_adapter, bulkIndex).Build(query,
                                                                                             out
                                                                                                 unhandledClausesForPagedQuery);
            unhandledClausesList.AddRange(unhandledClausesForPagedQuery);

            SkipClause skipClause = query.Clauses.OfType<SkipClause>().FirstOrDefault();
            TakeClause takeClause = query.Clauses.OfType<TakeClause>().FirstOrDefault();

            if (skipClause != null || takeClause != null)
            {
                var queryPager = _adapter.ProviderHelper.GetCustomProvider<IQueryPager>(_adapter.ConnectionProvider);
                if (queryPager == null)
                {
                    Trace.TraceWarning("There is no database-specific query paging in your current Simple.Data Provider. Paging will be done in memory.");
                    DeferPaging(ref query, mainCommandBuilder, commandBuilders, unhandledClausesList);
                }
                else
                {
                    ApplyPaging(query, commandBuilders, mainCommandBuilder, skipClause, takeClause, query.Clauses.OfType<WithClause>().Any(), queryPager);
                }
            }
            return commandBuilders.ToArray();
        }
        private ICommandBuilder[] GetPagedQueryCommandBuilders(SimpleQuery query, Int32 bulkIndex,
                                                               out IEnumerable<SimpleQueryClauseBase> unhandledClauses)
        {
            var commandBuilders = new List<ICommandBuilder>();
            var unhandledClausesList = new List<SimpleQueryClauseBase>();
            unhandledClauses = unhandledClausesList;

            IEnumerable<SimpleQueryClauseBase> unhandledClausesForPagedQuery;
            ICommandBuilder mainCommandBuilder = new QueryBuilder(_adapter, bulkIndex).Build(query,
                                                                                             out
                                                                                                 unhandledClausesForPagedQuery);
            unhandledClausesList.AddRange(unhandledClausesForPagedQuery);


            SkipClause skipClause = query.Clauses.OfType<SkipClause>().FirstOrDefault();
            TakeClause takeClause = query.Clauses.OfType<TakeClause>().FirstOrDefault();

            if (skipClause != null || takeClause != null)
            {
                var queryPager = _adapter.ProviderHelper.GetCustomProvider<IQueryPager>(_adapter.ConnectionProvider);
                if (queryPager == null)
                {
                    DeferPaging(query, mainCommandBuilder, commandBuilders, unhandledClausesList);
                }
                else
                {
                    ApplyPaging(commandBuilders, mainCommandBuilder, skipClause, takeClause, queryPager);
                }
            }
            return commandBuilders.ToArray();
        }