Ejemplo n.º 1
0
        private SqlWhereClause Substitute(SqlSelectSpec spec, SqlIdentifier inputParam, SqlWhereClause whereClause)
        {
            if (whereClause == null)
            {
                return(null);
            }

            if (spec is SqlSelectStarSpec)
            {
                return(whereClause);
            }
            else
            {
                SqlSelectValueSpec selValue = spec as SqlSelectValueSpec;
                if (selValue != null)
                {
                    SqlScalarExpression replaced    = selValue.Expression;
                    SqlScalarExpression original    = whereClause.FilterExpression;
                    SqlScalarExpression substituted = SqlExpressionManipulation.Substitute(replaced, inputParam, original);
                    SqlWhereClause      result      = SqlWhereClause.Create(substituted);
                    return(result);
                }
            }

            throw new DocumentQueryException("Unexpected SQL select clause type: " + spec.Kind);
        }
Ejemplo n.º 2
0
        private SqlOrderbyClause Substitute(SqlSelectSpec spec, SqlIdentifier inputParam, SqlOrderbyClause orderByClause)
        {
            if (orderByClause == null)
            {
                return(null);
            }

            if (spec is SqlSelectStarSpec)
            {
                return(orderByClause);
            }

            SqlSelectValueSpec selValue = spec as SqlSelectValueSpec;

            if (selValue != null)
            {
                SqlScalarExpression replaced         = selValue.Expression;
                SqlOrderByItem[]    substitutedItems = new SqlOrderByItem[orderByClause.OrderbyItems.Count];
                for (int i = 0; i < substitutedItems.Length; ++i)
                {
                    SqlScalarExpression substituted = SqlExpressionManipulation.Substitute(replaced, inputParam, orderByClause.OrderbyItems[i].Expression);
                    substitutedItems[i] = SqlOrderByItem.Create(substituted, orderByClause.OrderbyItems[i].IsDescending);
                }
                SqlOrderbyClause result = SqlOrderbyClause.Create(substitutedItems);
                return(result);
            }

            throw new DocumentQueryException("Unexpected SQL select clause type: " + spec.Kind);
        }
Ejemplo n.º 3
0
        private SqlSelectClause Substitute(SqlSelectClause inputSelectClause, SqlTopSpec topSpec, SqlIdentifier inputParam, SqlSelectClause selectClause)
        {
            SqlSelectSpec selectSpec = inputSelectClause.SelectSpec;

            if (selectClause == null)
            {
                return(selectSpec != null?SqlSelectClause.Create(selectSpec, topSpec, inputSelectClause.HasDistinct) : null);
            }

            if (selectSpec is SqlSelectStarSpec)
            {
                return(SqlSelectClause.Create(selectSpec, topSpec, inputSelectClause.HasDistinct));
            }

            SqlSelectValueSpec selValue = selectSpec as SqlSelectValueSpec;

            if (selValue != null)
            {
                SqlSelectSpec intoSpec = selectClause.SelectSpec;
                if (intoSpec is SqlSelectStarSpec)
                {
                    return(SqlSelectClause.Create(selectSpec, topSpec, selectClause.HasDistinct || inputSelectClause.HasDistinct));
                }

                SqlSelectValueSpec intoSelValue = intoSpec as SqlSelectValueSpec;
                if (intoSelValue != null)
                {
                    SqlScalarExpression replacement         = SqlExpressionManipulation.Substitute(selValue.Expression, inputParam, intoSelValue.Expression);
                    SqlSelectValueSpec  selValueReplacement = SqlSelectValueSpec.Create(replacement);
                    return(SqlSelectClause.Create(selValueReplacement, topSpec, selectClause.HasDistinct || inputSelectClause.HasDistinct));
                }

                throw new DocumentQueryException("Unexpected SQL select clause type: " + intoSpec.Kind);
            }

            throw new DocumentQueryException("Unexpected SQL select clause type: " + selectSpec.Kind);
        }