public NpgsqlCircle(NpgsqlPoint center, double radius) : this() { X = center.X; Y = center.Y; Radius = radius; }
public void Point() { using (var conn = OpenConnection()) { var expected = new NpgsqlPoint(1.2, 3.4); var cmd = new NpgsqlCommand("SELECT @p1, @p2", conn); var p1 = new NpgsqlParameter("p1", NpgsqlDbType.Point) { Value = expected }; var p2 = new NpgsqlParameter { ParameterName = "p2", Value = expected }; Assert.That(p2.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Point)); 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(NpgsqlPoint))); var actual = reader.GetFieldValue <NpgsqlPoint>(i); AssertPointsEqual(actual, expected); } } } }
public void Point() { var expected = new NpgsqlPoint(1.2, 3.4); var cmd = new NpgsqlCommand("SELECT @p1, @p2", Conn); var p1 = new NpgsqlParameter("p1", NpgsqlDbType.Point) { Value = expected }; var p2 = new NpgsqlParameter { ParameterName = "p2", Value = expected }; Assert.That(p2.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Point)); 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(NpgsqlPoint))); Assert.That(reader[i], Is.EqualTo(expected)); } }
/// <summary> /// 测量两个经纬度的距离,返回单位:米 /// </summary> /// <param name="that">经纬坐标1</param> /// <param name="point">经纬坐标2</param> /// <returns>返回距离(单位:米)</returns> public static double Distance(this NpgsqlPoint that, NpgsqlPoint point) { double radLat1 = (double)(that.Y) * Math.PI / 180d; double radLng1 = (double)(that.X) * Math.PI / 180d; double radLat2 = (double)(point.Y) * Math.PI / 180d; double radLng2 = (double)(point.X) * Math.PI / 180d; return(2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin((radLat1 - radLat2) / 2), 2) + Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin((radLng1 - radLng2) / 2), 2))) * 6378137); }
public void TestPointSupport() { _conn.Open(); NpgsqlCommand command = new NpgsqlCommand("select field_point from tablee where field_serial = 1", _conn); NpgsqlPoint p = (NpgsqlPoint)command.ExecuteScalar(); Assert.AreEqual(4, p.X); Assert.AreEqual(3, p.Y); }
public void ContainsTest() { NpgsqlPoint pointContains = new NpgsqlPoint(4, 5); NpgsqlPoint pointNotContains = new NpgsqlPoint(4, 6); using (var session = Domain.OpenSession()) { using (var t = session.OpenTransaction()) { var query = session.Query.All <EntityWithNpgsqlPolygon>() .Where(e => e.Polygon.Contains(pointContains)); Assert.IsTrue(query.ToList().FirstOrDefault() != null); query = session.Query.All <EntityWithNpgsqlPolygon>() .Where(e => e.Polygon.Contains(pointNotContains)); Assert.IsTrue(query.ToList().FirstOrDefault() == null); t.Complete(); } } }
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))); }
/// <summary> /// Our import command to import the data for the day into our pgsql database, /// will be broken up into multiple functions for increased readability /// </summary> /// <param name="dataset">Our current DataSet to load into our DB</param> /// <param name="connString">The string to initialize the connection to the database</param> /// <param name="tableName">The tableName, set to calls by default, allows for testing /// to a different table without adding fake data to the database, the testing database is /// otherwise functionally identical to the calls database /// </param> public void Import(List <Json311> dataset, String connString, string tableName = "calls", Boolean updateTime = true) { using (var conn = new NpgsqlConnection(connString)) { /// <remarks> /// Make Sure data is not duplicated /// </remarks> conn.Open(); this.CheckConnection(conn); //conn.TypeMapper.UseJsonNet(); NpgsqlDateTime last_date = new NpgsqlDateTime(); DateTime construct = new DateTime(0); NpgsqlDateTime most_recent = new NpgsqlDateTime(construct); /// <remarks> /// Get the DateStamp frmo our checktime table /// We do this in order to check the stored datestamp so as not to import duplicate DATA /// We cannot read and write over the same connection so we need to retrieve the dateTime so we can check it against the timestamp /// of the entries later /// </remarks> if (updateTime == true) { using (NpgsqlCommand checkDate = new NpgsqlCommand("SELECT * FROM checktime", conn)) using (NpgsqlDataReader reader = checkDate.ExecuteReader()) { try { while (reader.Read()) { last_date = reader.GetTimeStamp(0); reader.Close(); } } catch (Exception a) { Console.WriteLine(a); } } } int oldC = 0, newC = 0; /// <remarks> /// postgres does not support nullable datetimes so we check the DateTime fields and /// write a null if the value is null /// if not we cast the nullable datetime to datetime and then write that /// Using the tablename variable allows us to change the target table without changing all the code /// </remarks> using (var writer = conn.BeginBinaryImport("COPY " + tableName + " FROM STDIN (FORMAT BINARY)")) { foreach (Json311 entry in dataset) { /// <remarks> /// Check the retrieved dateTime against the entries dateTime /// </remarks> NpgsqlDateTime entryDate = Convert.ToDateTime(entry.Created_date); if (entryDate < last_date) { if (most_recent < entryDate) { most_recent = entryDate; } oldC++; continue; } writer.StartRow(); writer.Write(entry.Unique_key); if (entry.Created_date == null) { writer.WriteNull(); } else { NpgsqlDateTime cdate = Convert.ToDateTime(entry.Created_date); writer.Write(cdate); } if (entry.Closed_date == null) { writer.WriteNull(); } else { NpgsqlDateTime cdate = Convert.ToDateTime(entry.Closed_date); writer.Write(cdate); } writer.Write(entry.Agency); writer.Write(entry.Agency_name); writer.Write(entry.Complaint_type); writer.Write(entry.Descriptor); writer.Write(entry.Location_type); writer.Write(entry.Incident_zip); writer.Write(entry.Incident_address); writer.Write(entry.Street_name); writer.Write(entry.Cross_street_1); writer.Write(entry.Cross_street_2); writer.Write(entry.Intersection_street_1); writer.Write(entry.Intersection_street_2); writer.Write(entry.Address_type); writer.Write(entry.City); writer.Write(entry.Landmark); writer.Write(entry.Facility_type); writer.Write(entry.Status); if (entry.Due_date == null) { writer.WriteNull(); } else { NpgsqlDateTime dDate = Convert.ToDateTime(entry.Due_date); writer.Write(dDate); } writer.Write(entry.Resolution_description); if (entry.Resolution_action_updated_date == null) { writer.WriteNull(); } else { NpgsqlDateTime rDate = Convert.ToDateTime(entry.Resolution_action_updated_date); writer.Write(rDate); } writer.Write(entry.Community_board); writer.Write(entry.Bbl); writer.Write(entry.Borough); writer.Write(entry.X_coordinate_state_plane); writer.Write(entry.Y_coordinate_state_plane); writer.Write(entry.Open_data_channel_type); writer.Write(entry.Park_facility_name); writer.Write(entry.Park_borough); writer.Write(entry.Vehicle_type); writer.Write(entry.Taxi_company_borough); writer.Write(entry.Taxi_pick_up_location); writer.Write(entry.Bridge_highway_name); writer.Write(entry.Bridge_highway_direction); writer.Write(entry.Road_ramp); writer.Write(entry.Bridge_highway_segment); writer.Write(entry.Latitude); writer.Write(entry.Longitude); writer.Write(entry.Location_city); if (entry.Location == null) { writer.WriteNull(); } else { var dat = entry.Location.SelectToken("coordinates"); double x = (double)dat[0]; double y = (double)dat[1]; NpgsqlPoint nPoint = new NpgsqlPoint(x, y); writer.Write(nPoint); } writer.Write(entry.Location_zip); writer.Write(entry.Location_state); newC++; } writer.Complete(); } Console.WriteLine("New Records:" + newC + " Old Records: " + oldC); /// <remarks> /// Update the stored Date in the checktime table, only update the time /// if we are actually adding data and not just for a test /// </remarks> if (updateTime == true) { NpgsqlCommand dropCheck = new NpgsqlCommand("DROP TABLE checktime", conn); dropCheck.ExecuteNonQuery(); NpgsqlCommand newCheck = new NpgsqlCommand("CREATE TABLE checktime (curr_up_date timestamp)", conn); newCheck.ExecuteNonQuery(); using (var writer = conn.BeginBinaryImport("COPY checktime FROM STDIN (FORMAT BINARY)")) { writer.StartRow(); writer.Write(most_recent); writer.Complete(); } } /// <remarks> /// Closes the connection when we are finished with it /// </remarks> conn.Close(); } }
public static Point2 <double> ToGeom(NpgsqlPoint geom) { return(factory.ConstructPoint(geom.X, geom.Y)); }
void AssertPointsEqual(NpgsqlPoint actual, NpgsqlPoint expected) { Assert.That(actual.X, Is.EqualTo(expected.X).Within(1).Ulps); Assert.That(actual.Y, Is.EqualTo(expected.Y).Within(1).Ulps); }
public async Task <ActionResult <LocationHistoryDetailsDTO> > AddLocationToHistory(LocationHistoryDTO locationHistoryDTO) { try { var cartIdExists = _context.Carts.Any(c => c.CartId == locationHistoryDTO.CartId); var siteIdExists = _context.Sites.Any(s => s.SiteId == locationHistoryDTO.SiteId); //check if cartid exists if (!cartIdExists && locationHistoryDTO.CartId != null) { //add error message ModelState.AddModelError("CartId", "No cart found with given cart id."); } //check if siteid exists if (!siteIdExists && locationHistoryDTO.SiteId != null) { //add error message ModelState.AddModelError("SiteId", "No site found with given site id."); } //if model is not valid return error messages if (!ModelState.IsValid) { return(BadRequest(ModelState.ToDictionary(x => x.Key, x => x.Value.Errors.Select(e => e.ErrorMessage).ToArray()))); } //tries to parse cart coordinates to NpgsqlPoint. if exception, return bad request var coords = new NpgsqlPoint();; try { coords = NpgsqlPoint.Parse(locationHistoryDTO.CartCoordinates); } catch (FormatException e) { //if exception is caught write to console and return error message Console.WriteLine("{0} Exception caught.", e); //add error message ModelState.AddModelError("CartCoordinates", "Invalid input: CartCoordinates must be specified using the following syntax \'(x,y)\' where x and y are the respective coordinates, as floating-point numbers."); return(BadRequest(ModelState.ToDictionary(x => x.Key, x => x.Value.Errors.Select(e => e.ErrorMessage).ToArray()))); } //create location history var locationHistory = new LocationHistory { CartId = locationHistoryDTO.CartId, SiteId = locationHistoryDTO.SiteId, CartCoordinates = coords, RecordDate = DateTime.Now }; //insert location history _context.LocationHistories.Add(locationHistory); await _context.SaveChangesAsync(); //rerturn the new location history details return(CreatedAtAction( nameof(GetLocationHistoryByRecordId), new { recordId = locationHistory.RecordId }, LocationHistoryToLocationHistoryDetailsDTO(locationHistory))); } catch (InvalidOperationException e) { //if exception is caught write to console and return error message Console.WriteLine("{0} Exception caught.", e); return(BadRequest(new { ApiProblem = "Invalid JSON format sent." })); } }
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(); } } }
public virtual void Can_query_using_any_mapped_data_type() { using (var context = CreateContext()) { context.Set <MappedNullableDataTypes>().Add( new MappedNullableDataTypes { Tinyint = 80, Smallint = 79, Int = 999, Bigint = 78L, Real = 84.4f, Double_precision = 85.5, Decimal = 101.7m, Numeric = 103.9m, Text = "Gumball Rules!", Bytea = new byte[] { 86 }, Timestamp = new DateTime(2015, 1, 2, 10, 11, 12), //Timestamptz = new DateTime(2016, 1, 2, 11, 11, 12, DateTimeKind.Utc), Date = new DateTime(2015, 1, 2, 0, 0, 0), Time = new TimeSpan(11, 15, 12), //Timetz = new DateTimeOffset(0, 0, 0, 12, 0, 0, TimeSpan.FromHours(2)), Interval = new TimeSpan(11, 15, 12), Uuid = new Guid("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11"), Bool = true, Macaddr = PhysicalAddress.Parse("08-00-2B-01-02-03"), Point = new NpgsqlPoint(5.2, 3.3), Jsonb = @"{""a"": ""b""}", Hstore = new Dictionary <string, string> { { "a", "b" } }, //SomeComposite = new SomeComposite { SomeNumber = 8, SomeText = "foo" } }); Assert.Equal(1, context.SaveChanges()); } using (var context = CreateContext()) { var entity = context.Set <MappedNullableDataTypes>().Single(e => e.Int == 999); byte?param1 = 80; Assert.Same(entity, context.Set <MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Tinyint == param1)); short?param2 = 79; Assert.Same(entity, context.Set <MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Smallint == param2)); long?param3 = 78L; Assert.Same(entity, context.Set <MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Bigint == param3)); float?param4 = 84.4f; Assert.Same(entity, context.Set <MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Real == param4)); double?param5 = 85.5; Assert.Same(entity, context.Set <MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Double_precision == param5)); decimal?param6 = 101.7m; Assert.Same(entity, context.Set <MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Decimal == param6)); decimal?param7 = 103.9m; Assert.Same(entity, context.Set <MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Numeric == param7)); var param8 = "Gumball Rules!"; Assert.Same(entity, context.Set <MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Text == param8)); var param9 = new byte[] { 86 }; Assert.Same(entity, context.Set <MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Bytea == param9)); DateTime?param10 = new DateTime(2015, 1, 2, 10, 11, 12); Assert.Same(entity, context.Set <MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Timestamp == param10)); //DateTime? param11 = new DateTime(2019, 1, 2, 14, 11, 12, DateTimeKind.Utc); //Assert.Same(entity, context.Set<MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Timestamptz == param11)); DateTime?param12 = new DateTime(2015, 1, 2, 0, 0, 0); Assert.Same(entity, context.Set <MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Date == param12)); TimeSpan?param13 = new TimeSpan(11, 15, 12); Assert.Same(entity, context.Set <MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Time == param13)); //DateTimeOffset? param14 = new DateTimeOffset(0, 0, 0, 12, 0, 0, TimeSpan.FromHours(2)); //Assert.Same(entity, context.Set<MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Timetz == param14)); TimeSpan?param15 = new TimeSpan(11, 15, 12); Assert.Same(entity, context.Set <MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Interval == param15)); Guid?param16 = new Guid("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11"); Assert.Same(entity, context.Set <MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Uuid == param16)); bool?param17 = true; Assert.Same(entity, context.Set <MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Bool == param17)); PhysicalAddress param18 = PhysicalAddress.Parse("08-00-2B-01-02-03"); Assert.Same(entity, context.Set <MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Macaddr.Equals(param18))); NpgsqlPoint?param19 = new NpgsqlPoint(5.2, 3.3); Assert.Same(entity, context.Set <MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Point == param19)); // The following fails because of https://github.com/aspnet/EntityFramework/issues/3617, // or rather https://github.com/aspnet/EntityFramework/issues/4608 //var param20 = @"{""a"": ""b""}"; //Assert.Same(entity, context.Set<MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Jsonb == param20)); // The following fails because of https://github.com/aspnet/EntityFramework/issues/5365 // var param21 = new Dictionary<string, string> { { "a", "b" } }; // Assert.Same(entity, context.Set<MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Hstore == param21)); //SomeComposite param22 = new SomeComposite { SomeNumber = 8, SomeText = "foo" }; //Assert.Same(entity, context.Set<MappedNullableDataTypes>().Single(e => e.Int == 999 && e.SomeComposite.Equals(param20))); } }
public void Import(List <Json311> dataset, String connString, string tableName = "calls", Boolean updateTime = true) { NpgsqlDateTime last_date = new NpgsqlDateTime(); DateTime construct = new DateTime(0); NpgsqlDateTime most_recent = new NpgsqlDateTime(construct); if (updateTime == true) { using (NpgsqlCommand checkDate = new NpgsqlCommand("SELECT * FROM checktime", _dbConnect)) using (NpgsqlDataReader reader = checkDate.ExecuteReader()) { try { while (reader.Read()) { last_date = reader.GetTimeStamp(0); reader.Close(); } } catch (Exception a) { Console.WriteLine(a); } } } int oldC = 0, newC = 0; using (var writer = _dbConnect.BeginBinaryImport("COPY " + tableName + " FROM STDIN (FORMAT BINARY)")) { foreach (Json311 entry in dataset) { NpgsqlDateTime entryDate = Convert.ToDateTime(entry.Created_date); if (entryDate < last_date) { if (most_recent < entryDate) { most_recent = entryDate; } oldC++; continue; } writer.StartRow(); writer.Write(entry.Unique_key); if (entry.Created_date == null) { writer.WriteNull(); } else { NpgsqlDateTime cdate = Convert.ToDateTime(entry.Created_date); writer.Write(cdate); } if (entry.Closed_date == null) { writer.WriteNull(); } else { NpgsqlDateTime cdate = Convert.ToDateTime(entry.Closed_date); writer.Write(cdate); } writer.Write(entry.Agency); writer.Write(entry.Agency_name); writer.Write(entry.Complaint_type); writer.Write(entry.Descriptor); writer.Write(entry.Location_type); writer.Write(entry.Incident_zip); writer.Write(entry.Incident_address); writer.Write(entry.Street_name); writer.Write(entry.Cross_street_1); writer.Write(entry.Cross_street_2); writer.Write(entry.Intersection_street_1); writer.Write(entry.Intersection_street_2); writer.Write(entry.Address_type); writer.Write(entry.City); writer.Write(entry.Landmark); writer.Write(entry.Facility_type); writer.Write(entry.Status); if (entry.Due_date == null) { writer.WriteNull(); } else { NpgsqlDateTime dDate = Convert.ToDateTime(entry.Due_date); writer.Write(dDate); } writer.Write(entry.Resolution_description); if (entry.Resolution_action_updated_date == null) { writer.WriteNull(); } else { NpgsqlDateTime rDate = Convert.ToDateTime(entry.Resolution_action_updated_date); writer.Write(rDate); } writer.Write(entry.Community_board); writer.Write(entry.Bbl); writer.Write(entry.Borough); writer.Write(entry.X_coordinate_state_plane); writer.Write(entry.Y_coordinate_state_plane); writer.Write(entry.Open_data_channel_type); writer.Write(entry.Park_facility_name); writer.Write(entry.Park_borough); writer.Write(entry.Vehicle_type); writer.Write(entry.Taxi_company_borough); writer.Write(entry.Taxi_pick_up_location); writer.Write(entry.Bridge_highway_name); writer.Write(entry.Bridge_highway_direction); writer.Write(entry.Road_ramp); writer.Write(entry.Bridge_highway_segment); writer.Write(entry.Latitude); writer.Write(entry.Longitude); writer.Write(entry.Location_city); if (entry.Location == null) { writer.WriteNull(); } else { var dat = entry.Location.SelectToken("coordinates"); double x = (double)dat[0]; double y = (double)dat[1]; NpgsqlPoint nPoint = new NpgsqlPoint(x, y); writer.Write(nPoint); } writer.Write(entry.Location_zip); writer.Write(entry.Location_state); newC++; } writer.Complete(); } Console.WriteLine("New Records:" + newC + " Old Records: " + oldC); if (updateTime == true) { NpgsqlCommand dropCheck = new NpgsqlCommand("DROP TABLE checktime", _dbConnect); dropCheck.ExecuteNonQuery(); NpgsqlCommand newCheck = new NpgsqlCommand("CREATE TABLE checktime (curr_up_date timestamp)", _dbConnect); newCheck.ExecuteNonQuery(); using (var writer = _dbConnect.BeginBinaryImport("COPY checktime FROM STDIN (FORMAT BINARY)")) { writer.StartRow(); writer.Write(most_recent); writer.Complete(); } } }