From cbb38476e19e8c5582d7d14ce98a8889132110d4 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 21 Feb 2007 14:45:19 +0400 Subject: Fix for bug #26038: X() value of empty NOT NULL POINT is neither NULL nor NOT NULL Having maybe_null flag unset for geometry/spatial functions leads to wrong Item_func_isnull::val_int()'s results. Fix: set maybe_null flag and add is_null() methods. mysql-test/r/gis.result: Fix for bug #26038: X() value of empty NOT NULL POINT is neither NULL nor NOT NULL - test result. mysql-test/t/gis.test: Fix for bug #26038: X() value of empty NOT NULL POINT is neither NULL nor NOT NULL - test case. sql/item_geofunc.cc: Fix for bug #26038: X() value of empty NOT NULL POINT is neither NULL nor NOT NULL - set maybe_null flag for Item_geometry_func and Item_func_as_wkt. - moved length check to the beginnig of the Item_func_spatial_collection::val_str() to affect geometry collection objects at once. - changed Item_func_isempty::val_int() and Item_func_issimple::val_int() to properly handle null_value. sql/item_geofunc.h: Fix for bug #26038: X() value of empty NOT NULL POINT is neither NULL nor NOT NULL - set maybe_null flag for geometry/spatial functions. - added is_null() to Item_geometry_func and Item_func_spatial_rel classes. sql/spatial.cc: Fix for bug #26038: X() value of empty NOT NULL POINT is neither NULL nor NOT NULL - changed return type of Geometry::create_from_wkb() to be consistent with Geometry::create_from_wkt(), now it returns Geometry object or NULL in case of error. sql/spatial.h: Fix for bug #26038: X() value of empty NOT NULL POINT is neither NULL nor NOT NULL - changed return type of Geometry::create_from_wkb() to be consistent with Geometry::create_from_wkt(), now it returns Geometry object or NULL in case of error. --- sql/item_geofunc.cc | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'sql/item_geofunc.cc') diff --git a/sql/item_geofunc.cc b/sql/item_geofunc.cc index 6bd2e65632f..6cb8c790319 100644 --- a/sql/item_geofunc.cc +++ b/sql/item_geofunc.cc @@ -30,6 +30,7 @@ void Item_geometry_func::fix_length_and_dec() collation.set(&my_charset_bin); decimals=0; max_length=MAX_BLOB_WIDTH; + maybe_null= 1; } @@ -109,6 +110,7 @@ String *Item_func_as_wkt::val_str(String *str) void Item_func_as_wkt::fix_length_and_dec() { max_length=MAX_BLOB_WIDTH; + maybe_null= 1; } @@ -356,7 +358,8 @@ String *Item_func_spatial_collection::val_str(String *str) for (i= 0; i < arg_count; ++i) { 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; if (coll_type == Geometry::wkb_geometrycollection) @@ -365,13 +368,12 @@ String *Item_func_spatial_collection::val_str(String *str) In the case of GeometryCollection we don't need any checkings 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; } else { enum Geometry::wkbType wkb_type; - uint32 len=res->length(); const char *data= res->ptr() + 1; /* @@ -379,8 +381,6 @@ String *Item_func_spatial_collection::val_str(String *str) are of specific type, let's do this checking now */ - if (len < 5) - goto err; wkb_type= (Geometry::wkbType) uint4korr(data); data+= 4; len-= 5; @@ -502,9 +502,13 @@ longlong Item_func_spatial_rel::val_int() longlong Item_func_isempty::val_int() { DBUG_ASSERT(fixed == 1); - String tmp; - null_value=0; - return args[0]->null_value ? 1 : 0; + String tmp; + String *swkb= args[0]->val_str(&tmp); + Geometry_buffer buffer; + + null_value= args[0]->null_value || + !(Geometry::construct(&buffer, swkb->ptr(), swkb->length())); + return null_value ? 1 : 0; } @@ -512,10 +516,11 @@ longlong Item_func_issimple::val_int() { DBUG_ASSERT(fixed == 1); String tmp; - String *wkb=args[0]->val_str(&tmp); - - if ((null_value= (!wkb || args[0]->null_value))) - return 0; + String *swkb= args[0]->val_str(&tmp); + Geometry_buffer buffer; + + null_value= args[0]->null_value || + !(Geometry::construct(&buffer, swkb->ptr(), swkb->length())); /* TODO: Ramil or Holyfoot, add real IsSimple calculation */ return 0; } -- cgit v1.2.1 From d4272a16deb9aa1b2428e446b2321697aebf9d94 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 2 Mar 2007 15:09:44 +0400 Subject: after merge fix (bug #26038) Item_func_geometry_from_text::val_str() should set null_value in case of wrong data. mysql-test/include/gis_generic.inc: after merge fix Item_func_geometry_from_text::val_str() should set null_value in case of wrong data. mysql-test/r/archive_gis.result: after merge fix Item_func_geometry_from_text::val_str() should set null_value in case of wrong data. mysql-test/r/gis.result: after merge fix Item_func_geometry_from_text::val_str() should set null_value in case of wrong data. mysql-test/r/innodb_gis.result: after merge fix Item_func_geometry_from_text::val_str() should set null_value in case of wrong data. mysql-test/r/ndb_gis.result: after merge fix Item_func_geometry_from_text::val_str() should set null_value in case of wrong data. mysql-test/t/gis.test: after merge fix Item_func_geometry_from_text::val_str() should set null_value in case of wrong data. sql/item_geofunc.cc: after merge fix Item_func_geometry_from_text::val_str() should set null_value in case of wrong data. --- sql/item_geofunc.cc | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'sql/item_geofunc.cc') diff --git a/sql/item_geofunc.cc b/sql/item_geofunc.cc index 955ba0ef67a..11cb8ad935b 100644 --- a/sql/item_geofunc.cc +++ b/sql/item_geofunc.cc @@ -64,11 +64,8 @@ String *Item_func_geometry_from_text::val_str(String *str) return 0; str->length(0); str->q_append(srid); - if (!Geometry::create_from_wkt(&buffer, &trs, str, 0)) - /* We shouldn't return NULL here as NULL is a legal spatial object */ - /* Geometry::bad_spatial_data will produce error message beeing stored*/ - /* in GEOMETRY field */ - return &Geometry::bad_geometry_data; + if ((null_value= !Geometry::create_from_wkt(&buffer, &trs, str, 0))) + return 0; return str; } -- cgit v1.2.1