Skip to content

Commit a944b2b

Browse files
committed
Fix wrong type names in error messages
1 parent c59d3e6 commit a944b2b

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

src/ewkb.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ macro_rules! point_container_write {
523523
I: 'a + Iterator<Item=&'a T> + ExactSizeIterator<Item=&'a T>
524524
{
525525
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
526-
write!(f, "$ewkbtype")?; //TODO
526+
write!(f, stringify!($ewkbtype))?; //TODO
527527
Ok(())
528528
}
529529
}
@@ -591,7 +591,7 @@ macro_rules! geometry_container_write {
591591
J: 'a + Iterator<Item=&'a T> + ExactSizeIterator<Item=&'a T>
592592
{
593593
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
594-
write!(f, "$ewkbtype")?; //TODO
594+
write!(f, stringify!($ewkbtype))?; //TODO
595595
Ok(())
596596
}
597597
}
@@ -665,7 +665,7 @@ macro_rules! geometry_container_write {
665665
J: 'a + Iterator<Item=&'a T> + ExactSizeIterator<Item=&'a T>
666666
{
667667
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
668-
write!(f, "$ewkbtype")?; //TODO
668+
write!(f, stringify!($ewkbtype))?; //TODO
669669
Ok(())
670670
}
671671
}

src/postgis.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ macro_rules! impl_sql_for_point_type {
3838
accepts_geography!();
3939
fn from_sql(ty: &Type, raw: &[u8], _ctx: &SessionInfo) -> Result<Self, Box<Error + Sync + Send>> {
4040
let mut rdr = Cursor::new(raw);
41-
ewkb::$ptype::read_ewkb(&mut rdr).map_err(|_| format!("cannot convert {} to POINT", ty).into())
41+
ewkb::$ptype::read_ewkb(&mut rdr).map_err(|_| format!("cannot convert {} to {}", ty, stringify!($ptype)).into())
4242
}
4343
}
4444

@@ -67,7 +67,7 @@ macro_rules! impl_sql_for_geom_type {
6767
accepts_geography!();
6868
fn from_sql(ty: &Type, raw: &[u8], _ctx: &SessionInfo) -> Result<Self, Box<Error + Sync + Send>> {
6969
let mut rdr = Cursor::new(raw);
70-
ewkb::$geotype::<T>::read_ewkb(&mut rdr).map_err(|_| format!("cannot convert {} to LINESTRING", ty).into())
70+
ewkb::$geotype::<T>::read_ewkb(&mut rdr).map_err(|_| format!("cannot convert {} to {}", ty, stringify!($geotype)).into())
7171
}
7272
}
7373

@@ -152,7 +152,7 @@ impl<P> FromSql for ewkb::GeometryT<P>
152152
accepts_geography!();
153153
fn from_sql(ty: &Type, raw: &[u8], _ctx: &SessionInfo) -> Result<Self, Box<Error + Sync + Send>> {
154154
let mut rdr = Cursor::new(raw);
155-
ewkb::GeometryT::<P>::read_ewkb(&mut rdr).map_err(|_| format!("cannot convert {} to MultiPoint", ty).into())
155+
ewkb::GeometryT::<P>::read_ewkb(&mut rdr).map_err(|_| format!("cannot convert {} to {}", ty, stringify!(P)).into())
156156
}
157157
}
158158

@@ -162,7 +162,7 @@ impl<P> FromSql for ewkb::GeometryCollectionT<P>
162162
accepts_geography!();
163163
fn from_sql(ty: &Type, raw: &[u8], _ctx: &SessionInfo) -> Result<Self, Box<Error + Sync + Send>> {
164164
let mut rdr = Cursor::new(raw);
165-
ewkb::GeometryCollectionT::<P>::read_ewkb(&mut rdr).map_err(|_| format!("cannot convert {} to MultiPoint", ty).into())
165+
ewkb::GeometryCollectionT::<P>::read_ewkb(&mut rdr).map_err(|_| format!("cannot convert {} to {}", ty, stringify!(P)).into())
166166
}
167167
}
168168

@@ -486,6 +486,15 @@ mod tests {
486486
assert_eq!(format!("{:?}", geom), "Point(PointZ { x: 10, y: -20, z: 99, srid: Some(4326) })");
487487
}
488488

489+
#[test]
490+
#[ignore]
491+
fn test_select_type_error() {
492+
let conn = connect();
493+
let result = or_panic!(conn.query("SELECT ('LINESTRING (10 -20, -0 -0.5)')::geometry", &[]));
494+
let poly = result.iter().map(|r| r.get_opt::<_, ewkb::Polygon>(0)).last().unwrap();
495+
assert_eq!(format!("{:?}", poly), "Some(Err(Conversion(StringError(\"cannot convert geometry to PolygonT\"))))");
496+
}
497+
489498
#[test]
490499
#[ignore]
491500
fn test_twkb() {

src/twkb.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -590,23 +590,23 @@ fn test_write_point() {
590590
fn test_write_line() {
591591
let twkb = hex_to_vec("220002c8018f03c7018603"); // SELECT encode(ST_AsTWKB('LINESTRING (10 -20, -0 -0.5)'::geometry, 1), 'hex')
592592
let line = LineString::read_twkb(&mut twkb.as_slice()).unwrap();
593-
assert_eq!(format!("{:?}", line.as_ewkb()), "$ewkbtype");
593+
assert_eq!(format!("{:?}", line.as_ewkb()), "EwkbLineString");
594594
assert_eq!(line.as_ewkb().to_hex_ewkb(), "010200000002000000000000000000244000000000000034C00000000000000000000000000000E0BF");
595595
}
596596

597597
#[test]
598598
fn test_write_polygon() {
599599
let twkb = hex_to_vec("03000205000004000004030000030514141700001718000018"); // SELECT encode(ST_AsTWKB('POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0),(10 10, -2 10, -2 -2, 10 -2, 10 10))'::geometry), 'hex')
600600
let polygon = Polygon::read_twkb(&mut twkb.as_slice()).unwrap();
601-
assert_eq!(format!("{:?}", polygon.as_ewkb()), "$ewkbtype");
601+
assert_eq!(format!("{:?}", polygon.as_ewkb()), "EwkbPolygon");
602602
assert_eq!(polygon.as_ewkb().to_hex_ewkb(), "010300000002000000050000000000000000000000000000000000000000000000000000400000000000000000000000000000004000000000000000400000000000000000000000000000004000000000000000000000000000000000050000000000000000002440000000000000244000000000000000C0000000000000244000000000000000C000000000000000C0000000000000244000000000000000C000000000000024400000000000002440");
603603
}
604604

605605
#[test]
606606
fn test_write_multipoint() {
607607
let twkb = hex_to_vec("04000214271326"); // SELECT encode(ST_AsTWKB('MULTIPOINT ((10 -20), (0 -0.5))'::geometry), 'hex')
608608
let multipoint = MultiPoint::read_twkb(&mut twkb.as_slice()).unwrap();
609-
assert_eq!(format!("{:?}", multipoint.as_ewkb()), "$ewkbtype");
609+
assert_eq!(format!("{:?}", multipoint.as_ewkb()), "EwkbMultiPoint");
610610
//assert_eq!(multipoint.as_ewkb().to_hex_ewkb(), "0104000000020000000101000000000000000000244000000000000034C001010000000000000000000000000000000000E0BF");
611611
// "MULTIPOINT(10 -20,0 -1)"
612612
assert_eq!(multipoint.as_ewkb().to_hex_ewkb(), "0104000000020000000101000000000000000000244000000000000034C001010000000000000000000000000000000000F0BF");
@@ -616,7 +616,7 @@ fn test_write_multipoint() {
616616
fn test_write_multiline() {
617617
let twkb = hex_to_vec("05000202142713260200020400"); // SELECT encode(ST_AsTWKB('MULTILINESTRING ((10 -20, 0 -0.5), (0 0, 2 0))'::geometry), 'hex')
618618
let multiline = MultiLineString::read_twkb(&mut twkb.as_slice()).unwrap();
619-
assert_eq!(format!("{:?}", multiline.as_ewkb()), "$ewkbtype");
619+
assert_eq!(format!("{:?}", multiline.as_ewkb()), "EwkbMultiLineString");
620620
//assert_eq!(multiline.as_ewkb().to_hex_ewkb(), "010500000002000000010200000002000000000000000000244000000000000034C00000000000000000000000000000E0BF0102000000020000000000000000000000000000000000000000000000000000400000000000000000");
621621
// "MULTILINESTRING((10 -20,0 -1),(0 0,2 0))"
622622
assert_eq!(multiline.as_ewkb().to_hex_ewkb(), "010500000002000000010200000002000000000000000000244000000000000034C00000000000000000000000000000F0BF0102000000020000000000000000000000000000000000000000000000000000400000000000000000");
@@ -626,6 +626,6 @@ fn test_write_multiline() {
626626
fn test_write_multipoly() {
627627
let twkb = hex_to_vec("060002010500000400000403000003010514141700001718000018"); // SELECT encode(ST_AsTWKB('MULTIPOLYGON (((0 0, 2 0, 2 2, 0 2, 0 0)), ((10 10, -2 10, -2 -2, 10 -2, 10 10)))'::geometry), 'hex')
628628
let multipoly = MultiPolygon::read_twkb(&mut twkb.as_slice()).unwrap();
629-
assert_eq!(format!("{:?}", multipoly.as_ewkb()), "$ewkbtype");
629+
assert_eq!(format!("{:?}", multipoly.as_ewkb()), "EwkbMultiPolygon");
630630
assert_eq!(multipoly.as_ewkb().to_hex_ewkb(), "010600000002000000010300000001000000050000000000000000000000000000000000000000000000000000400000000000000000000000000000004000000000000000400000000000000000000000000000004000000000000000000000000000000000010300000001000000050000000000000000002440000000000000244000000000000000C0000000000000244000000000000000C000000000000000C0000000000000244000000000000000C000000000000024400000000000002440");
631631
}

0 commit comments

Comments
 (0)