diff options
-rw-r--r-- | mysql-test/r/gis.result | 11 | ||||
-rw-r--r-- | mysql-test/t/gis.test | 11 | ||||
-rw-r--r-- | sql/item.cc | 5 | ||||
-rw-r--r-- | sql/sql_select.cc | 6 |
4 files changed, 29 insertions, 4 deletions
diff --git a/mysql-test/r/gis.result b/mysql-test/r/gis.result index 58149d68ca3..749c84a1a6f 100644 --- a/mysql-test/r/gis.result +++ b/mysql-test/r/gis.result @@ -769,3 +769,14 @@ create table t1 (g geometry not null); insert into t1 values(default); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field drop table t1; +CREATE TABLE t1 (a GEOMETRY); +CREATE VIEW v1 AS SELECT GeomFromwkb(ASBINARY(a)) FROM t1; +CREATE VIEW v2 AS SELECT a FROM t1; +DESCRIBE v1; +Field Type Null Key Default Extra +GeomFromwkb(ASBINARY(a)) geometry YES NULL +DESCRIBE v2; +Field Type Null Key Default Extra +a geometry YES NULL +DROP VIEW v1,v2; +DROP TABLE t1; diff --git a/mysql-test/t/gis.test b/mysql-test/t/gis.test index d92ff804ccb..4f6104aab3e 100644 --- a/mysql-test/t/gis.test +++ b/mysql-test/t/gis.test @@ -479,3 +479,14 @@ create table t1 (g geometry not null); insert into t1 values(default); drop table t1; +# +# Bug #27300: create view with geometry functions lost columns types +# +CREATE TABLE t1 (a GEOMETRY); +CREATE VIEW v1 AS SELECT GeomFromwkb(ASBINARY(a)) FROM t1; +CREATE VIEW v2 AS SELECT a FROM t1; +DESCRIBE v1; +DESCRIBE v2; + +DROP VIEW v1,v2; +DROP TABLE t1; diff --git a/sql/item.cc b/sql/item.cc index 808e7925729..8568a44c547 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -4275,7 +4275,6 @@ Field *Item::tmp_table_field_from_field_type(TABLE *table) case MYSQL_TYPE_MEDIUM_BLOB: case MYSQL_TYPE_LONG_BLOB: case MYSQL_TYPE_BLOB: - case MYSQL_TYPE_GEOMETRY: if (this->type() == Item::TYPE_HOLDER) return new Field_blob(max_length, maybe_null, name, table, collation.collation, 1); @@ -4283,6 +4282,10 @@ Field *Item::tmp_table_field_from_field_type(TABLE *table) return new Field_blob(max_length, maybe_null, name, table, collation.collation); break; // Blob handled outside of case + case MYSQL_TYPE_GEOMETRY: + return new Field_geom(max_length, maybe_null, name, table, + (Field::geometry_type) + ((Item_geometry_func *)this)->get_geometry_type()); } } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index bb57764700d..d983146da93 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -8793,12 +8793,12 @@ static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table, enum enum_field_types type; /* - DATE/TIME fields have STRING_RESULT result type. To preserve - type they needed to be handled separately. + DATE/TIME and GEOMETRY fields have STRING_RESULT result type. + To preserve type they needed to be handled separately. */ if ((type= item->field_type()) == MYSQL_TYPE_DATETIME || type == MYSQL_TYPE_TIME || type == MYSQL_TYPE_DATE || - type == MYSQL_TYPE_TIMESTAMP) + type == MYSQL_TYPE_TIMESTAMP || type == MYSQL_TYPE_GEOMETRY) new_field= item->tmp_table_field_from_field_type(table); /* Make sure that the blob fits into a Field_varstring which has |