public void RangeIntersectsRange(NpgsqlRange <int> range)
        {
            using (RangeContext context = Fixture.CreateContext())
            {
                NpgsqlRange <int>[] _ =
                    context.RangeTestEntities
                    .Select(x => x.Range.Intersect(range))
                    .ToArray();

                AssertContainsSql("SELECT (x.\"Range\" * @__range_0)");
            }
        }
        public void RangeDoesNotContainValue(int value)
        {
            using (RangeContext context = Fixture.CreateContext())
            {
                RangeTestEntity[] _ =
                    context.RangeTestEntities
                    .Where(x => !x.Range.Contains(value))
                    .ToArray();

                AssertContainsSql("WHERE NOT ((x.\"Range\" @> @__value_0) = TRUE)");
            }
        }
        public void RangeContainsRange(NpgsqlRange <int> range)
        {
            using (RangeContext context = Fixture.CreateContext())
            {
                RangeTestEntity[] _ =
                    context.RangeTestEntities
                    .Where(x => x.Range.Contains(range))
                    .ToArray();

                AssertContainsSql("WHERE (x.\"Range\" @> @__range_0) = TRUE");
            }
        }
        public void RangeIsNotAdjacentToRange(NpgsqlRange <int> range)
        {
            using (RangeContext context = Fixture.CreateContext())
            {
                RangeTestEntity[] _ =
                    context.RangeTestEntities
                    .Where(x => !x.Range.IsAdjacentTo(range))
                    .ToArray();

                AssertContainsSql("WHERE NOT ((x.\"Range\" -|- @__range_0) = TRUE)");
            }
        }
        public void RangeDoesExtendRightOfRange(NpgsqlRange <int> range)
        {
            using (RangeContext context = Fixture.CreateContext())
            {
                RangeTestEntity[] _ =
                    context.RangeTestEntities
                    .Where(x => !x.Range.DoesNotExtendRightOf(range))
                    .ToArray();

                AssertContainsSql("WHERE NOT ((x.\"Range\" &< @__range_0) = TRUE)");
            }
        }
        public void RangeIsStrictlyRightOfRange(NpgsqlRange <int> range)
        {
            using (RangeContext context = Fixture.CreateContext())
            {
                RangeTestEntity[] _ =
                    context.RangeTestEntities
                    .Where(x => x.Range.IsStrictlyRightOf(range))
                    .ToArray();

                AssertContainsSql("WHERE (x.\"Range\" >> @__range_0)");
            }
        }
        public void RangeDoesNotEqualsRange_Method(NpgsqlRange <int> range)
        {
            using (RangeContext context = Fixture.CreateContext())
            {
                RangeTestEntity[] _ =
                    context.RangeTestEntities
                    .Where(x => !x.Range.Equals(range))
                    .ToArray();

                AssertContainsSql("WHERE x.\"Range\" <> @__range_0");
            }
        }
        public void RangeEqualsRange_Operator(NpgsqlRange <int> range)
        {
            using (RangeContext context = Fixture.CreateContext())
            {
                RangeTestEntity[] _ =
                    context.RangeTestEntities
                    .Where(x => x.Range == range)
                    .ToArray();

                AssertContainsSql("WHERE x.\"Range\" = @__range_0");
            }
        }
        public void RangeNotContainedByRange(NpgsqlRange <int> range)
        {
            using (RangeContext context = Fixture.CreateContext())
            {
                RangeTestEntity[] _ =
                    context.RangeTestEntities
                    .Where(x => !range.ContainedBy(x.Range))
                    .ToArray();

                AssertContainsSql("WHERE NOT ((@__range_0 <@ x.\"Range\") = TRUE)");
            }
        }
Beispiel #10
0
            public static void Seed(RangeContext context)
            {
                context.RangeTestEntities.AddRange(
                    new RangeTestEntity
                {
                    Id = 1,
                    // (0, 10)
                    Range       = new NpgsqlRange <int>(0, false, false, 10, false, false),
                    FloatRange  = new NpgsqlRange <float>(0, false, false, 10, false, false),
                    SchemaRange = new NpgsqlRange <double>(0, false, false, 10, false, false)
                },
                    new RangeTestEntity
                {
                    Id = 2,
                    // [0, 10)
                    Range = new NpgsqlRange <int>(0, true, false, 10, false, false)
                },
                    new RangeTestEntity
                {
                    Id = 3,
                    // [0, 10]
                    Range = new NpgsqlRange <int>(0, true, false, 10, true, false)
                },
                    new RangeTestEntity
                {
                    Id = 4,
                    // [0, ∞)
                    Range = new NpgsqlRange <int>(0, true, false, 0, false, true)
                },
                    new RangeTestEntity
                {
                    Id = 5,
                    // (-∞, 10]
                    Range = new NpgsqlRange <int>(0, false, true, 10, true, false)
                },
                    new RangeTestEntity
                {
                    Id = 6,
                    // (-∞, ∞)
                    Range = new NpgsqlRange <int>(0, false, true, 0, false, true)
                },
                    new RangeTestEntity
                {
                    Id = 7,
                    // (-∞, ∞)
                    Range = new NpgsqlRange <int>(0, false, true, 0, false, true)
                });

                context.SaveChanges();
            }
Beispiel #11
0
 public static void Seed(RangeContext context)
 {
     context.RangeTestEntities.AddRange(
         new RangeTestEntity
     {
         Id                         = 1,
         IntRange                   = new NpgsqlRange <int>(1, 10),
         LongRange                  = new NpgsqlRange <long>(1, 10),
         DecimalRange               = new NpgsqlRange <decimal>(1, 10),
         DateOnlyDateRange          = new NpgsqlRange <DateOnly>(new(2020, 1, 1), new(2020, 1, 10)),
         DateTimeDateRange          = new NpgsqlRange <DateTime>(new(2020, 1, 1), new(2020, 1, 10)),
         UserDefinedRange           = new NpgsqlRange <double>(1, 10),
         UserDefinedRangeWithSchema = new NpgsqlRange <float>(1, 10)
     },
        public void RangeExceptRange(NpgsqlRange <int> range)
        {
            using (RangeContext context = Fixture.CreateContext())
            {
                try
                {
                    NpgsqlRange <int>[] _ =
                        context.RangeTestEntities
                        .Select(x => x.Range.Except(range))
                        .ToArray();
                }
                catch (PostgresException)
                {
                    // ignore: Npgsql.PostgresException : 22000: result of range difference would not be contiguous.
                }

                AssertContainsSql("SELECT (x.\"Range\" - @__range_0)");
            }
        }
        public RangeContext range()
        {
            RangeContext _localctx = new RangeContext(_ctx, State);

            EnterRule(_localctx, 4, RULE_range);
            try {
                EnterOuterAlt(_localctx, 1);
                {
                    State = 19; _localctx.start = Match(NUMBER);
                    State = 20; Match(MINUS);
                    State = 21; _localctx.stop = Match(NUMBER);
                }
            }
            catch (RecognitionException re) {
                _localctx.exception = re;
                _errHandler.ReportError(this, re);
                _errHandler.Recover(this, re);
            }
            finally {
                ExitRule();
            }
            return(_localctx);
        }
Beispiel #14
0
        private ExprContext expr(int _p)
        {
            ParserRuleContext _parentctx = Context;
            int         _parentState     = State;
            ExprContext _localctx        = new ExprContext(Context, _parentState);
            ExprContext _prevctx         = _localctx;
            int         _startState      = 2;

            EnterRecursionRule(_localctx, 2, RULE_expr, _p);
            int _la;

            try {
                int _alt;
                EnterOuterAlt(_localctx, 1);
                {
                    State = 34;
                    ErrorHandler.Sync(this);
                    switch (Interpreter.AdaptivePredict(TokenStream, 2, Context))
                    {
                    case 1:
                    {
                        _localctx = new UnaryContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;

                        State = 9;
                        ((UnaryContext)_localctx).sign = TokenStream.LT(1);
                        _la = TokenStream.LA(1);
                        if (!(_la == T__2 || _la == T__3))
                        {
                            ((UnaryContext)_localctx).sign = ErrorHandler.RecoverInline(this);
                        }
                        else
                        {
                            ErrorHandler.ReportMatch(this);
                            Consume();
                        }
                        State = 10; expr(16);
                    }
                    break;

                    case 2:
                    {
                        _localctx = new ParenthesisContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 11; Match(T__14);
                        State     = 12; expr(0);
                        State     = 13; Match(T__15);
                    }
                    break;

                    case 3:
                    {
                        _localctx = new FunctionContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 15; ((FunctionContext)_localctx).name = Match(NAME);
                        State     = 16; Match(T__14);
                        State     = 25;
                        ErrorHandler.Sync(this);
                        _la = TokenStream.LA(1);
                        if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__2) | (1L << T__3) | (1L << T__14) | (1L << STRING) | (1L << CELLREF) | (1L << BOOLEAN) | (1L << NUMBER) | (1L << NAME) | (1L << ERROR))) != 0))
                        {
                            {
                                State = 17; expr(0);
                                State = 22;
                                ErrorHandler.Sync(this);
                                _la = TokenStream.LA(1);
                                while (_la == T__16)
                                {
                                    {
                                        {
                                            State = 18; Match(T__16);
                                            State = 19; expr(0);
                                        }
                                    }
                                    State = 24;
                                    ErrorHandler.Sync(this);
                                    _la = TokenStream.LA(1);
                                }
                            }
                        }

                        State = 27; Match(T__15);
                    }
                    break;

                    case 4:
                    {
                        _localctx = new StringContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 28; Match(STRING);
                    }
                    break;

                    case 5:
                    {
                        _localctx = new CellRefContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 29; Match(CELLREF);
                    }
                    break;

                    case 6:
                    {
                        _localctx = new BooleanContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 30; Match(BOOLEAN);
                    }
                    break;

                    case 7:
                    {
                        _localctx = new NumberContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 31; Match(NUMBER);
                    }
                    break;

                    case 8:
                    {
                        _localctx = new NameContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 32; Match(NAME);
                    }
                    break;

                    case 9:
                    {
                        _localctx = new ErrorContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 33; Match(ERROR);
                    }
                    break;
                    }
                    Context.Stop = TokenStream.LT(-1);
                    State        = 61;
                    ErrorHandler.Sync(this);
                    _alt = Interpreter.AdaptivePredict(TokenStream, 4, Context);
                    while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER)
                    {
                        if (_alt == 1)
                        {
                            if (ParseListeners != null)
                            {
                                TriggerExitRuleEvent();
                            }
                            _prevctx = _localctx;
                            {
                                State = 59;
                                ErrorHandler.Sync(this);
                                switch (Interpreter.AdaptivePredict(TokenStream, 3, Context))
                                {
                                case 1:
                                {
                                    _localctx = new RangeContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 36;
                                    if (!(Precpred(Context, 17)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 17)");
                                    }
                                    State = 37; Match(T__1);
                                    State = 38; expr(18);
                                }
                                break;

                                case 2:
                                {
                                    _localctx = new PowContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 39;
                                    if (!(Precpred(Context, 14)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 14)");
                                    }
                                    State = 40; Match(T__5);
                                    State = 41; expr(15);
                                }
                                break;

                                case 3:
                                {
                                    _localctx = new MulDivContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 42;
                                    if (!(Precpred(Context, 13)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 13)");
                                    }
                                    State = 43;
                                    ((MulDivContext)_localctx).op = TokenStream.LT(1);
                                    _la = TokenStream.LA(1);
                                    if (!(_la == T__6 || _la == T__7))
                                    {
                                        ((MulDivContext)_localctx).op = ErrorHandler.RecoverInline(this);
                                    }
                                    else
                                    {
                                        ErrorHandler.ReportMatch(this);
                                        Consume();
                                    }
                                    State = 44; expr(14);
                                }
                                break;

                                case 4:
                                {
                                    _localctx = new AddSubContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 45;
                                    if (!(Precpred(Context, 12)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 12)");
                                    }
                                    State = 46;
                                    ((AddSubContext)_localctx).op = TokenStream.LT(1);
                                    _la = TokenStream.LA(1);
                                    if (!(_la == T__2 || _la == T__3))
                                    {
                                        ((AddSubContext)_localctx).op = ErrorHandler.RecoverInline(this);
                                    }
                                    else
                                    {
                                        ErrorHandler.ReportMatch(this);
                                        Consume();
                                    }
                                    State = 47; expr(13);
                                }
                                break;

                                case 5:
                                {
                                    _localctx = new ConcatenateContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 48;
                                    if (!(Precpred(Context, 11)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 11)");
                                    }
                                    State = 49; Match(T__8);
                                    State = 50; expr(12);
                                }
                                break;

                                case 6:
                                {
                                    _localctx = new EqualityContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 51;
                                    if (!(Precpred(Context, 10)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 10)");
                                    }
                                    State = 52;
                                    ((EqualityContext)_localctx).op = TokenStream.LT(1);
                                    _la = TokenStream.LA(1);
                                    if (!(_la == T__0 || _la == T__9))
                                    {
                                        ((EqualityContext)_localctx).op = ErrorHandler.RecoverInline(this);
                                    }
                                    else
                                    {
                                        ErrorHandler.ReportMatch(this);
                                        Consume();
                                    }
                                    State = 53; expr(11);
                                }
                                break;

                                case 7:
                                {
                                    _localctx = new RelationalContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 54;
                                    if (!(Precpred(Context, 9)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 9)");
                                    }
                                    State = 55;
                                    ((RelationalContext)_localctx).op = TokenStream.LT(1);
                                    _la = TokenStream.LA(1);
                                    if (!((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__10) | (1L << T__11) | (1L << T__12) | (1L << T__13))) != 0)))
                                    {
                                        ((RelationalContext)_localctx).op = ErrorHandler.RecoverInline(this);
                                    }
                                    else
                                    {
                                        ErrorHandler.ReportMatch(this);
                                        Consume();
                                    }
                                    State = 56; expr(10);
                                }
                                break;

                                case 8:
                                {
                                    _localctx = new PercentageContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 57;
                                    if (!(Precpred(Context, 15)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 15)");
                                    }
                                    State = 58; Match(T__4);
                                }
                                break;
                                }
                            }
                        }
                        State = 63;
                        ErrorHandler.Sync(this);
                        _alt = Interpreter.AdaptivePredict(TokenStream, 4, Context);
                    }
                }
            }
            catch (RecognitionException re) {
                _localctx.exception = re;
                ErrorHandler.ReportError(this, re);
                ErrorHandler.Recover(this, re);
            }
            finally {
                UnrollRecursionContexts(_parentctx);
            }
            return(_localctx);
        }
Beispiel #15
0
        public RangeContext range()
        {
            RangeContext _localctx = new RangeContext(Context, State);

            EnterRule(_localctx, 16, RULE_range);
            int _la;

            try {
                int _alt;
                EnterOuterAlt(_localctx, 1);
                {
                    State = 81; rangeStart();
                    State = 85;
                    ErrorHandler.Sync(this);
                    _alt = Interpreter.AdaptivePredict(TokenStream, 6, Context);
                    while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER)
                    {
                        if (_alt == 1)
                        {
                            {
                                {
                                    State = 82; Match(WS);
                                }
                            }
                        }
                        State = 87;
                        ErrorHandler.Sync(this);
                        _alt = Interpreter.AdaptivePredict(TokenStream, 6, Context);
                    }
                    State = 89;
                    ErrorHandler.Sync(this);
                    _la = TokenStream.LA(1);
                    if (_la == String)
                    {
                        {
                            State = 88; lower();
                        }
                    }

                    State = 94;
                    ErrorHandler.Sync(this);
                    _la = TokenStream.LA(1);
                    while (_la == WS)
                    {
                        {
                            {
                                State = 91; Match(WS);
                            }
                        }
                        State = 96;
                        ErrorHandler.Sync(this);
                        _la = TokenStream.LA(1);
                    }
                    State = 97; Match(RD);
                    State = 101;
                    ErrorHandler.Sync(this);
                    _alt = Interpreter.AdaptivePredict(TokenStream, 9, Context);
                    while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER)
                    {
                        if (_alt == 1)
                        {
                            {
                                {
                                    State = 98; Match(WS);
                                }
                            }
                        }
                        State = 103;
                        ErrorHandler.Sync(this);
                        _alt = Interpreter.AdaptivePredict(TokenStream, 9, Context);
                    }
                    State = 105;
                    ErrorHandler.Sync(this);
                    _la = TokenStream.LA(1);
                    if (_la == String)
                    {
                        {
                            State = 104; upper();
                        }
                    }

                    State = 110;
                    ErrorHandler.Sync(this);
                    _la = TokenStream.LA(1);
                    while (_la == WS)
                    {
                        {
                            {
                                State = 107; Match(WS);
                            }
                        }
                        State = 112;
                        ErrorHandler.Sync(this);
                        _la = TokenStream.LA(1);
                    }
                    State = 113; rangeEnd();
                }
            }
            catch (RecognitionException re) {
                _localctx.exception = re;
                ErrorHandler.ReportError(this, re);
                ErrorHandler.Recover(this, re);
            }
            finally {
                ExitRule();
            }
            return(_localctx);
        }
            /// <summary>
            /// Initializes a <see cref="RangeQueryNpgsqlFixture"/>.
            /// </summary>
            // ReSharper disable once UnusedMember.Global
            public RangeQueryNpgsqlFixture()
            {
                TestSqlLoggerFactory = new TestSqlLoggerFactory();

                _testStore = NpgsqlTestStore.CreateScratch();

                _options =
                    new DbContextOptionsBuilder()
                    .UseNpgsql(_testStore.ConnectionString, b => b.ApplyConfiguration())
                    .UseInternalServiceProvider(
                        new ServiceCollection()
                        .AddEntityFrameworkNpgsql()
                        .AddSingleton <ILoggerFactory>(TestSqlLoggerFactory)
                        .BuildServiceProvider())
                    .Options;

                using (RangeContext context = CreateContext())
                {
                    context.Database.EnsureCreated();

                    context.RangeTestEntities.AddRange(
                        new RangeTestEntity
                    {
                        Id = 1,
                        // (0, 10)
                        Range = new NpgsqlRange <int>(0, false, false, 10, false, false),
                    },
                        new RangeTestEntity
                    {
                        Id = 2,
                        // [0, 10)
                        Range = new NpgsqlRange <int>(0, true, false, 10, false, false)
                    },
                        new RangeTestEntity
                    {
                        Id = 3,
                        // [0, 10]
                        Range = new NpgsqlRange <int>(0, true, false, 10, true, false)
                    },
                        new RangeTestEntity
                    {
                        Id = 4,
                        // [0, ∞)
                        Range = new NpgsqlRange <int>(0, true, false, 0, false, true)
                    },
                        new RangeTestEntity
                    {
                        Id = 5,
                        // (-∞, 10]
                        Range = new NpgsqlRange <int>(0, false, true, 10, true, false)
                    },
                        new RangeTestEntity
                    {
                        Id = 6,
                        // (-∞, ∞)
                        Range = new NpgsqlRange <int>(0, false, true, 0, false, true)
                    },
                        new RangeTestEntity
                    {
                        Id = 7,
                        // (-∞, ∞)
                        Range = new NpgsqlRange <int>(0, false, true, 0, false, true)
                    });

                    context.SaveChanges();
                }
            }