public void LineSegment() { using (var conn = OpenConnection()) { var expected = new NpgsqlLSeg(1, 2, 3, 4); var cmd = new NpgsqlCommand("SELECT @p1, @p2", conn); var p1 = new NpgsqlParameter("p1", NpgsqlDbType.LSeg) { Value = expected }; var p2 = new NpgsqlParameter { ParameterName = "p2", Value = expected }; Assert.That(p2.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.LSeg)); 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(NpgsqlLSeg))); var actual = reader.GetFieldValue <NpgsqlLSeg>(i); AssertPointsEqual(actual.Start, expected.Start); AssertPointsEqual(actual.End, expected.End); } } } }
public void LineSegment() { var expected = new NpgsqlLSeg(1, 2, 3, 4); var cmd = new NpgsqlCommand("SELECT @p1, @p2", Conn); var p1 = new NpgsqlParameter("p1", NpgsqlDbType.LSeg) { Value = expected }; var p2 = new NpgsqlParameter { ParameterName = "p2", Value = expected }; Assert.That(p2.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.LSeg)); 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(NpgsqlLSeg))); Assert.That(reader[i], Is.EqualTo(expected)); } }
public void TestLSegSupport() { _conn.Open(); NpgsqlCommand command = new NpgsqlCommand("select field_lseg from tablee where field_serial = 3", _conn); NpgsqlLSeg lseg = (NpgsqlLSeg)command.ExecuteScalar(); Assert.AreEqual(4, lseg.Start.X); Assert.AreEqual(3, lseg.Start.Y); Assert.AreEqual(5, lseg.End.X); Assert.AreEqual(4, lseg.End.Y); }
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))); }
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(); } } }