internal override SqlExpression VisitMultiset(SqlSubSelect sms)
        {
            // allow one big-join per query?
            if ((this.options & SqlMultiplexerOptionType.EnableBigJoin) != 0 &&
                !this.hasBigJoin && this.canJoin && this.isTopLevel && this.outerSelect != null &&
                !MultisetChecker.HasMultiset(sms.Select.Selection) &&
                BigJoinChecker.CanBigJoin(sms.Select))
            {
                sms.Select = this.VisitSelect(sms.Select);

                SqlAlias alias = new SqlAlias(sms.Select);
                SqlJoin  join  = new SqlJoin(SqlJoinType.OuterApply, this.outerSelect.From, alias, null, sms.SourceExpression);
                this.outerSelect.From         = @join;
                this.outerSelect.OrderingType = SqlOrderingType.Always;

                // make joined expression
                SqlExpression expr = (SqlExpression)SqlDuplicator.Copy(sms.Select.Selection);

                // make count expression
                SqlSelect copySelect  = (SqlSelect)SqlDuplicator.Copy(sms.Select);
                SqlAlias  copyAlias   = new SqlAlias(copySelect);
                SqlSelect countSelect = new SqlSelect(sql.Unary(SqlNodeType.Count, null, sms.SourceExpression), copyAlias, sms.SourceExpression);
                countSelect.OrderingType = SqlOrderingType.Never;
                SqlExpression count = sql.SubSelect(SqlNodeType.ScalarSubSelect, countSelect);

                // make joined collection
                SqlJoinedCollection jc = new SqlJoinedCollection(sms.ClrType, sms.SqlType, expr, count, sms.SourceExpression);
                this.hasBigJoin = true;
                return(jc);
            }
            return(QueryExtractor.Extract(sms, this.parentParameters));
        }
Пример #2
0
        protected override SqlSelect GenerateSkipTake(SqlSelect sequence, SqlExpression skipExp, SqlExpression takeExp)
        {
            //return base.GenerateSkipTake(sequence, skipExp, takeExp);
            SqlSelect node   = LockSelect(sequence);
            var       value2 = skipExp as SqlValue;

            if ((skipExp == null) || ((value2 != null) && (((int)value2.Value) <= 0)))
            {
                skipExp = sql.ValueFromObject(0, dominatingExpression);
            }
            var alias     = new SqlAlias(node);
            var selection = new SqlAliasRef(alias);

            if (UseConverterStrategy(ConverterStrategy.SkipWithRowNumber))
            {
                var col = new SqlColumn("ROW_NUMBER",
                                        this.sql.RowNumber(new List <SqlOrderExpression>(),
                                                           this.dominatingExpression));
                var expr = new SqlColumnRef(col);
                node.Row.Columns.Add(col);
                var select2 = new SqlSelect(selection, alias, this.dominatingExpression);
                if (takeExp != null)
                {
                    select2.Where = this.sql.Between(expr, this.sql.Add(skipExp, 1),
                                                     this.sql.Binary(SqlNodeType.Add,
                                                                     (SqlExpression)SqlDuplicator.Copy(skipExp),
                                                                     takeExp), this.dominatingExpression);
                    return(select2);
                }
                select2.Where = this.sql.Binary(SqlNodeType.GT, expr, skipExp);
                return(select2);
            }
            if (!this.CanSkipOnSelection(node.Selection))
            {
                throw SqlClient.Error.SkipNotSupportedForSequenceTypes();
            }
            var visitor = new SingleTableQueryVisitor();

            visitor.Visit(node);
            if (!visitor.IsValid)
            {
                throw ALinq.SqlClient.Error.SkipRequiresSingleTableQueryWithPKs();
            }
            var select3 = (SqlSelect)SqlDuplicator.Copy(node);

            select3.Top = skipExp;
            var alias2 = new SqlAlias(select3);
            var ref4   = new SqlAliasRef(alias2);
            var select = new SqlSelect(ref4, alias2, this.dominatingExpression);

            select.Where = this.sql.Binary(SqlNodeType.EQ2V, selection, ref4);
            SqlSubSelect expression = this.sql.SubSelect(SqlNodeType.Exists, select);
            var          select6    = new SqlSelect(selection, alias, this.dominatingExpression);

            select6.Where = this.sql.Unary(SqlNodeType.Not, expression, this.dominatingExpression);
            select6.Top   = takeExp;
            return(select6);
        }
Пример #3
0
        //private new void Initialize(IDataServices dataServices, IDbConnection connection)
        //{
        //    services = dataServices;
        //    conManager = new SqlConnectionManager(this, (DbConnection)connection, 100);
        //    var type = typeof(ALinq.Oracle.DataReader);
        //    readerCompiler = new ObjectReaderCompiler(type, services);
        //    InitializeProviderMode();
        //}

        internal override ICompiledSubQuery CompileSubQuery(SqlNode query, Type elementType, ReadOnlyCollection <SqlParameter> parameters)
        {
            query = SqlDuplicator.Copy(query);
            var annotations = new SqlNodeAnnotations();
            var queries     = BuildQuery(ResultShape.Sequence, TypeSystem.GetSequenceType(elementType), query, parameters, annotations);
            var queryInfo   = queries[0];

            //Set CommandText
            queryInfo.CommandText = new OracleFormatter(this).Format(queryInfo.Query);
            ICompiledSubQuery[]  subQueries    = CompileSubQueries(queryInfo.Query);
            IObjectReaderFactory readerFactory = GetReaderFactory(queryInfo.Query, elementType);

            CheckSqlCompatibility(queries, annotations);

            return(new CompiledSubQuery(queryInfo, readerFactory, parameters, subQueries));
        }
Пример #4
0
        internal override ICompiledSubQuery CompileSubQuery(SqlNode query, Type elementType, ReadOnlyCollection <SqlParameter> parameters)
        {
            query = SqlDuplicator.Copy(query);
            var annotations = new SqlNodeAnnotations();

            QueryInfo[] queries   = BuildQuery(ResultShape.Sequence, TypeSystem.GetSequenceType(elementType), query, parameters, annotations);
            QueryInfo   queryInfo = queries[0];

            ICompiledSubQuery[] subQueries = this.CompileSubQueries(queryInfo.Query);
            var formatter = new MySqlFormatter(this);

            for (int i = 0; i < subQueries.Length; i++)
            {
                var subQuery = (CompiledSubQuery)subQueries[i];
                subQuery.QueryInfo.CommandText = formatter.Format(subQuery.QueryInfo.Query);
            }
            IObjectReaderFactory readerFactory = this.GetReaderFactory(queryInfo.Query, elementType);

            CheckSqlCompatibility(queries, annotations);
            return(new CompiledSubQuery(queryInfo, readerFactory, parameters, subQueries, connectionString, this));
        }