Hi, Holyfoot! On Feb 20, holyfoot@askmonty.org wrote:
revno: 3663 revision-id: holyfoot@askmonty.org-20130220172419-j5sad8p7t3191kii parent: vvaintroub@pcbsd-20130219224652-t84v8wepdqvhxfwb committer: Alexey Botchkov <holyfoot@askmonty.org> branch nick: mdev-3819 timestamp: Wed 2013-02-20 21:24:19 +0400 message: MDEV-3819 missing constraints for spatial column types. Checks added to return and error when inappropriate geometry type is stored in a field.
=== modified file 'sql/field.cc' --- a/sql/field.cc 2013-01-28 12:36:05 +0000 +++ b/sql/field.cc 2013-02-20 17:24:19 +0000 @@ -7580,6 +7580,12 @@ int Field_geom::store(const char *from, if (wkb_type < (uint32) Geometry::wkb_point || wkb_type > (uint32) Geometry::wkb_last) goto err; + + if (geom_type != Field::GEOM_GEOMETRY && + geom_type != Field::GEOM_GEOMETRYCOLLECTION && + (uint32) geom_type != wkb_type) + goto err_wrong_type;
why goto err_wrong_type? there's no common cleanup or any common code at all at the end, you can put it right here in the if().
+ Field_blob::store_length(length); if (table->copy_blobs || length <= MAX_FIELD_WIDTH) { // Must make a copy @@ -7595,6 +7601,12 @@ int Field_geom::store(const char *from, my_message(ER_CANT_CREATE_GEOMETRY_OBJECT, ER(ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0)); return -1; + +err_wrong_type: + bzero(ptr, Field_blob::pack_length()); + my_message(ER_WRONG_GEOMETRY_TYPE, + ER(ER_WRONG_GEOMETRY_TYPE), MYF(0)); + return -1; }
#endif /*HAVE_SPATIAL*/
=== modified file 'sql/share/errmsg-utf8.txt' --- a/sql/share/errmsg-utf8.txt 2013-02-08 21:24:06 +0000 +++ b/sql/share/errmsg-utf8.txt 2013-02-20 17:24:19 +0000 @@ -6588,3 +6588,5 @@ ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT ER_NO_SUCH_TABLE_IN_ENGINE 42S02 eng "Table '%-.192s.%-.192s' doesn't exist in engine" swe "Det finns ingen tabell som heter '%-.192s.%-.192s' i handlern" +ER_WRONG_GEOMETRY_TYPE + eng "Unsuitable geometry type for the field"
Ouch, is that really needed? Can you use ER_WRONG_VALUE instead? Like Incorrect POINT value: 'POLYGON((1 1, 2 2, 2 1, 1 1))' Regards, Sergei