Exemple #1
0
        public void Circle()
        {
            using (var conn = OpenConnection())
            {
                var expected = new NpgsqlCircle(1, 2, 0.5);
                var cmd      = new NpgsqlCommand("SELECT @p1, @p2", conn);
                var p1       = new NpgsqlParameter("p1", NpgsqlDbType.Circle)
                {
                    Value = expected
                };
                var p2 = new NpgsqlParameter {
                    ParameterName = "p2", Value = expected
                };
                Assert.That(p2.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Circle));
                cmd.Parameters.Add(p1);
                cmd.Parameters.Add(p2);
                using (var reader = cmd.ExecuteReader())
                {
                    reader.Read();

                    for (var i = 0; i < cmd.Parameters.Count; i++)
                    {
                        Assert.That(reader.GetFieldType(i), Is.EqualTo(typeof(NpgsqlCircle)));
                        var actual = reader.GetFieldValue <NpgsqlCircle>(i);
                        Assert.That(actual.X, Is.EqualTo(expected.X).Within(1).Ulps);
                        Assert.That(actual.Y, Is.EqualTo(expected.Y).Within(1).Ulps);
                        Assert.That(actual.Radius, Is.EqualTo(expected.Radius).Within(1).Ulps);
                    }
                }
            }
        }
Exemple #2
0
        public void Circle()
        {
            var expected = new NpgsqlCircle(1, 2, 0.5);
            var cmd      = new NpgsqlCommand("SELECT @p1, @p2", Conn);
            var p1       = new NpgsqlParameter("p1", NpgsqlDbType.Circle)
            {
                Value = expected
            };
            var p2 = new NpgsqlParameter {
                ParameterName = "p2", Value = expected
            };

            Assert.That(p2.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Circle));
            cmd.Parameters.Add(p1);
            cmd.Parameters.Add(p2);
            var reader = cmd.ExecuteReader();

            reader.Read();

            for (var i = 0; i < cmd.Parameters.Count; i++)
            {
                Assert.That(reader.GetFieldType(i), Is.EqualTo(typeof(NpgsqlCircle)));
                Assert.That(reader[i], Is.EqualTo(expected));
            }
        }
Exemple #3
0
        public void TestCircleSupport()
        {
            _conn.Open();

            NpgsqlCommand command = new NpgsqlCommand("select field_circle from tablee where field_serial = 7", _conn);

            NpgsqlCircle circle = (NpgsqlCircle)command.ExecuteScalar();

            Assert.AreEqual(4, circle.Center.X);
            Assert.AreEqual(3, circle.Center.Y);
            Assert.AreEqual(5, circle.Radius);
        }
        private object YieldJToken(Type ctype, JToken jt, int rank)
        {
            if (rank == 0)
            {
                if (ctype == typeof_BitArray)
                {
                    return(Executer.Parse1010(jt.ToString()));
                }

                if (ctype == typeof_NpgsqlPoint)
                {
                    return(NpgsqlPoint.Parse(jt.ToString()));
                }
                if (ctype == typeof_NpgsqlLine)
                {
                    return(NpgsqlLine.Parse(jt.ToString()));
                }
                if (ctype == typeof_NpgsqlLSeg)
                {
                    return(NpgsqlLSeg.Parse(jt.ToString()));
                }
                if (ctype == typeof_NpgsqlBox)
                {
                    return(NpgsqlBox.Parse(jt.ToString()));
                }
                if (ctype == typeof_NpgsqlPath)
                {
                    return(NpgsqlPath.Parse(jt.ToString()));
                }
                if (ctype == typeof_NpgsqlPolygon)
                {
                    return(NpgsqlPolygon.Parse(jt.ToString()));
                }
                if (ctype == typeof_NpgsqlCircle)
                {
                    return(NpgsqlCircle.Parse(jt.ToString()));
                }

                if (ctype == typeof_NpgsqlInet)
                {
                    return(new NpgsqlInet(jt.ToString()));
                }
                if (ctype == typeof_IPAddress)
                {
                    return(new NpgsqlInet(jt.ToString()));
                }
                if (ctype == typeof_PhysicalAddress)
                {
                    return(PhysicalAddress.Parse(jt.ToString()));
                }

                if (ctype == typeof_NpgsqlRange_int)
                {
                    return(Executer.ParseNpgsqlRange <int>(jt.ToString()));
                }
                if (ctype == typeof_NpgsqlRange_long)
                {
                    return(Executer.ParseNpgsqlRange <long>(jt.ToString()));
                }
                if (ctype == typeof_NpgsqlRange_decimal)
                {
                    return(Executer.ParseNpgsqlRange <decimal>(jt.ToString()));
                }
                if (ctype == typeof_NpgsqlRange_DateTime)
                {
                    return(Executer.ParseNpgsqlRange <DateTime>(jt.ToString()));
                }

                return(null);
            }
            return(jt.Select <JToken, object>(a => YieldJToken(ctype, a, rank - 1)));
        }
Exemple #5
0
        public void MainTest()
        {
            NpgsqlPoint point = new NpgsqlPoint(1, 2);
            NpgsqlLSeg  lSeg  = new NpgsqlLSeg(new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4));
            NpgsqlBox   box   = new NpgsqlBox(new NpgsqlPoint(1, 1), new NpgsqlPoint(-1, -1));
            NpgsqlPath  path  = new NpgsqlPath(new[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) })
            {
                Open = true
            };
            NpgsqlPolygon polygon = new NpgsqlPolygon(new[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4), new NpgsqlPoint(5, 6) });
            NpgsqlCircle  circle  = new NpgsqlCircle(new NpgsqlPoint(1, 2), 3);

            using (Domain.OpenSession()) {
                using (var t = Session.Current.OpenTransaction()) {
                    _ = new Container {
                        Point   = new NpgsqlPoint(),
                        LSeg    = new NpgsqlLSeg(),
                        Box     = new NpgsqlBox(),
                        Path    = new NpgsqlPath(),
                        Polygon = new NpgsqlPolygon(),
                        Circle  = new NpgsqlCircle()
                    };

                    _ = new Container {
                        Point   = point,
                        LSeg    = lSeg,
                        Box     = box,
                        Path    = path,
                        Polygon = polygon,
                        Circle  = circle
                    };
                    t.Complete();
                }

                using (var t = Session.Current.OpenTransaction()) {
                    var record = Query.All <Container>().First(c => c.Id == 1);

                    Console.WriteLine("The record without the initial parameters:");
                    OutputRecord(record);

                    Assert.IsTrue(record.Point.Equals(new NpgsqlPoint()));
                    Assert.IsTrue(record.LSeg.Equals(new NpgsqlLSeg()));
                    Assert.IsTrue(record.Box.Equals(new NpgsqlBox()));
                    Assert.IsTrue(record.Path.Equals(new NpgsqlPath(new[] { new NpgsqlPoint() })));
                    Assert.IsTrue(record.Polygon.Equals(new NpgsqlPolygon(new[] { new NpgsqlPoint() })));
                    Assert.IsTrue(record.Circle.Equals(new NpgsqlCircle()));

                    record = Query.All <Container>().First(c => c.Id == 2);

                    Console.WriteLine("The record with the initial parameters:");
                    OutputRecord(record);
                    Assert.IsTrue(record.Point.Equals(point));
                    Assert.IsTrue(record.LSeg.Equals(lSeg));
                    Assert.IsTrue(record.Box.Equals(box));
                    Assert.IsTrue(record.Path.Equals(path));
                    Assert.IsTrue(record.Polygon.Equals(polygon));
                    Assert.IsTrue(record.Circle.Equals(circle));

                    t.Complete();
                }
            }
        }