Skip to content

Commit

Permalink
MDEV-27666 User variable not parsed as geometry variable in geometry …
Browse files Browse the repository at this point in the history
…function

Adding GEOMETRY type user variables.
  • Loading branch information
abarkov committed Jan 16, 2024
1 parent caad34d commit fa3171d
Show file tree
Hide file tree
Showing 23 changed files with 509 additions and 118 deletions.
107 changes: 107 additions & 0 deletions mysql-test/main/gis.result
Expand Up @@ -5328,5 +5328,112 @@ SELECT BIT_XOR(a) FROM t1;
ERROR HY000: Illegal parameter data type geometry for operation 'bit_xor('
DROP TABLE t1;
#
# MDEV-27666 User variable not parsed as geometry variable in geometry function.
#
set @g= point(1, 1);
select ST_AsWKT(GeometryCollection(Point(44, 6), @g));
ST_AsWKT(GeometryCollection(Point(44, 6), @g))
GEOMETRYCOLLECTION(POINT(44 6),POINT(1 1))
set @g= "just a string";
select ST_AsWKT(GeometryCollection(Point(44, 6), @g));
ERROR HY000: Illegal parameter data type longblob for operation 'geometrycollection'
SET @g= LineString(Point(0,0), Point(0,1));
SELECT AsText(PointN(@g, 1));
AsText(PointN(@g, 1))
POINT(0 0)
SELECT AsText(PointN(@g, 2));
AsText(PointN(@g, 2))
POINT(0 1)
SET @g= Point(1, 1);
CREATE TABLE t1 AS SELECT @g AS g;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`g` point DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT AsText(g) FROM t1;
AsText(g)
POINT(1 1)
DROP TABLE t1;
SET @g= MultiPoint(Point(1, 1), Point(-1,-1));
CREATE TABLE t1 AS SELECT @g AS g;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`g` multipoint DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT AsText(g) FROM t1;
AsText(g)
MULTIPOINT(1 1,-1 -1)
DROP TABLE t1;
SET @g= LineString(Point(1, 1), Point(2,2));
CREATE TABLE t1 AS SELECT @g AS g;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`g` linestring DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT AsText(g) FROM t1;
AsText(g)
LINESTRING(1 1,2 2)
DROP TABLE t1;
SET @g= MultiLineString(LineString(Point(1, 1), Point(2,2)),
LineString(Point(-1, -1), Point(-2,-2)));
CREATE TABLE t1 AS SELECT @g AS g;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`g` multilinestring DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT AsText(g) FROM t1;
AsText(g)
MULTILINESTRING((1 1,2 2),(-1 -1,-2 -2))
DROP TABLE t1;
SET @g= Polygon(LineString(Point(0, 0), Point(30, 0), Point(30, 30), Point(0, 0)));
CREATE TABLE t1 AS SELECT @g AS g;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`g` polygon DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT AsText(g) FROM t1;
AsText(g)
POLYGON((0 0,30 0,30 30,0 0))
DROP TABLE t1;
SET @g= MultiPolygon(Polygon(LineString(Point(0, 3), Point(3, 3),
Point(3, 0), Point(0, 3))));
CREATE TABLE t1 AS SELECT @g AS g;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`g` multipolygon DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT AsText(g) FROM t1;
AsText(g)
MULTIPOLYGON(((0 3,3 3,3 0,0 3)))
DROP TABLE t1;
SET @g= GeometryCollection(Point(44, 6), LineString(Point(3, 6), Point(7, 9)));
CREATE TABLE t1 AS SELECT @g AS g;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`g` geometrycollection DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT AsText(g) FROM t1;
AsText(g)
GEOMETRYCOLLECTION(POINT(44 6),LINESTRING(3 6,7 9))
DROP TABLE t1;
SET @g= GeometryFromText('POINT(1 1)');
CREATE TABLE t1 AS SELECT @g AS g;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`g` geometry DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT AsText(g) FROM t1;
AsText(g)
POINT(1 1)
DROP TABLE t1;
#
# End of 10.5 tests
#
63 changes: 63 additions & 0 deletions mysql-test/main/gis.test
Expand Up @@ -3374,6 +3374,69 @@ SELECT BIT_OR(a) FROM t1;
SELECT BIT_XOR(a) FROM t1;
DROP TABLE t1;

--echo #
--echo # MDEV-27666 User variable not parsed as geometry variable in geometry function.
--echo #

set @g= point(1, 1);
select ST_AsWKT(GeometryCollection(Point(44, 6), @g));
set @g= "just a string";
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
select ST_AsWKT(GeometryCollection(Point(44, 6), @g));

SET @g= LineString(Point(0,0), Point(0,1));
SELECT AsText(PointN(@g, 1));
SELECT AsText(PointN(@g, 2));

SET @g= Point(1, 1);
CREATE TABLE t1 AS SELECT @g AS g;
SHOW CREATE TABLE t1;
SELECT AsText(g) FROM t1;
DROP TABLE t1;

SET @g= MultiPoint(Point(1, 1), Point(-1,-1));
CREATE TABLE t1 AS SELECT @g AS g;
SHOW CREATE TABLE t1;
SELECT AsText(g) FROM t1;
DROP TABLE t1;

SET @g= LineString(Point(1, 1), Point(2,2));
CREATE TABLE t1 AS SELECT @g AS g;
SHOW CREATE TABLE t1;
SELECT AsText(g) FROM t1;
DROP TABLE t1;

SET @g= MultiLineString(LineString(Point(1, 1), Point(2,2)),
LineString(Point(-1, -1), Point(-2,-2)));
CREATE TABLE t1 AS SELECT @g AS g;
SHOW CREATE TABLE t1;
SELECT AsText(g) FROM t1;
DROP TABLE t1;

SET @g= Polygon(LineString(Point(0, 0), Point(30, 0), Point(30, 30), Point(0, 0)));
CREATE TABLE t1 AS SELECT @g AS g;
SHOW CREATE TABLE t1;
SELECT AsText(g) FROM t1;
DROP TABLE t1;

SET @g= MultiPolygon(Polygon(LineString(Point(0, 3), Point(3, 3),
Point(3, 0), Point(0, 3))));
CREATE TABLE t1 AS SELECT @g AS g;
SHOW CREATE TABLE t1;
SELECT AsText(g) FROM t1;
DROP TABLE t1;

SET @g= GeometryCollection(Point(44, 6), LineString(Point(3, 6), Point(7, 9)));
CREATE TABLE t1 AS SELECT @g AS g;
SHOW CREATE TABLE t1;
SELECT AsText(g) FROM t1;
DROP TABLE t1;

SET @g= GeometryFromText('POINT(1 1)');
CREATE TABLE t1 AS SELECT @g AS g;
SHOW CREATE TABLE t1;
SELECT AsText(g) FROM t1;
DROP TABLE t1;

--echo #
--echo # End of 10.5 tests
Expand Down
12 changes: 12 additions & 0 deletions mysql-test/suite/binlog/r/binlog_gis_user_var_stm.result
@@ -0,0 +1,12 @@
SET @g0= POINT(1,1);
SET @g1= Polygon(LineString(Point(0, 0), Point(30, 0), Point(30, 30), Point(0, 0)));
CREATE TABLE t1 AS SELECT @g0 AS g0, @g1 AS g1;
DROP TABLE t1;
include/show_binlog_events.inc
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Gtid # # GTID #-#-#
master-bin.000001 # User var # # @`g0`=/*point*/_binary X'000000000101000000000000000000F03F000000000000F03F' COLLATE binary
master-bin.000001 # User var # # @`g1`=/*polygon*/_binary X'0000000001030000000100000004000000000000000000000000000000000000000000000000003E4000000000000000000000000000003E400000000000003E4000000000000000000000000000000000' COLLATE binary
master-bin.000001 # Query # # use `test`; CREATE TABLE t1 AS SELECT @g0 AS g0, @g1 AS g1
master-bin.000001 # Gtid # # GTID #-#-#
master-bin.000001 # Query # # use `test`; DROP TABLE `t1` /* generated by server */
15 changes: 15 additions & 0 deletions mysql-test/suite/binlog/t/binlog_gis_user_var_stm.test
@@ -0,0 +1,15 @@
--source include/not_embedded.inc
--source include/have_binlog_format_statement.inc
--source include/have_geometry.inc

--disable_query_log
reset master; # get rid of previous tests binlog
--enable_query_log

SET @g0= POINT(1,1);
SET @g1= Polygon(LineString(Point(0, 0), Point(30, 0), Point(30, 30), Point(0, 0)));
CREATE TABLE t1 AS SELECT @g0 AS g0, @g1 AS g1;
DROP TABLE t1;

--let $binlog_file = LAST
source include/show_binlog_events.inc;
21 changes: 21 additions & 0 deletions mysql-test/suite/rpl/r/rpl_gis_user_var.result
@@ -0,0 +1,21 @@
include/master-slave.inc
[connection master]
#
#
#
connection master;
SET @p=POINT(1,1);
CREATE TABLE t1 AS SELECT @p AS p;
connection slave;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`p` point DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT ST_AsWKT(p) FROM t1;
ST_AsWKT(p)
POINT(1 1)
connection master;
DROP TABLE t1;
connection slave;
include/rpl_end.inc
18 changes: 18 additions & 0 deletions mysql-test/suite/rpl/t/rpl_gis_user_var.test
@@ -0,0 +1,18 @@
--source include/have_geometry.inc
--source include/master-slave.inc

--echo #
--echo #
--echo #

connection master;
SET @p=POINT(1,1);
CREATE TABLE t1 AS SELECT @p AS p;
sync_slave_with_master;
SHOW CREATE TABLE t1;
SELECT ST_AsWKT(p) FROM t1;
connection master;
DROP TABLE t1;
sync_slave_with_master;

--source include/rpl_end.inc
6 changes: 3 additions & 3 deletions plugin/user_variables/user_variables.cc
Expand Up @@ -79,9 +79,9 @@ static int user_variables_fill(THD *thd, TABLE_LIST *tables, COND *cond)
else
return 1;

const LEX_CSTRING *tmp= var->unsigned_flag ?
&unsigned_result_types[var->type] :
&result_types[var->type];
const LEX_CSTRING *tmp= var->type_handler()->is_unsigned() ?
&unsigned_result_types[var->type_handler()->result_type()] :
&result_types[var->type_handler()->result_type()];
field[2]->store(tmp->str, tmp->length, system_charset_info);

if (var->charset())
Expand Down

0 comments on commit fa3171d

Please sign in to comment.