[Commits] Rev 3663: MDEV-3819 missing constraints for spatial column types. in file:///home/hf/wmar/mdev-3819/

holyfoot at askmonty.org holyfoot at askmonty.org
Wed Feb 20 19:32:40 EET 2013


At file:///home/hf/wmar/mdev-3819/

------------------------------------------------------------
revno: 3663
revision-id: holyfoot at askmonty.org-20130220172419-j5sad8p7t3191kii
parent: vvaintroub at pcbsd-20130219224652-t84v8wepdqvhxfwb
committer: Alexey Botchkov <holyfoot at 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.
  
  per-file comments:
    mysql-test/r/gis-rtree.result
    mysql-test/r/gis.result
    mysql-test/t/gis-rtree.test
    mysql-test/t/gis.test
    sql/field.cc
    sql/share/errmsg-utf8.txt
-------------- next part --------------
=== modified file 'mysql-test/r/gis-rtree.result'
--- a/mysql-test/r/gis-rtree.result	2012-06-04 15:26:11 +0000
+++ b/mysql-test/r/gis-rtree.result	2013-02-20 17:24:19 +0000
@@ -758,7 +758,7 @@ SPATIAL KEY(g)
 INSERT INTO t1 (g) VALUES (GeomFromText('LineString(1 2, 2 3)')),(GeomFromText('LineString(1 2, 2 4)'));
 drop table t1;
 CREATE TABLE t1 (
-line LINESTRING NOT NULL,
+line GEOMETRY NOT NULL,
 kind ENUM('po', 'pp', 'rr', 'dr', 'rd', 'ts', 'cl') NOT NULL DEFAULT 'po',
 name VARCHAR(32),
 SPATIAL KEY (line)
@@ -1553,7 +1553,7 @@ End of 5.0 tests.
 # Bug #57323/11764487: myisam corruption with insert ignore 
 # and invalid spatial data
 #
-CREATE TABLE t1(a LINESTRING NOT NULL, b GEOMETRY NOT NULL,
+CREATE TABLE t1(a POINT NOT NULL, b GEOMETRY NOT NULL,
 SPATIAL KEY(a), SPATIAL KEY(b)) ENGINE=MyISAM;
 INSERT INTO t1 VALUES(GEOMFROMTEXT("point (0 0)"), GEOMFROMTEXT("point (1 1)"));
 INSERT IGNORE INTO t1 SET a=GEOMFROMTEXT("point (-6 0)"), b=GEOMFROMTEXT("error");

=== modified file 'mysql-test/r/gis.result'
--- a/mysql-test/r/gis.result	2012-09-05 21:14:33 +0000
+++ b/mysql-test/r/gis.result	2013-02-20 17:24:19 +0000
@@ -1047,7 +1047,7 @@ SET @a=0x0000000003000000010000000000000
 SET @a=POLYFROMWKB(@a);
 SET @a=0x00000000030000000000000000000000000000000000144000000000000014400000000000001840000000000000184000000000000014400000000000001440;
 SET @a=POLYFROMWKB(@a);
-create table t1(a polygon NOT NULL)engine=myisam;
+create table t1(a geometry NOT NULL)engine=myisam;
 insert into t1 values (geomfromtext("point(0 1)"));
 insert into t1 values (geomfromtext("point(1 0)"));
 select * from (select polygon(t1.a) as p from t1 order by t1.a) d;
@@ -1491,4 +1491,11 @@ SELECT 1 FROM g1 WHERE a >= ANY
 (SELECT 1 FROM g1 WHERE a = geomfromtext('') OR a) ;
 1
 DROP TABLE g1;
+#
+# MDEV-3819 missing constraints for spatial column types
+#
+create table t1 (pt point);
+insert into t1 values(Geomfromtext('POLYGON((1 1, 2 2, 2 1, 1 1))'));
+ERROR HY000: Unsuitable geometry type for the field
+drop table t1;
 End of 5.5 tests

=== modified file 'mysql-test/t/gis-rtree.test'
--- a/mysql-test/t/gis-rtree.test	2012-01-13 14:50:02 +0000
+++ b/mysql-test/t/gis-rtree.test	2013-02-20 17:24:19 +0000
@@ -120,7 +120,7 @@ INSERT INTO t1 (g) VALUES (GeomFromText(
 drop table t1;
 
 CREATE TABLE t1 (
-  line LINESTRING NOT NULL,
+  line GEOMETRY NOT NULL,
   kind ENUM('po', 'pp', 'rr', 'dr', 'rd', 'ts', 'cl') NOT NULL DEFAULT 'po',
   name VARCHAR(32),
 
@@ -935,7 +935,7 @@ DROP TABLE t1;
 --echo # and invalid spatial data
 --echo #
 
-CREATE TABLE t1(a LINESTRING NOT NULL, b GEOMETRY NOT NULL,
+CREATE TABLE t1(a POINT NOT NULL, b GEOMETRY NOT NULL,
   SPATIAL KEY(a), SPATIAL KEY(b)) ENGINE=MyISAM;
 INSERT INTO t1 VALUES(GEOMFROMTEXT("point (0 0)"), GEOMFROMTEXT("point (1 1)"));
 --error ER_CANT_CREATE_GEOMETRY_OBJECT

=== modified file 'mysql-test/t/gis.test'
--- a/mysql-test/t/gis.test	2012-09-05 21:14:33 +0000
+++ b/mysql-test/t/gis.test	2013-02-20 17:24:19 +0000
@@ -741,7 +741,7 @@ SET @a=POLYFROMWKB(@a);
 # Bug #57321    crashes and valgrind errors from spatial types
 #
 
-create table t1(a polygon NOT NULL)engine=myisam;
+create table t1(a geometry NOT NULL)engine=myisam;
 insert into t1 values (geomfromtext("point(0 1)"));
 insert into t1 values (geomfromtext("point(1 0)"));
 select * from (select polygon(t1.a) as p from t1 order by t1.a) d;
@@ -1358,4 +1358,13 @@ SELECT 1 FROM g1 WHERE a >= ANY
 
 DROP TABLE g1;
 
+--echo #
+--echo # MDEV-3819 missing constraints for spatial column types
+--echo #
+
+create table t1 (pt point);
+--error ER_WRONG_GEOMETRY_TYPE
+insert into t1 values(Geomfromtext('POLYGON((1 1, 2 2, 2 1, 1 1))'));
+drop table t1;
+
 --echo End of 5.5 tests

=== 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;
+
     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"



More information about the commits mailing list