Skip to content

Commit f13a9aa

Browse files
committed
Npgsql: Validate marshalling GEO_SHAPE types as STRING
1 parent 7d76d60 commit f13a9aa

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

by-language/csharp-npgsql/DemoTypes.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ INSERT INTO testdrive.example (
116116
""array"",
117117
""object"",
118118
geopoint,
119-
-- geoshape,
119+
geoshape,
120120
float_vector
121121
) VALUES (
122122
@null_integer,
@@ -135,7 +135,7 @@ INSERT INTO testdrive.example (
135135
@array,
136136
@object,
137137
@geopoint,
138-
-- @egoshape,
138+
@geoshape,
139139
@float_vector
140140
);
141141
", conn))
@@ -159,8 +159,7 @@ INSERT INTO testdrive.example (
159159
// cmd.Parameters.AddWithValue("object", new Dictionary<string, string>(){{"foo", "bar"}});
160160
cmd.Parameters.AddWithValue("object", @"{""foo"": ""bar""}");
161161
cmd.Parameters.AddWithValue("geopoint", new List<double>{85.43, 66.23});
162-
// FIXME: Npgsql.PostgresException : XX000: line 38:9: no viable alternative at input 'VALUES
163-
// cmd.Parameters.AddWithValue("geoshape", "POLYGON ((5 5, 10 5, 10 10, 5 10, 5 5))");
162+
cmd.Parameters.AddWithValue("geoshape", "POLYGON ((5 5, 10 5, 10 10, 5 10, 5 5))");
164163
cmd.Parameters.AddWithValue("float_vector", new List<double> {1.1, 2.2, 3.3});
165164
cmd.ExecuteNonQuery();
166165
}

by-language/csharp-npgsql/tests/DemoProgramTest.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,12 @@ public async Task TestAllTypesExample()
119119
Assert.Equal(@"{""foo"":""bar""}", row["object"]);
120120

121121
// Geospatial types
122+
// TODO: Unlock native data types?
123+
// GEO_POINT and GEO_SHAPE types can be marshalled back and forth using STRING.
124+
// GEO_POINT is using a tuple format, GEO_SHAPE is using the GeoJSON format.
122125
// Assert.Equal(new List<double>{85.43, 66.23}, row["geopoint"]); // TODO
123126
Assert.Equal("(85.42999997735023,66.22999997343868)", row["geopoint"].ToString()); // FIXME
124-
Assert.Equal(DBNull.Value, row["geoshape"]); // FIXME
127+
Assert.Equal(@"{""coordinates"":[[[5.0,5.0],[5.0,10.0],[10.0,10.0],[10.0,5.0],[5.0,5.0]]],""type"":""Polygon""}", row["geoshape"]);
125128

126129
// Vector type
127130
Assert.Equal((new List<double>{1.1, 2.2, 3.3}).Select(d => (float) d).ToArray(), row["float_vector"]);

0 commit comments

Comments
 (0)