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.GetType()); }
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.Length]; 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.GetType()); }
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.GetType()); } throw new DocumentQueryException("Unexpected SQL select clause type: " + selectSpec.GetType()); }