public override int Visit(SqlTopSpec sqlTopSpec) { int hashCode = SqlTopSpecHashCode; hashCode = CombineHashes(hashCode, sqlTopSpec.TopExpresion.Accept(this)); return(hashCode); }
private static long GetTopCount(SqlTopSpec sqlTopSpec) { if (sqlTopSpec == null) { throw new ArgumentNullException(nameof(sqlTopSpec)); } SqlScalarExpression topExpression = sqlTopSpec.TopExpresion; if (!(topExpression is SqlLiteralScalarExpression topLiteralExpression)) { throw new ArgumentException($"Expected number literal scalar expression."); } SqlLiteral sqlLiteral = topLiteralExpression.Literal; if (!(sqlLiteral is SqlNumberLiteral sqlNumberLiteral)) { throw new ArgumentException($"Expected number literal."); } if (!sqlNumberLiteral.Value.IsInteger) { throw new ArgumentException($"Expected integer literal."); } long value = Number64.ToLong(sqlNumberLiteral.Value); return(value); }
public override SqlObject VisitTop_spec([NotNull] sqlParser.Top_specContext context) { Contract.Requires(context != null); Number64 topCount = CstToAstVisitor.GetNumber64ValueFromNode(context.NUMERIC_LITERAL()); return(SqlTopSpec.Create(SqlNumberLiteral.Create(topCount))); }
public QueryUnderConstruction AddTopSpec(SqlTopSpec topSpec) { if (this.topSpec != null) { // Set the topSpec to the one with minimum Count value this.topSpec = (this.topSpec.Count < topSpec.Count) ? this.topSpec : topSpec; } else { this.topSpec = topSpec; } return(this); }
public override bool Visit(SqlTopSpec first, SqlObject secondAsObject) { if (!(secondAsObject is SqlTopSpec second)) { return(false); } if (!Equals(first.TopExpresion, second.TopExpresion)) { return(false); } return(true); }
public QueryUnderConstruction AddTopSpec(SqlTopSpec topSpec) { QueryUnderConstruction result = this; if (result.topSpec != null) { // Set the topSpec to the one with minimum Count value result.topSpec = (result.topSpec.Count < topSpec.Count) ? result.topSpec : topSpec; } else { result.topSpec = topSpec; } return(result); }
public QueryUnderConstruction AddTopSpec(SqlTopSpec topSpec, HashSet <ParameterExpression> inScope, Collection currentCollection) { QueryUnderConstruction result = this; if (result.topSpec != null) { // Set the topSpec to the one with minimum Count value result.topSpec = (this.topSpec.Count < topSpec.Count) ? this.topSpec : topSpec; } else { result.topSpec = topSpec; } if (result.topSpec.Count < 0) { result.topSpec = SqlTopSpec.Create(0); } return(result); }
public QueryUnderConstruction AddTopSpec(SqlTopSpec topSpec) { QueryUnderConstruction result = this; if (result.topSpec != null) { long accumulatedTopCount = QueryUnderConstruction.GetTopCount(result.topSpec); long currentTopCount = QueryUnderConstruction.GetTopCount(topSpec); if (currentTopCount < accumulatedTopCount) { result.topSpec = topSpec; } } else { result.topSpec = topSpec; } return(result); }
public override SqlObject VisitTop_spec([NotNull] sqlParser.Top_specContext context) { Contract.Requires(context != null); SqlTopSpec sqlTopSpec; if (context.NUMERIC_LITERAL() != null) { Number64 topCount = CstToAstVisitor.GetNumber64ValueFromNode(context.NUMERIC_LITERAL()); sqlTopSpec = SqlTopSpec.Create(SqlNumberLiteral.Create(topCount)); } else if (context.PARAMETER() != null) { sqlTopSpec = SqlTopSpec.Create(SqlParameter.Create(context.PARAMETER().GetText())); } else { throw new InvalidOperationException(); } return(sqlTopSpec); }
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); }
public abstract void Visit(SqlTopSpec sqlObject);
public override void Visit(SqlTopSpec sqlTopSpec) { this.writer.Write("TOP "); sqlTopSpec.TopExpresion.Accept(this); }
public override SqlObject Visit(SqlTopSpec sqlTopSpec) { return(SqlTopSpec.Create(SqlNumberLiteral.Create(0))); }
public abstract TResult Visit(SqlTopSpec sqlObject);
public abstract TOutput Visit(SqlTopSpec sqlObject, TArg input);