Commit 6b64baf3 authored by Alexey Botchkov's avatar Alexey Botchkov

fix for bug 848926 GIS functions return "GEOMETRYCOLLECTION()" instead of...

fix for bug 848926 GIS functions return "GEOMETRYCOLLECTION()" instead of "GEOMETRYCOLLECTION EMPTY"

per-file comments:
  mysql-test/r/gis.result
fix for bug 848926 GIS functions return "GEOMETRYCOLLECTION()" instead of "GEOMETRYCOLLECTION EMPTY"
        test result updated.
  mysql-test/t/gis.test
fix for bug 848926 GIS functions return "GEOMETRYCOLLECTION()" instead of "GEOMETRYCOLLECTION EMPTY"
        test case added.
  sql/gstream.cc
fix for bug 848926 GIS functions return "GEOMETRYCOLLECTION()" instead of "GEOMETRYCOLLECTION EMPTY"
        lookup_next_word() implemented.
  sql/gstream.h
fix for bug 848926 GIS functions return "GEOMETRYCOLLECTION()" instead of "GEOMETRYCOLLECTION EMPTY"
        lookup_next_word() added.
  sql/spatial.cc
fix for bug 848926 GIS functions return "GEOMETRYCOLLECTION()" instead of "GEOMETRYCOLLECTION EMPTY"
        name changed for the empty geometry.
  sql/spatial.h
fix for bug 848926 GIS functions return "GEOMETRYCOLLECTION()" instead of "GEOMETRYCOLLECTION EMPTY"
        declarations modified.
parent 25b5019c
...@@ -67,7 +67,8 @@ INSERT INTO gis_multi_polygon VALUES ...@@ -67,7 +67,8 @@ INSERT INTO gis_multi_polygon VALUES
INSERT INTO gis_geometrycollection VALUES INSERT INTO gis_geometrycollection VALUES
(120, GeomCollFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))')), (120, GeomCollFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))')),
(121, GeometryFromWKB(AsWKB(GeometryCollection(Point(44, 6), LineString(Point(3, 6), Point(7, 9)))))), (121, GeometryFromWKB(AsWKB(GeometryCollection(Point(44, 6), LineString(Point(3, 6), Point(7, 9)))))),
(122, GeomFromText('GeometryCollection()')); (122, GeomFromText('GeometryCollection()')),
(123, GeomFromText('GeometryCollection EMPTY'));
INSERT into gis_geometry SELECT * FROM gis_point; INSERT into gis_geometry SELECT * FROM gis_point;
INSERT into gis_geometry SELECT * FROM gis_line; INSERT into gis_geometry SELECT * FROM gis_line;
INSERT into gis_geometry SELECT * FROM gis_polygon; INSERT into gis_geometry SELECT * FROM gis_polygon;
...@@ -110,7 +111,8 @@ SELECT fid, AsText(g) FROM gis_geometrycollection; ...@@ -110,7 +111,8 @@ SELECT fid, AsText(g) FROM gis_geometrycollection;
fid AsText(g) fid AsText(g)
120 GEOMETRYCOLLECTION(POINT(0 0),LINESTRING(0 0,10 10)) 120 GEOMETRYCOLLECTION(POINT(0 0),LINESTRING(0 0,10 10))
121 GEOMETRYCOLLECTION(POINT(44 6),LINESTRING(3 6,7 9)) 121 GEOMETRYCOLLECTION(POINT(44 6),LINESTRING(3 6,7 9))
122 GEOMETRYCOLLECTION() 122 GEOMETRYCOLLECTION EMPTY
123 GEOMETRYCOLLECTION EMPTY
SELECT fid, AsText(g) FROM gis_geometry; SELECT fid, AsText(g) FROM gis_geometry;
fid AsText(g) fid AsText(g)
101 POINT(10 10) 101 POINT(10 10)
...@@ -134,7 +136,8 @@ fid AsText(g) ...@@ -134,7 +136,8 @@ fid AsText(g)
119 MULTIPOLYGON(((0 3,3 3,3 0,0 3))) 119 MULTIPOLYGON(((0 3,3 3,3 0,0 3)))
120 GEOMETRYCOLLECTION(POINT(0 0),LINESTRING(0 0,10 10)) 120 GEOMETRYCOLLECTION(POINT(0 0),LINESTRING(0 0,10 10))
121 GEOMETRYCOLLECTION(POINT(44 6),LINESTRING(3 6,7 9)) 121 GEOMETRYCOLLECTION(POINT(44 6),LINESTRING(3 6,7 9))
122 GEOMETRYCOLLECTION() 122 GEOMETRYCOLLECTION EMPTY
123 GEOMETRYCOLLECTION EMPTY
SELECT fid, Dimension(g) FROM gis_geometry; SELECT fid, Dimension(g) FROM gis_geometry;
fid Dimension(g) fid Dimension(g)
101 0 101 0
...@@ -159,6 +162,7 @@ fid Dimension(g) ...@@ -159,6 +162,7 @@ fid Dimension(g)
120 1 120 1
121 1 121 1
122 0 122 0
123 0
SELECT fid, GeometryType(g) FROM gis_geometry; SELECT fid, GeometryType(g) FROM gis_geometry;
fid GeometryType(g) fid GeometryType(g)
101 POINT 101 POINT
...@@ -183,6 +187,7 @@ fid GeometryType(g) ...@@ -183,6 +187,7 @@ fid GeometryType(g)
120 GEOMETRYCOLLECTION 120 GEOMETRYCOLLECTION
121 GEOMETRYCOLLECTION 121 GEOMETRYCOLLECTION
122 GEOMETRYCOLLECTION 122 GEOMETRYCOLLECTION
123 GEOMETRYCOLLECTION
SELECT fid, IsEmpty(g) FROM gis_geometry; SELECT fid, IsEmpty(g) FROM gis_geometry;
fid IsEmpty(g) fid IsEmpty(g)
101 0 101 0
...@@ -207,6 +212,7 @@ fid IsEmpty(g) ...@@ -207,6 +212,7 @@ fid IsEmpty(g)
120 0 120 0
121 0 121 0
122 0 122 0
123 0
SELECT fid, AsText(Envelope(g)) FROM gis_geometry; SELECT fid, AsText(Envelope(g)) FROM gis_geometry;
fid AsText(Envelope(g)) fid AsText(Envelope(g))
101 POLYGON((10 10,10 10,10 10,10 10,10 10)) 101 POLYGON((10 10,10 10,10 10,10 10,10 10))
...@@ -231,9 +237,10 @@ fid AsText(Envelope(g)) ...@@ -231,9 +237,10 @@ fid AsText(Envelope(g))
120 POLYGON((0 0,10 0,10 10,0 10,0 0)) 120 POLYGON((0 0,10 0,10 10,0 10,0 0))
121 POLYGON((3 6,44 6,44 9,3 9,3 6)) 121 POLYGON((3 6,44 6,44 9,3 9,3 6))
122 NULL 122 NULL
123 NULL
explain extended select Dimension(g), GeometryType(g), IsEmpty(g), AsText(Envelope(g)) from gis_geometry; explain extended select Dimension(g), GeometryType(g), IsEmpty(g), AsText(Envelope(g)) from gis_geometry;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE gis_geometry ALL NULL NULL NULL NULL 22 100.00 1 SIMPLE gis_geometry ALL NULL NULL NULL NULL 23 100.00
Warnings: Warnings:
Note 1003 select st_dimension(`test`.`gis_geometry`.`g`) AS `Dimension(g)`,st_geometrytype(`test`.`gis_geometry`.`g`) AS `GeometryType(g)`,st_isempty(`test`.`gis_geometry`.`g`) AS `IsEmpty(g)`,st_astext(st_envelope(`test`.`gis_geometry`.`g`)) AS `AsText(Envelope(g))` from `test`.`gis_geometry` Note 1003 select st_dimension(`test`.`gis_geometry`.`g`) AS `Dimension(g)`,st_geometrytype(`test`.`gis_geometry`.`g`) AS `GeometryType(g)`,st_isempty(`test`.`gis_geometry`.`g`) AS `IsEmpty(g)`,st_astext(st_envelope(`test`.`gis_geometry`.`g`)) AS `AsText(Envelope(g))` from `test`.`gis_geometry`
SELECT fid, X(g) FROM gis_point; SELECT fid, X(g) FROM gis_point;
...@@ -353,6 +360,7 @@ fid NumGeometries(g) ...@@ -353,6 +360,7 @@ fid NumGeometries(g)
120 2 120 2
121 2 121 2
122 0 122 0
123 0
explain extended SELECT fid, NumGeometries(g) from gis_multi_point; explain extended SELECT fid, NumGeometries(g) from gis_multi_point;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE gis_multi_point ALL NULL NULL NULL NULL 3 100.00 1 SIMPLE gis_multi_point ALL NULL NULL NULL NULL 3 100.00
...@@ -378,11 +386,13 @@ fid AsText(GeometryN(g, 2)) ...@@ -378,11 +386,13 @@ fid AsText(GeometryN(g, 2))
120 LINESTRING(0 0,10 10) 120 LINESTRING(0 0,10 10)
121 LINESTRING(3 6,7 9) 121 LINESTRING(3 6,7 9)
122 NULL 122 NULL
123 NULL
SELECT fid, AsText(GeometryN(g, 1)) from gis_geometrycollection; SELECT fid, AsText(GeometryN(g, 1)) from gis_geometrycollection;
fid AsText(GeometryN(g, 1)) fid AsText(GeometryN(g, 1))
120 POINT(0 0) 120 POINT(0 0)
121 POINT(44 6) 121 POINT(44 6)
122 NULL 122 NULL
123 NULL
explain extended SELECT fid, AsText(GeometryN(g, 2)) from gis_multi_point; explain extended SELECT fid, AsText(GeometryN(g, 2)) from gis_multi_point;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE gis_multi_point ALL NULL NULL NULL NULL 3 100.00 1 SIMPLE gis_multi_point ALL NULL NULL NULL NULL 3 100.00
...@@ -397,20 +407,27 @@ first second w c o e d t i r ...@@ -397,20 +407,27 @@ first second w c o e d t i r
120 120 1 1 0 1 0 1 1 1 120 120 1 1 0 1 0 1 1 1
120 121 0 0 1 0 0 0 1 0 120 121 0 0 1 0 0 0 1 0
120 122 0 1 NULL NULL NULL 0 NULL 0 120 122 0 1 NULL NULL NULL 0 NULL 0
120 123 0 1 NULL NULL NULL 0 NULL 0
121 120 0 0 1 0 0 0 1 0 121 120 0 0 1 0 0 0 1 0
121 121 1 1 0 1 0 1 1 1 121 121 1 1 0 1 0 1 1 1
121 122 0 1 NULL NULL NULL 0 NULL 0 121 122 0 1 NULL NULL NULL 0 NULL 0
121 123 0 1 NULL NULL NULL 0 NULL 0
122 120 1 0 NULL NULL NULL 0 NULL 0 122 120 1 0 NULL NULL NULL 0 NULL 0
122 121 1 0 NULL NULL NULL 0 NULL 0 122 121 1 0 NULL NULL NULL 0 NULL 0
122 122 1 1 NULL NULL NULL 0 NULL 0 122 122 1 1 NULL NULL NULL 0 NULL 0
122 123 1 1 NULL NULL NULL 0 NULL 0
123 120 1 0 NULL NULL NULL 0 NULL 0
123 121 1 0 NULL NULL NULL 0 NULL 0
123 122 1 1 NULL NULL NULL 0 NULL 0
123 123 1 1 NULL NULL NULL 0 NULL 0
explain extended SELECT g1.fid as first, g2.fid as second, explain extended SELECT g1.fid as first, g2.fid as second,
Within(g1.g, g2.g) as w, Contains(g1.g, g2.g) as c, Overlaps(g1.g, g2.g) as o, Within(g1.g, g2.g) as w, Contains(g1.g, g2.g) as c, Overlaps(g1.g, g2.g) as o,
Equals(g1.g, g2.g) as e, Disjoint(g1.g, g2.g) as d, Touches(g1.g, g2.g) as t, Equals(g1.g, g2.g) as e, Disjoint(g1.g, g2.g) as d, Touches(g1.g, g2.g) as t,
Intersects(g1.g, g2.g) as i, Crosses(g1.g, g2.g) as r Intersects(g1.g, g2.g) as i, Crosses(g1.g, g2.g) as r
FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second; FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE g1 ALL NULL NULL NULL NULL 3 100.00 Using temporary; Using filesort 1 SIMPLE g1 ALL NULL NULL NULL NULL 4 100.00 Using temporary; Using filesort
1 SIMPLE g2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join) 1 SIMPLE g2 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (flat, BNL join)
Warnings: Warnings:
Note 1003 select `test`.`g1`.`fid` AS `first`,`test`.`g2`.`fid` AS `second`,st_within(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `w`,st_contains(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `c`,mbroverlaps(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `o`,mbrequals(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `e`,mbrdisjoint(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `d`,st_touches(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `t`,mbrintersects(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `i`,st_crosses(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `r` from `test`.`gis_geometrycollection` `g1` join `test`.`gis_geometrycollection` `g2` order by `test`.`g1`.`fid`,`test`.`g2`.`fid` Note 1003 select `test`.`g1`.`fid` AS `first`,`test`.`g2`.`fid` AS `second`,st_within(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `w`,st_contains(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `c`,mbroverlaps(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `o`,mbrequals(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `e`,mbrdisjoint(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `d`,st_touches(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `t`,mbrintersects(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `i`,st_crosses(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `r` from `test`.`gis_geometrycollection` `g1` join `test`.`gis_geometrycollection` `g2` order by `test`.`g1`.`fid`,`test`.`g2`.`fid`
DROP TABLE gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry; DROP TABLE gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry;
...@@ -850,7 +867,7 @@ mbroverlaps ...@@ -850,7 +867,7 @@ mbroverlaps
down,left,right,up down,left,right,up
SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrtouches FROM t1 a1 JOIN t1 a2 ON MBRTouches( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name; SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrtouches FROM t1 a1 JOIN t1 a2 ON MBRTouches( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
mbrtouches mbrtouches
down2,left2,right2,up2 big,down2,left,left2,right,right2,small,up2
SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrwithin FROM t1 a1 JOIN t1 a2 ON MBRWithin( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name; SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrwithin FROM t1 a1 JOIN t1 a2 ON MBRWithin( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
mbrwithin mbrwithin
big,center big,center
...@@ -871,7 +888,7 @@ overlaps ...@@ -871,7 +888,7 @@ overlaps
down,left,right,up down,left,right,up
SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS touches FROM t1 a1 JOIN t1 a2 ON Touches( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name; SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS touches FROM t1 a1 JOIN t1 a2 ON Touches( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
touches touches
down2,left2,right2,up2 big,down2,left,left2,right,right2,small,up2
SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS within FROM t1 a1 JOIN t1 a2 ON Within( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name; SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS within FROM t1 a1 JOIN t1 a2 ON Within( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
within within
big,center big,center
......
...@@ -63,7 +63,8 @@ INSERT INTO gis_multi_polygon VALUES ...@@ -63,7 +63,8 @@ INSERT INTO gis_multi_polygon VALUES
INSERT INTO gis_geometrycollection VALUES INSERT INTO gis_geometrycollection VALUES
(120, GeomCollFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))')), (120, GeomCollFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))')),
(121, GeometryFromWKB(AsWKB(GeometryCollection(Point(44, 6), LineString(Point(3, 6), Point(7, 9)))))), (121, GeometryFromWKB(AsWKB(GeometryCollection(Point(44, 6), LineString(Point(3, 6), Point(7, 9)))))),
(122, GeomFromText('GeometryCollection()')); (122, GeomFromText('GeometryCollection()')),
(123, GeomFromText('GeometryCollection EMPTY'));
INSERT into gis_geometry SELECT * FROM gis_point; INSERT into gis_geometry SELECT * FROM gis_point;
INSERT into gis_geometry SELECT * FROM gis_line; INSERT into gis_geometry SELECT * FROM gis_line;
......
...@@ -39,6 +39,29 @@ enum Gis_read_stream::enum_tok_types Gis_read_stream::get_next_toc_type() ...@@ -39,6 +39,29 @@ enum Gis_read_stream::enum_tok_types Gis_read_stream::get_next_toc_type()
} }
bool Gis_read_stream::lookup_next_word(LEX_STRING *res)
{
const char *cur= m_cur;
skip_space();
res->str= (char*) cur;
/* The following will also test for \0 */
if ((cur >= m_limit) || !my_isvar_start(&my_charset_bin, *cur))
return 1;
/*
We can't combine the following increment with my_isvar() because
my_isvar() is a macro that would cause side effects
*/
cur++;
while ((cur < m_limit) && my_isvar(&my_charset_bin, *cur))
cur++;
res->length= (uint32) (cur - res->str);
return 0;
}
bool Gis_read_stream::get_next_word(LEX_STRING *res) bool Gis_read_stream::get_next_word(LEX_STRING *res)
{ {
skip_space(); skip_space();
......
...@@ -39,6 +39,7 @@ public: ...@@ -39,6 +39,7 @@ public:
} }
enum enum_tok_types get_next_toc_type(); enum enum_tok_types get_next_toc_type();
bool lookup_next_word(LEX_STRING *res);
bool get_next_word(LEX_STRING *); bool get_next_word(LEX_STRING *);
bool get_next_number(double *); bool get_next_number(double *);
bool check_next_symbol(char); bool check_next_symbol(char);
......
...@@ -178,6 +178,7 @@ Geometry *Geometry::create_from_wkt(Geometry_buffer *buffer, ...@@ -178,6 +178,7 @@ Geometry *Geometry::create_from_wkt(Geometry_buffer *buffer,
{ {
LEX_STRING name; LEX_STRING name;
Class_info *ci; Class_info *ci;
char next_sym;
if (trs->get_next_word(&name)) if (trs->get_next_word(&name))
{ {
...@@ -190,9 +191,13 @@ Geometry *Geometry::create_from_wkt(Geometry_buffer *buffer, ...@@ -190,9 +191,13 @@ Geometry *Geometry::create_from_wkt(Geometry_buffer *buffer,
Geometry *result= (*ci->m_create_func)(buffer->data); Geometry *result= (*ci->m_create_func)(buffer->data);
wkt->q_append((char) wkb_ndr); wkt->q_append((char) wkb_ndr);
wkt->q_append((uint32) result->get_class_info()->m_type_id); wkt->q_append((uint32) result->get_class_info()->m_type_id);
if (trs->check_next_symbol('(') || if (!(next_sym= trs->next_symbol()))
return NULL;
if (!(next_sym= trs->next_symbol()))
return NULL;
if ((next_sym == '(' && trs->check_next_symbol('(')) ||
result->init_from_wkt(trs, wkt) || result->init_from_wkt(trs, wkt) ||
trs->check_next_symbol(')')) (next_sym == '(' && trs->check_next_symbol(')')))
return NULL; return NULL;
if (init_stream) if (init_stream)
{ {
...@@ -203,6 +208,22 @@ Geometry *Geometry::create_from_wkt(Geometry_buffer *buffer, ...@@ -203,6 +208,22 @@ Geometry *Geometry::create_from_wkt(Geometry_buffer *buffer,
} }
int Geometry::as_wkt(String *wkt, const char **end)
{
uint32 len= (uint) get_class_info()->m_name.length;
if (wkt->reserve(len + 2, 512))
return 1;
wkt->qs_append(get_class_info()->m_name.str, len);
if (get_class_info() != &geometrycollection_class)
wkt->qs_append('(');
if (get_data_as_wkt(wkt, end))
return 1;
if (get_class_info() != &geometrycollection_class)
wkt->qs_append(')');
return 0;
}
static double wkb_get_double(const char *ptr, Geometry::wkbByteOrder bo) static double wkb_get_double(const char *ptr, Geometry::wkbByteOrder bo)
{ {
double res; double res;
...@@ -2092,26 +2113,40 @@ bool Gis_geometry_collection::init_from_wkt(Gis_read_stream *trs, String *wkb) ...@@ -2092,26 +2113,40 @@ bool Gis_geometry_collection::init_from_wkt(Gis_read_stream *trs, String *wkb)
uint32 no_pos= wkb->length(); uint32 no_pos= wkb->length();
Geometry_buffer buffer; Geometry_buffer buffer;
Geometry *g; Geometry *g;
char next_sym;
if (wkb->reserve(4, 512)) if (wkb->reserve(4, 512))
return 1; return 1;
wkb->length(wkb->length()+4); // Reserve space for points wkb->length(wkb->length()+4); // Reserve space for points
if (trs->next_symbol() != ')') if (!(next_sym= trs->next_symbol()))
return 1;
if (next_sym != ')')
{ {
for (;;) LEX_STRING next_word;
{ if (trs->lookup_next_word(&next_word))
if (!(g= create_from_wkt(&buffer, trs, wkb))) return 1;
return 1;
if (g->get_class_info()->m_type_id == wkb_geometrycollection) if (next_word.length != 5 ||
(my_strnncoll(&my_charset_latin1,
(const uchar*) "empty", 5,
(const uchar*) next_word.str, 5) != 0))
{
for (;;)
{ {
trs->set_error_msg("Unexpected GEOMETRYCOLLECTION"); if (!(g= create_from_wkt(&buffer, trs, wkb)))
return 1; return 1;
if (g->get_class_info()->m_type_id == wkb_geometrycollection)
{
trs->set_error_msg("Unexpected GEOMETRYCOLLECTION");
return 1;
}
n_objects++;
if (trs->skip_char(',')) // Didn't find ','
break;
} }
n_objects++;
if (trs->skip_char(',')) // Didn't find ','
break;
} }
} }
...@@ -2219,6 +2254,13 @@ bool Gis_geometry_collection::get_data_as_wkt(String *txt, ...@@ -2219,6 +2254,13 @@ bool Gis_geometry_collection::get_data_as_wkt(String *txt,
n_objects= uint4korr(data); n_objects= uint4korr(data);
data+= 4; data+= 4;
if (n_objects == 0)
{
txt->append(STRING_WITH_LEN(" EMPTY"), 512);
goto exit;
}
txt->qs_append('(');
while (n_objects--) while (n_objects--)
{ {
uint32 wkb_type; uint32 wkb_type;
...@@ -2236,6 +2278,8 @@ bool Gis_geometry_collection::get_data_as_wkt(String *txt, ...@@ -2236,6 +2278,8 @@ bool Gis_geometry_collection::get_data_as_wkt(String *txt,
if (n_objects && txt->append(STRING_WITH_LEN(","), 512)) if (n_objects && txt->append(STRING_WITH_LEN(","), 512))
return 1; return 1;
} }
txt->qs_append(')');
exit:
*end= data; *end= data;
return 0; return 0;
} }
......
...@@ -286,18 +286,7 @@ public: ...@@ -286,18 +286,7 @@ public:
const char *wkb, uint32 len, String *res); const char *wkb, uint32 len, String *res);
static int create_from_opresult(Geometry_buffer *g_buf, static int create_from_opresult(Geometry_buffer *g_buf,
String *res, Gcalc_result_receiver &rr); String *res, Gcalc_result_receiver &rr);
int as_wkt(String *wkt, const char **end) int as_wkt(String *wkt, const char **end);
{
uint32 len= (uint) get_class_info()->m_name.length;
if (wkt->reserve(len + 2, 512))
return 1;
wkt->qs_append(get_class_info()->m_name.str, len);
wkt->qs_append('(');
if (get_data_as_wkt(wkt, end))
return 1;
wkt->qs_append(')');
return 0;
}
inline void set_data_ptr(const char *data, uint32 data_len) inline void set_data_ptr(const char *data, uint32 data_len)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment