Example #1
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);
                }
            }
        }
Example #2
0
        public override IEnumerable <IDictionary <string, object> > RunQuery(SimpleQuery query,
                                                                             out IEnumerable <SimpleQueryClauseBase>
                                                                             unhandledClauses)
        {
            if (query.Clauses.OfType <WithCountClause>().Any())
            {
                return(RunQueryWithCount(query, out unhandledClauses));
            }

            ICommandBuilder[] commandBuilders = GetQueryCommandBuilders(query, out unhandledClauses);
            IDbConnection     connection      = CreateConnection();

            if (ProviderSupportsCompoundStatements || commandBuilders.Length == 1)
            {
                return
                    (CommandBuilder.CreateCommand(
                         _providerHelper.GetCustomProvider <IDbParameterFactory>(_schema.SchemaProvider), commandBuilders,
                         connection).ToEnumerable(this.CreateConnection));
            }
            else
            {
                return(commandBuilders.SelectMany(cb => cb.GetCommand(connection).ToEnumerable(this.CreateConnection)));
            }
        }