Commit 57c08a6a authored by unknown's avatar unknown

Merge mysql.com:/home/ram/work/b26038/b26038.5.0

into  mysql.com:/home/ram/work/b26038/b26038.5.1


mysql-test/t/gis.test:
  Auto merged
sql/item_geofunc.cc:
  Auto merged
sql/item_geofunc.h:
  Auto merged
sql/spatial.cc:
  Auto merged
sql/spatial.h:
  Auto merged
mysql-test/include/gis_generic.inc:
  manual merge
mysql-test/r/archive_gis.result:
  manual merge
mysql-test/r/gis.result:
  manual merge
mysql-test/r/innodb_gis.result:
  manual merge
mysql-test/r/ndb_gis.result:
  manual merge
parents 71a25f2b d4272a16
...@@ -166,14 +166,14 @@ insert IGNORE into t1 (a) values ('Garbage'); ...@@ -166,14 +166,14 @@ insert IGNORE into t1 (a) values ('Garbage');
drop table t1; drop table t1;
create table t1 (pk integer primary key auto_increment, fl geometry); create table t1 (pk integer primary key auto_increment, fl geometry not null);
--error 1416 --error 1416
insert into t1 (fl) values (1); insert into t1 (fl) values (1);
--error 1416 --error 1416
insert into t1 (fl) values (1.11); insert into t1 (fl) values (1.11);
--error 1416 --error 1416
insert into t1 (fl) values ("qwerty"); insert into t1 (fl) values ("qwerty");
--error 1416 --error 1048
insert into t1 (fl) values (pointfromtext('point(1,1)')); insert into t1 (fl) values (pointfromtext('point(1,1)'));
drop table t1; drop table t1;
......
...@@ -450,7 +450,7 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ...@@ -450,7 +450,7 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert IGNORE into t1 (a) values ('Garbage'); insert IGNORE into t1 (a) values ('Garbage');
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
drop table t1; drop table t1;
create table t1 (pk integer primary key auto_increment, fl geometry); create table t1 (pk integer primary key auto_increment, fl geometry not null);
insert into t1 (fl) values (1); insert into t1 (fl) values (1);
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert into t1 (fl) values (1.11); insert into t1 (fl) values (1.11);
...@@ -458,5 +458,5 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ...@@ -458,5 +458,5 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert into t1 (fl) values ("qwerty"); insert into t1 (fl) values ("qwerty");
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert into t1 (fl) values (pointfromtext('point(1,1)')); insert into t1 (fl) values (pointfromtext('point(1,1)'));
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 23000: Column 'fl' cannot be null
drop table t1; drop table t1;
...@@ -578,7 +578,7 @@ create table t1 select GeomFromWKB(POINT(1,3)); ...@@ -578,7 +578,7 @@ create table t1 select GeomFromWKB(POINT(1,3));
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`GeomFromWKB(POINT(1,3))` geometry NOT NULL DEFAULT '' `GeomFromWKB(POINT(1,3))` geometry DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1; drop table t1;
CREATE TABLE `t1` (`object_id` bigint(20) unsigned NOT NULL default '0', `geo` CREATE TABLE `t1` (`object_id` bigint(20) unsigned NOT NULL default '0', `geo`
...@@ -657,7 +657,7 @@ t1 where object_id=85984; ...@@ -657,7 +657,7 @@ t1 where object_id=85984;
object_id geometrytype(geo) ISSIMPLE(GEO) ASTEXT(centroid(geo)) object_id geometrytype(geo) ISSIMPLE(GEO) ASTEXT(centroid(geo))
85984 MULTIPOLYGON 0 POINT(-114.87787186923 36.33101763469) 85984 MULTIPOLYGON 0 POINT(-114.87787186923 36.33101763469)
drop table t1; drop table t1;
create table t1 (fl geometry); create table t1 (fl geometry not null);
insert into t1 values (1); insert into t1 values (1);
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert into t1 values (1.11); insert into t1 values (1.11);
...@@ -665,7 +665,7 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ...@@ -665,7 +665,7 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert into t1 values ("qwerty"); insert into t1 values ("qwerty");
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert into t1 values (pointfromtext('point(1,1)')); insert into t1 values (pointfromtext('point(1,1)'));
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 23000: Column 'fl' cannot be null
drop table t1; drop table t1;
select (asWKT(geomfromwkb((0x000000000140240000000000004024000000000000)))); select (asWKT(geomfromwkb((0x000000000140240000000000004024000000000000))));
(asWKT(geomfromwkb((0x000000000140240000000000004024000000000000)))) (asWKT(geomfromwkb((0x000000000140240000000000004024000000000000))))
...@@ -689,6 +689,48 @@ load data infile '../std_data_ln/bad_gis_data.dat' into table t1; ...@@ -689,6 +689,48 @@ load data infile '../std_data_ln/bad_gis_data.dat' into table t1;
ERROR 22004: Column set to default value; NULL supplied to NOT NULL column 'b' at row 1 ERROR 22004: Column set to default value; NULL supplied to NOT NULL column 'b' at row 1
alter table t1 enable keys; alter table t1 enable keys;
drop table t1; drop table t1;
create table t1 (a int, b blob);
insert into t1 values (1, ''), (2, NULL), (3, '1');
select * from t1;
a b
1
2 NULL
3 1
select
geometryfromtext(b) IS NULL, geometryfromwkb(b) IS NULL, astext(b) IS NULL,
aswkb(b) IS NULL, geometrytype(b) IS NULL, centroid(b) IS NULL,
envelope(b) IS NULL, startpoint(b) IS NULL, endpoint(b) IS NULL,
exteriorring(b) IS NULL, pointn(b, 1) IS NULL, geometryn(b, 1) IS NULL,
interiorringn(b, 1) IS NULL, multipoint(b) IS NULL, isempty(b) IS NULL,
issimple(b) IS NULL, isclosed(b) IS NULL, dimension(b) IS NULL,
numgeometries(b) IS NULL, numinteriorrings(b) IS NULL, numpoints(b) IS NULL,
area(b) IS NULL, glength(b) IS NULL, srid(b) IS NULL, x(b) IS NULL,
y(b) IS NULL
from t1;
geometryfromtext(b) IS NULL geometryfromwkb(b) IS NULL astext(b) IS NULL aswkb(b) IS NULL geometrytype(b) IS NULL centroid(b) IS NULL envelope(b) IS NULL startpoint(b) IS NULL endpoint(b) IS NULL exteriorring(b) IS NULL pointn(b, 1) IS NULL geometryn(b, 1) IS NULL interiorringn(b, 1) IS NULL multipoint(b) IS NULL isempty(b) IS NULL issimple(b) IS NULL isclosed(b) IS NULL dimension(b) IS NULL numgeometries(b) IS NULL numinteriorrings(b) IS NULL numpoints(b) IS NULL area(b) IS NULL glength(b) IS NULL srid(b) IS NULL x(b) IS NULL y(b) IS NULL
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
select
within(b, b) IS NULL, contains(b, b) IS NULL, overlaps(b, b) IS NULL,
equals(b, b) IS NULL, disjoint(b, b) IS NULL, touches(b, b) IS NULL,
intersects(b, b) IS NULL, crosses(b, b) IS NULL
from t1;
within(b, b) IS NULL contains(b, b) IS NULL overlaps(b, b) IS NULL equals(b, b) IS NULL disjoint(b, b) IS NULL touches(b, b) IS NULL intersects(b, b) IS NULL crosses(b, b) IS NULL
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
select
point(b, b) IS NULL, linestring(b) IS NULL, polygon(b) IS NULL, multipoint(b) IS NULL,
multilinestring(b) IS NULL, multipolygon(b) IS NULL,
geometrycollection(b) IS NULL
from t1;
point(b, b) IS NULL linestring(b) IS NULL polygon(b) IS NULL multipoint(b) IS NULL multilinestring(b) IS NULL multipolygon(b) IS NULL geometrycollection(b) IS NULL
0 1 1 1 1 1 1
1 1 1 1 1 1 1
0 1 1 1 1 1 1
drop table t1;
End of 4.1 tests
create table t1 (s1 geometry not null,s2 char(100)); create table t1 (s1 geometry not null,s2 char(100));
create trigger t1_bu before update on t1 for each row set new.s1 = null; create trigger t1_bu before update on t1 for each row set new.s1 = null;
insert into t1 values (null,null); insert into t1 values (null,null);
...@@ -716,7 +758,7 @@ drop table t1; ...@@ -716,7 +758,7 @@ drop table t1;
create table t1 select GeomFromText('point(1 1)'); create table t1 select GeomFromText('point(1 1)');
desc t1; desc t1;
Field Type Null Key Default Extra Field Type Null Key Default Extra
GeomFromText('point(1 1)') geometry NO GeomFromText('point(1 1)') geometry YES NULL
drop table t1; drop table t1;
create table t1 (g geometry not null); create table t1 (g geometry not null);
insert into t1 values(default); insert into t1 values(default);
......
...@@ -450,7 +450,7 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ...@@ -450,7 +450,7 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert IGNORE into t1 (a) values ('Garbage'); insert IGNORE into t1 (a) values ('Garbage');
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
drop table t1; drop table t1;
create table t1 (pk integer primary key auto_increment, fl geometry); create table t1 (pk integer primary key auto_increment, fl geometry not null);
insert into t1 (fl) values (1); insert into t1 (fl) values (1);
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert into t1 (fl) values (1.11); insert into t1 (fl) values (1.11);
...@@ -458,7 +458,7 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ...@@ -458,7 +458,7 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert into t1 (fl) values ("qwerty"); insert into t1 (fl) values ("qwerty");
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert into t1 (fl) values (pointfromtext('point(1,1)')); insert into t1 (fl) values (pointfromtext('point(1,1)'));
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 23000: Column 'fl' cannot be null
drop table t1; drop table t1;
create table t1 (g geometry not null, spatial gk(g)) engine=innodb; create table t1 (g geometry not null, spatial gk(g)) engine=innodb;
ERROR HY000: The used table type doesn't support SPATIAL indexes ERROR HY000: The used table type doesn't support SPATIAL indexes
...@@ -450,7 +450,7 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ...@@ -450,7 +450,7 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert IGNORE into t1 (a) values ('Garbage'); insert IGNORE into t1 (a) values ('Garbage');
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
drop table t1; drop table t1;
create table t1 (pk integer primary key auto_increment, fl geometry); create table t1 (pk integer primary key auto_increment, fl geometry not null);
insert into t1 (fl) values (1); insert into t1 (fl) values (1);
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert into t1 (fl) values (1.11); insert into t1 (fl) values (1.11);
...@@ -458,7 +458,7 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ...@@ -458,7 +458,7 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert into t1 (fl) values ("qwerty"); insert into t1 (fl) values ("qwerty");
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert into t1 (fl) values (pointfromtext('point(1,1)')); insert into t1 (fl) values (pointfromtext('point(1,1)'));
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 23000: Column 'fl' cannot be null
drop table t1; drop table t1;
set engine_condition_pushdown = on; set engine_condition_pushdown = on;
DROP TABLE IF EXISTS t1, gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry; DROP TABLE IF EXISTS t1, gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry;
...@@ -912,7 +912,7 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ...@@ -912,7 +912,7 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert IGNORE into t1 (a) values ('Garbage'); insert IGNORE into t1 (a) values ('Garbage');
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
drop table t1; drop table t1;
create table t1 (pk integer primary key auto_increment, fl geometry); create table t1 (pk integer primary key auto_increment, fl geometry not null);
insert into t1 (fl) values (1); insert into t1 (fl) values (1);
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert into t1 (fl) values (1.11); insert into t1 (fl) values (1.11);
...@@ -920,5 +920,5 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ...@@ -920,5 +920,5 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert into t1 (fl) values ("qwerty"); insert into t1 (fl) values ("qwerty");
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert into t1 (fl) values (pointfromtext('point(1,1)')); insert into t1 (fl) values (pointfromtext('point(1,1)'));
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field ERROR 23000: Column 'fl' cannot be null
drop table t1; drop table t1;
...@@ -360,14 +360,14 @@ t1 where object_id=85984; ...@@ -360,14 +360,14 @@ t1 where object_id=85984;
drop table t1; drop table t1;
create table t1 (fl geometry); create table t1 (fl geometry not null);
--error 1416 --error 1416
insert into t1 values (1); insert into t1 values (1);
--error 1416 --error 1416
insert into t1 values (1.11); insert into t1 values (1.11);
--error 1416 --error 1416
insert into t1 values ("qwerty"); insert into t1 values ("qwerty");
--error 1416 --error 1048
insert into t1 values (pointfromtext('point(1,1)')); insert into t1 values (pointfromtext('point(1,1)'));
drop table t1; drop table t1;
...@@ -389,7 +389,41 @@ load data infile '../std_data_ln/bad_gis_data.dat' into table t1; ...@@ -389,7 +389,41 @@ load data infile '../std_data_ln/bad_gis_data.dat' into table t1;
alter table t1 enable keys; alter table t1 enable keys;
drop table t1; drop table t1;
# End of 4.1 tests #
# Bug #26038: is null and bad data
#
create table t1 (a int, b blob);
insert into t1 values (1, ''), (2, NULL), (3, '1');
select * from t1;
select
geometryfromtext(b) IS NULL, geometryfromwkb(b) IS NULL, astext(b) IS NULL,
aswkb(b) IS NULL, geometrytype(b) IS NULL, centroid(b) IS NULL,
envelope(b) IS NULL, startpoint(b) IS NULL, endpoint(b) IS NULL,
exteriorring(b) IS NULL, pointn(b, 1) IS NULL, geometryn(b, 1) IS NULL,
interiorringn(b, 1) IS NULL, multipoint(b) IS NULL, isempty(b) IS NULL,
issimple(b) IS NULL, isclosed(b) IS NULL, dimension(b) IS NULL,
numgeometries(b) IS NULL, numinteriorrings(b) IS NULL, numpoints(b) IS NULL,
area(b) IS NULL, glength(b) IS NULL, srid(b) IS NULL, x(b) IS NULL,
y(b) IS NULL
from t1;
select
within(b, b) IS NULL, contains(b, b) IS NULL, overlaps(b, b) IS NULL,
equals(b, b) IS NULL, disjoint(b, b) IS NULL, touches(b, b) IS NULL,
intersects(b, b) IS NULL, crosses(b, b) IS NULL
from t1;
select
point(b, b) IS NULL, linestring(b) IS NULL, polygon(b) IS NULL, multipoint(b) IS NULL,
multilinestring(b) IS NULL, multipolygon(b) IS NULL,
geometrycollection(b) IS NULL
from t1;
drop table t1;
--echo End of 4.1 tests
# #
# Bug #12281 (Geometry: crash in trigger) # Bug #12281 (Geometry: crash in trigger)
......
...@@ -38,6 +38,7 @@ void Item_geometry_func::fix_length_and_dec() ...@@ -38,6 +38,7 @@ void Item_geometry_func::fix_length_and_dec()
collation.set(&my_charset_bin); collation.set(&my_charset_bin);
decimals=0; decimals=0;
max_length=MAX_BLOB_WIDTH; max_length=MAX_BLOB_WIDTH;
maybe_null= 1;
} }
int Item_geometry_func::get_geometry_type() const int Item_geometry_func::get_geometry_type() const
...@@ -66,11 +67,8 @@ String *Item_func_geometry_from_text::val_str(String *str) ...@@ -66,11 +67,8 @@ String *Item_func_geometry_from_text::val_str(String *str)
return 0; return 0;
str->length(0); str->length(0);
str->q_append(srid); str->q_append(srid);
if (!Geometry::create_from_wkt(&buffer, &trs, str, 0)) if ((null_value= !Geometry::create_from_wkt(&buffer, &trs, str, 0)))
/* We shouldn't return NULL here as NULL is a legal spatial object */ return 0;
/* Geometry::bad_spatial_data will produce error message beeing stored*/
/* in GEOMETRY field */
return &Geometry::bad_geometry_data;
return str; return str;
} }
...@@ -124,6 +122,7 @@ String *Item_func_as_wkt::val_str(String *str) ...@@ -124,6 +122,7 @@ String *Item_func_as_wkt::val_str(String *str)
void Item_func_as_wkt::fix_length_and_dec() void Item_func_as_wkt::fix_length_and_dec()
{ {
max_length=MAX_BLOB_WIDTH; max_length=MAX_BLOB_WIDTH;
maybe_null= 1;
} }
...@@ -389,7 +388,8 @@ String *Item_func_spatial_collection::val_str(String *str) ...@@ -389,7 +388,8 @@ String *Item_func_spatial_collection::val_str(String *str)
for (i= 0; i < arg_count; ++i) for (i= 0; i < arg_count; ++i)
{ {
String *res= args[i]->val_str(&arg_value); String *res= args[i]->val_str(&arg_value);
if (args[i]->null_value) uint32 len;
if (args[i]->null_value || ((len= res->length()) < WKB_HEADER_SIZE))
goto err; goto err;
if (coll_type == Geometry::wkb_geometrycollection) if (coll_type == Geometry::wkb_geometrycollection)
...@@ -398,13 +398,12 @@ String *Item_func_spatial_collection::val_str(String *str) ...@@ -398,13 +398,12 @@ String *Item_func_spatial_collection::val_str(String *str)
In the case of GeometryCollection we don't need any checkings In the case of GeometryCollection we don't need any checkings
for item types, so just copy them into target collection for item types, so just copy them into target collection
*/ */
if (str->append(res->ptr(), res->length(), (uint32) 512)) if (str->append(res->ptr(), len, (uint32) 512))
goto err; goto err;
} }
else else
{ {
enum Geometry::wkbType wkb_type; enum Geometry::wkbType wkb_type;
uint32 len=res->length();
const char *data= res->ptr() + 1; const char *data= res->ptr() + 1;
/* /*
...@@ -412,8 +411,6 @@ String *Item_func_spatial_collection::val_str(String *str) ...@@ -412,8 +411,6 @@ String *Item_func_spatial_collection::val_str(String *str)
are of specific type, let's do this checking now are of specific type, let's do this checking now
*/ */
if (len < 5)
goto err;
wkb_type= (Geometry::wkbType) uint4korr(data); wkb_type= (Geometry::wkbType) uint4korr(data);
data+= 4; data+= 4;
len-= 5; len-= 5;
...@@ -535,9 +532,13 @@ longlong Item_func_spatial_rel::val_int() ...@@ -535,9 +532,13 @@ longlong Item_func_spatial_rel::val_int()
longlong Item_func_isempty::val_int() longlong Item_func_isempty::val_int()
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
String tmp; String tmp;
null_value=0; String *swkb= args[0]->val_str(&tmp);
return args[0]->null_value ? 1 : 0; Geometry_buffer buffer;
null_value= args[0]->null_value ||
!(Geometry::construct(&buffer, swkb->ptr(), swkb->length()));
return null_value ? 1 : 0;
} }
...@@ -545,10 +546,11 @@ longlong Item_func_issimple::val_int() ...@@ -545,10 +546,11 @@ longlong Item_func_issimple::val_int()
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
String tmp; String tmp;
String *wkb=args[0]->val_str(&tmp); String *swkb= args[0]->val_str(&tmp);
Geometry_buffer buffer;
if ((null_value= (!wkb || args[0]->null_value)))
return 0; null_value= args[0]->null_value ||
!(Geometry::construct(&buffer, swkb->ptr(), swkb->length()));
/* TODO: Ramil or Holyfoot, add real IsSimple calculation */ /* TODO: Ramil or Holyfoot, add real IsSimple calculation */
return 0; return 0;
} }
......
...@@ -34,6 +34,7 @@ class Item_geometry_func: public Item_str_func ...@@ -34,6 +34,7 @@ class Item_geometry_func: public Item_str_func
enum_field_types field_type() const { return MYSQL_TYPE_GEOMETRY; } enum_field_types field_type() const { return MYSQL_TYPE_GEOMETRY; }
Field *tmp_table_field(TABLE *t_arg); Field *tmp_table_field(TABLE *t_arg);
virtual int get_geometry_type() const; virtual int get_geometry_type() const;
bool is_null() { (void) val_int(); return null_value; }
}; };
class Item_func_geometry_from_text: public Item_geometry_func class Item_func_geometry_from_text: public Item_geometry_func
...@@ -81,6 +82,7 @@ class Item_func_geometry_type: public Item_str_func ...@@ -81,6 +82,7 @@ class Item_func_geometry_type: public Item_str_func
void fix_length_and_dec() void fix_length_and_dec()
{ {
max_length=20; // "GeometryCollection" is the most long max_length=20; // "GeometryCollection" is the most long
maybe_null= 1;
}; };
}; };
...@@ -225,6 +227,8 @@ class Item_func_spatial_rel: public Item_bool_func2 ...@@ -225,6 +227,8 @@ class Item_func_spatial_rel: public Item_bool_func2
} }
} }
void print(String *str) { Item_func::print(str); } void print(String *str) { Item_func::print(str); }
void fix_length_and_dec() { maybe_null= 1; }
bool is_null() { (void) val_int(); return null_value; }
}; };
class Item_func_isempty: public Item_bool_func class Item_func_isempty: public Item_bool_func
...@@ -234,6 +238,7 @@ class Item_func_isempty: public Item_bool_func ...@@ -234,6 +238,7 @@ class Item_func_isempty: public Item_bool_func
longlong val_int(); longlong val_int();
optimize_type select_optimize() const { return OPTIMIZE_NONE; } optimize_type select_optimize() const { return OPTIMIZE_NONE; }
const char *func_name() const { return "isempty"; } const char *func_name() const { return "isempty"; }
void fix_length_and_dec() { maybe_null= 1; }
}; };
class Item_func_issimple: public Item_bool_func class Item_func_issimple: public Item_bool_func
...@@ -243,6 +248,7 @@ class Item_func_issimple: public Item_bool_func ...@@ -243,6 +248,7 @@ class Item_func_issimple: public Item_bool_func
longlong val_int(); longlong val_int();
optimize_type select_optimize() const { return OPTIMIZE_NONE; } optimize_type select_optimize() const { return OPTIMIZE_NONE; }
const char *func_name() const { return "issimple"; } const char *func_name() const { return "issimple"; }
void fix_length_and_dec() { maybe_null= 1; }
}; };
class Item_func_isclosed: public Item_bool_func class Item_func_isclosed: public Item_bool_func
...@@ -252,6 +258,7 @@ class Item_func_isclosed: public Item_bool_func ...@@ -252,6 +258,7 @@ class Item_func_isclosed: public Item_bool_func
longlong val_int(); longlong val_int();
optimize_type select_optimize() const { return OPTIMIZE_NONE; } optimize_type select_optimize() const { return OPTIMIZE_NONE; }
const char *func_name() const { return "isclosed"; } const char *func_name() const { return "isclosed"; }
void fix_length_and_dec() { maybe_null= 1; }
}; };
class Item_func_dimension: public Item_int_func class Item_func_dimension: public Item_int_func
...@@ -261,7 +268,7 @@ class Item_func_dimension: public Item_int_func ...@@ -261,7 +268,7 @@ class Item_func_dimension: public Item_int_func
Item_func_dimension(Item *a): Item_int_func(a) {} Item_func_dimension(Item *a): Item_int_func(a) {}
longlong val_int(); longlong val_int();
const char *func_name() const { return "dimension"; } const char *func_name() const { return "dimension"; }
void fix_length_and_dec() { max_length=10; } void fix_length_and_dec() { max_length= 10; maybe_null= 1; }
}; };
class Item_func_x: public Item_real_func class Item_func_x: public Item_real_func
...@@ -271,6 +278,11 @@ class Item_func_x: public Item_real_func ...@@ -271,6 +278,11 @@ class Item_func_x: public Item_real_func
Item_func_x(Item *a): Item_real_func(a) {} Item_func_x(Item *a): Item_real_func(a) {}
double val_real(); double val_real();
const char *func_name() const { return "x"; } const char *func_name() const { return "x"; }
void fix_length_and_dec()
{
Item_real_func::fix_length_and_dec();
maybe_null= 1;
}
}; };
...@@ -281,6 +293,11 @@ class Item_func_y: public Item_real_func ...@@ -281,6 +293,11 @@ class Item_func_y: public Item_real_func
Item_func_y(Item *a): Item_real_func(a) {} Item_func_y(Item *a): Item_real_func(a) {}
double val_real(); double val_real();
const char *func_name() const { return "y"; } const char *func_name() const { return "y"; }
void fix_length_and_dec()
{
Item_real_func::fix_length_and_dec();
maybe_null= 1;
}
}; };
...@@ -291,7 +308,7 @@ class Item_func_numgeometries: public Item_int_func ...@@ -291,7 +308,7 @@ class Item_func_numgeometries: public Item_int_func
Item_func_numgeometries(Item *a): Item_int_func(a) {} Item_func_numgeometries(Item *a): Item_int_func(a) {}
longlong val_int(); longlong val_int();
const char *func_name() const { return "numgeometries"; } const char *func_name() const { return "numgeometries"; }
void fix_length_and_dec() { max_length=10; } void fix_length_and_dec() { max_length= 10; maybe_null= 1; }
}; };
...@@ -302,7 +319,7 @@ class Item_func_numinteriorring: public Item_int_func ...@@ -302,7 +319,7 @@ class Item_func_numinteriorring: public Item_int_func
Item_func_numinteriorring(Item *a): Item_int_func(a) {} Item_func_numinteriorring(Item *a): Item_int_func(a) {}
longlong val_int(); longlong val_int();
const char *func_name() const { return "numinteriorrings"; } const char *func_name() const { return "numinteriorrings"; }
void fix_length_and_dec() { max_length=10; } void fix_length_and_dec() { max_length= 10; maybe_null= 1; }
}; };
...@@ -313,7 +330,7 @@ class Item_func_numpoints: public Item_int_func ...@@ -313,7 +330,7 @@ class Item_func_numpoints: public Item_int_func
Item_func_numpoints(Item *a): Item_int_func(a) {} Item_func_numpoints(Item *a): Item_int_func(a) {}
longlong val_int(); longlong val_int();
const char *func_name() const { return "numpoints"; } const char *func_name() const { return "numpoints"; }
void fix_length_and_dec() { max_length=10; } void fix_length_and_dec() { max_length= 10; maybe_null= 1; }
}; };
...@@ -324,6 +341,11 @@ class Item_func_area: public Item_real_func ...@@ -324,6 +341,11 @@ class Item_func_area: public Item_real_func
Item_func_area(Item *a): Item_real_func(a) {} Item_func_area(Item *a): Item_real_func(a) {}
double val_real(); double val_real();
const char *func_name() const { return "area"; } const char *func_name() const { return "area"; }
void fix_length_and_dec()
{
Item_real_func::fix_length_and_dec();
maybe_null= 1;
}
}; };
...@@ -334,6 +356,11 @@ class Item_func_glength: public Item_real_func ...@@ -334,6 +356,11 @@ class Item_func_glength: public Item_real_func
Item_func_glength(Item *a): Item_real_func(a) {} Item_func_glength(Item *a): Item_real_func(a) {}
double val_real(); double val_real();
const char *func_name() const { return "glength"; } const char *func_name() const { return "glength"; }
void fix_length_and_dec()
{
Item_real_func::fix_length_and_dec();
maybe_null= 1;
}
}; };
...@@ -344,7 +371,7 @@ class Item_func_srid: public Item_int_func ...@@ -344,7 +371,7 @@ class Item_func_srid: public Item_int_func
Item_func_srid(Item *a): Item_int_func(a) {} Item_func_srid(Item *a): Item_int_func(a) {}
longlong val_int(); longlong val_int();
const char *func_name() const { return "srid"; } const char *func_name() const { return "srid"; }
void fix_length_and_dec() { max_length= 10; } void fix_length_and_dec() { max_length= 10; maybe_null= 1; }
}; };
#define GEOM_NEW(thd, obj_constructor) new (thd->mem_root) obj_constructor #define GEOM_NEW(thd, obj_constructor) new (thd->mem_root) obj_constructor
......
...@@ -216,23 +216,24 @@ static uint32 wkb_get_uint(const char *ptr, Geometry::wkbByteOrder bo) ...@@ -216,23 +216,24 @@ static uint32 wkb_get_uint(const char *ptr, Geometry::wkbByteOrder bo)
} }
int Geometry::create_from_wkb(Geometry_buffer *buffer, Geometry *Geometry::create_from_wkb(Geometry_buffer *buffer,
const char *wkb, uint32 len, String *res) const char *wkb, uint32 len, String *res)
{ {
uint32 geom_type; uint32 geom_type;
Geometry *geom; Geometry *geom;
if (len < WKB_HEADER_SIZE) if (len < WKB_HEADER_SIZE)
return 1; return NULL;
geom_type= wkb_get_uint(wkb+1, (wkbByteOrder)wkb[0]); geom_type= wkb_get_uint(wkb+1, (wkbByteOrder)wkb[0]);
if (!(geom= create_by_typeid(buffer, (int) geom_type)) || if (!(geom= create_by_typeid(buffer, (int) geom_type)) ||
res->reserve(WKB_HEADER_SIZE, 512)) res->reserve(WKB_HEADER_SIZE, 512))
return 1; return NULL;
res->q_append((char) wkb_ndr); res->q_append((char) wkb_ndr);
res->q_append(geom_type); res->q_append(geom_type);
return geom->init_from_wkb(wkb+WKB_HEADER_SIZE, len - WKB_HEADER_SIZE,
(wkbByteOrder) wkb[0], res); return geom->init_from_wkb(wkb + WKB_HEADER_SIZE, len - WKB_HEADER_SIZE,
(wkbByteOrder) wkb[0], res) ? geom : NULL;
} }
......
...@@ -246,8 +246,8 @@ class Geometry ...@@ -246,8 +246,8 @@ class Geometry
static Geometry *create_from_wkt(Geometry_buffer *buffer, static Geometry *create_from_wkt(Geometry_buffer *buffer,
Gis_read_stream *trs, String *wkt, Gis_read_stream *trs, String *wkt,
bool init_stream=1); bool init_stream=1);
static int create_from_wkb(Geometry_buffer *buffer, static Geometry *create_from_wkb(Geometry_buffer *buffer, const char *wkb,
const char *wkb, uint32 len, String *res); uint32 len, String *res);
int as_wkt(String *wkt, const char **end) int as_wkt(String *wkt, const char **end)
{ {
uint32 len= get_class_info()->m_name.length; uint32 len= get_class_info()->m_name.length;
......
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