Skip to content

Commit

Permalink
fix: add WGS84_ONLY option to InitSpatialMetadata and only call the…
Browse files Browse the repository at this point in the history
… function if necessary
  • Loading branch information
Oreilles committed Nov 29, 2023
1 parent 7b8348c commit 31228b5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
13 changes: 11 additions & 2 deletions quaint/src/connector/sqlite/native/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@ pub fn load_spatialite(conn: &rusqlite::Connection) -> crate::Result<()> {
unsafe {
let _guard = LoadExtensionGuard::new(conn)?;
conn.load_extension(spatialite_path, None)?;
conn.query_row("SELECT InitSpatialMetaData(1)", [], |_| Ok(())).unwrap();
}
return match conn.query_row("SELECT CheckSpatialMetaData()", [], |r| r.get(0))? {
0 => {
match conn.query_row("SELECT InitSpatialMetaData(1, 'WGS84_ONLY')", [], |r| r.get(0))? {
1 => Ok(()),
_ => Err(Error::builder(ErrorKind::QueryError("Failed to load Spatialite".into())).build()),
}
},
3 => Ok(()),
_ => Err(Error::builder(ErrorKind::ConnectionError("Invalid Spatialite State".into())).build())
}
}
}
Ok(())
return Ok(())
}

impl TryFrom<&str> for Sqlite {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ mod sqlite {
let schema = indoc! {
r#"model Model {
#id(id, String, @id, @default(cuid()))
geometry Geometry @test.Geometry(Geometry, 3857)
geometry_point Geometry @test.Geometry(Point, 3857)
geometry_line Geometry @test.Geometry(LineString, 3857)
geometry_poly Geometry @test.Geometry(Polygon, 3857)
geometry_multipoint Geometry @test.Geometry(MultiPoint, 3857)
geometry_multiline Geometry @test.Geometry(MultiLineString, 3857)
geometry_multipoly Geometry @test.Geometry(MultiPolygon, 3857)
geometry_collection Geometry @test.Geometry(GeometryCollection, 3857)
geometry Geometry @test.Geometry(Geometry, 4326)
geometry_point Geometry @test.Geometry(Point, 4326)
geometry_line Geometry @test.Geometry(LineString, 4326)
geometry_poly Geometry @test.Geometry(Polygon, 4326)
geometry_multipoint Geometry @test.Geometry(MultiPoint, 4326)
geometry_multiline Geometry @test.Geometry(MultiLineString, 4326)
geometry_multipoly Geometry @test.Geometry(MultiPolygon, 4326)
geometry_collection Geometry @test.Geometry(GeometryCollection, 4326)
}"#
};

Expand All @@ -81,14 +81,14 @@ mod sqlite {
run_query!(&runner, r#"mutation {
createOneModel(
data: {
geometry: "SRID=3857;POINT(1 2)"
geometry_point: "SRID=3857;POINT(1 2)"
geometry_line: "SRID=3857;LINESTRING(1 2,3 4)"
geometry_poly: "SRID=3857;POLYGON((1 2,3 4,5 6,1 2))"
geometry_multipoint: "SRID=3857;MULTIPOINT(1 2)"
geometry_multiline: "SRID=3857;MULTILINESTRING((1 2,3 4))"
geometry_multipoly: "SRID=3857;MULTIPOLYGON(((1 2,3 4,5 6,1 2)))"
geometry_collection: "SRID=3857;GEOMETRYCOLLECTION(POINT(1 2))"
geometry: "SRID=4326;POINT(1 2)"
geometry_point: "SRID=4326;POINT(1 2)"
geometry_line: "SRID=4326;LINESTRING(1 2,3 4)"
geometry_poly: "SRID=4326;POLYGON((1 2,3 4,5 6,1 2))"
geometry_multipoint: "SRID=4326;MULTIPOINT(1 2)"
geometry_multiline: "SRID=4326;MULTILINESTRING((1 2,3 4))"
geometry_multipoly: "SRID=4326;MULTIPOLYGON(((1 2,3 4,5 6,1 2)))"
geometry_collection: "SRID=4326;GEOMETRYCOLLECTION(POINT(1 2))"
}
) {
geometry
Expand All @@ -101,7 +101,7 @@ mod sqlite {
geometry_collection
}
}"#),
@r###"{"data":{"createOneModel":{"geometry":"SRID=3857;POINT(1 2)","geometry_point":"SRID=3857;POINT(1 2)","geometry_line":"SRID=3857;LINESTRING(1 2,3 4)","geometry_poly":"SRID=3857;POLYGON((1 2,3 4,5 6,1 2))","geometry_multipoint":"SRID=3857;MULTIPOINT(1 2)","geometry_multiline":"SRID=3857;MULTILINESTRING((1 2,3 4))","geometry_multipoly":"SRID=3857;MULTIPOLYGON(((1 2,3 4,5 6,1 2)))","geometry_collection":"SRID=3857;GEOMETRYCOLLECTION(POINT(1 2))"}}}"###
@r###"{"data":{"createOneModel":{"geometry":"SRID=4326;POINT(1 2)","geometry_point":"SRID=4326;POINT(1 2)","geometry_line":"SRID=4326;LINESTRING(1 2,3 4)","geometry_poly":"SRID=4326;POLYGON((1 2,3 4,5 6,1 2))","geometry_multipoint":"SRID=4326;MULTIPOINT(1 2)","geometry_multiline":"SRID=4326;MULTILINESTRING((1 2,3 4))","geometry_multipoly":"SRID=4326;MULTIPOLYGON(((1 2,3 4,5 6,1 2)))","geometry_collection":"SRID=4326;GEOMETRYCOLLECTION(POINT(1 2))"}}}"###
);

Ok(())
Expand Down

0 comments on commit 31228b5

Please sign in to comment.