diff --git a/cli/tests/00-base.result b/cli/tests/00-base.result index 6c2f6605..219cfe54 100644 --- a/cli/tests/00-base.result +++ b/cli/tests/00-base.result @@ -37,4 +37,5 @@ NULL "{""k1"":""v1"",""k2"":""v2""}" (2,NULL) 1 NULL 1 ab NULL v1 2 NULL "{""k1"":""v1"",""k2"":""v2""}" [6162,78797A] "([1,2],""2024-04-10"")" +"[{""type"": ""Point"", ""coordinates"": [-122.35,37.55]}]" "[{""type"": ""LineString"", ""coordinates"": [[0.75,0.75],[-10,20]]}]" bye diff --git a/cli/tests/00-base.sql b/cli/tests/00-base.sql index cc7594c2..f618dfa4 100644 --- a/cli/tests/00-base.sql +++ b/cli/tests/00-base.sql @@ -64,6 +64,9 @@ select a[1], b['k1'], c:x, c:y from test_nested; select {'k1':'v1','k2':'v2'}, [to_binary('ab'), to_binary('xyz')], (parse_json('[1,2]'), to_date('2024-04-10')); +set geometry_output_format='GEOJSON'; +select [to_geometry('POINT(-122.35 37.55)')], [st_geographyfromewkt('LINESTRING(0.75 0.75, -10 20)')]; + select 'bye'; drop table test; drop table test_decimal; diff --git a/sql/src/value/string_decoder.rs b/sql/src/value/string_decoder.rs index 9d3c0151..bfd310da 100644 --- a/sql/src/value/string_decoder.rs +++ b/sql/src/value/string_decoder.rs @@ -354,26 +354,28 @@ impl ValueDecoder { fn read_geometry>(&self, reader: &mut Cursor) -> Result { let mut buf = Vec::new(); - if reader.read_quoted_text(&mut buf, b'"').is_err() { - if let Ok(val) = self.read_json(reader) { - return Ok(Value::Variant(val)); - } - reader.read_quoted_text(&mut buf, b'\'')?; + if reader.read_quoted_text(&mut buf, b'"').is_ok() + || reader.read_quoted_text(&mut buf, b'\'').is_ok() + { + Ok(Value::Geometry(unsafe { String::from_utf8_unchecked(buf) })) + } else { + let val = self.read_json(reader)?; + Ok(Value::Geometry(val)) } - Ok(Value::Geometry(unsafe { String::from_utf8_unchecked(buf) })) } fn read_geography>(&self, reader: &mut Cursor) -> Result { let mut buf = Vec::new(); - if reader.read_quoted_text(&mut buf, b'"').is_err() { - if let Ok(val) = self.read_json(reader) { - return Ok(Value::Variant(val)); - } - reader.read_quoted_text(&mut buf, b'\'')?; + if reader.read_quoted_text(&mut buf, b'"').is_ok() + || reader.read_quoted_text(&mut buf, b'\'').is_ok() + { + Ok(Value::Geography(unsafe { + String::from_utf8_unchecked(buf) + })) + } else { + let val = self.read_json(reader)?; + Ok(Value::Geography(val)) } - Ok(Value::Geography(unsafe { - String::from_utf8_unchecked(buf) - })) } fn read_nullable>(