Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
WIP: Add support for geometry columns. #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Shelnutt2 committed Apr 30, 2018
1 parent 361d4f2 commit 7a13ea3
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 14 deletions.
88 changes: 88 additions & 0 deletions mysql-test/mytile/r/data_types.result
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,91 @@ select * FROM t1;
column1 column2
test 1
DROP TABLE t1;
# POINT
CREATE TABLE t1 (
column1 int,
column2 POINT,
primary key(column1)
) ENGINE=mytile;
INSERT INTO t1 VALUES (1, PointFromText('POINT(10 10)'));
select ST_AsText(column1) FROM t1;
ST_AsText(column1)
POINT(10 10)
DROP TABLE t1;
# LINESTRING
CREATE TABLE t1 (
column1 int,
column2 LINESTRING,
primary key(column1)
) ENGINE=mytile;
INSERT INTO t1 VALUES (1, LineFromText('LINESTRING(0 0,0 10,10 0)'));
select ST_AsText(column1) FROM t1;
ST_AsText(column1)
LINESTRING(0 0,0 10,10 0)
DROP TABLE t1;
# POLYGON
CREATE TABLE t1 (
column1 int,
column2 POLYGON
primary key(column1)
) ENGINE=mytile;
INSERT INTO t1 VALUES (1, PolygonFromText('POLYGON((10 10,20 10,20 20,10 20,10 10))'));
select ST_AsText(column1) FROM t1;
ST_AsText(column1)
POLYGON((10 10,20 10,20 20,10 20,10 10))
DROP TABLE t1;
# MULTIPOINT
CREATE TABLE t1 (
column1 int,
column2 MULTIPOINT,
primary key(column1)
) ENGINE=mytile;
INSERT INTO t1 VALUES (1, MultiPointFromText('MULTIPOINT(0 0,10 10,10 20,20 20)'));
select ST_AsText(column1) FROM t1;
ST_AsText(column1)
MULTIPOINT(0 0,10 10,10 20,20 20)
DROP TABLE t1;
# MULTILINESTRING
CREATE TABLE t1 (
column1 int,
column2 MULTILINESTRING,
primary key(column1)
) ENGINE=mytile;
INSERT INTO t1 VALUES (1, MultiLineStringFromText('MULTILINESTRING((10 48,10 21,10 0),(16 0,16 23,16 48))'));
select ST_AsText(column1) FROM t1;
ST_AsText(column1)
MULTILINESTRING((10 48,10 21,10 0),(16 0,16 23,16 48))
DROP TABLE t1;
# MULTIPOLYGON
CREATE TABLE t1 (
column1 int,
column2 MULTIPOLYGON,
primary key(column1)
) ENGINE=mytile;
INSERT INTO t1 VALUES (1, MultiPolygonFromText('MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))'));
select ST_AsText(column1) FROM t1;
ST_AsText(column1)
MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))
DROP TABLE t1;
# GEOMETRYCOLLECTION
CREATE TABLE t1 (
column1 int,
column2 GEOMETRYCOLLECTION,
primary key(column1)
) ENGINE=mytile;
INSERT INTO t1 VALUES (1, GeomCollFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))'));
select ST_AsText(column1) FROM t1;
ST_AsText(column1)
GEOMETRYCOLLECTION(POINT(0 0),LINESTRING(0 0,10 10))
DROP TABLE t1;
# GEOMETRY
CREATE TABLE t1 (
column1 int,
column2 GEOMETRY,
primary key(column1)
) ENGINE=mytile;
INSERT INTO t1 VALUES (1, PointFromText('POINT(10 10)'));
select ST_AsText(column1) FROM t1;
ST_AsText(column1)
POINT(10 10)
DROP TABLE t1;
80 changes: 80 additions & 0 deletions mysql-test/mytile/t/data_types.test
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,83 @@ CREATE TABLE t1 (
INSERT INTO t1 VALUES ("test", 1);
select * FROM t1;
DROP TABLE t1;

--echo # POINT
CREATE TABLE t1 (
column1 int,
column2 POINT,
primary key(column1)
) ENGINE=mytile;
INSERT INTO t1 VALUES (1, PointFromText('POINT(10 10)'));
select ST_AsText(column1) FROM t1;
DROP TABLE t1;

--echo # LINESTRING
CREATE TABLE t1 (
column1 int,
column2 LINESTRING,
primary key(column1)
) ENGINE=mytile;
INSERT INTO t1 VALUES (1, LineFromText('LINESTRING(0 0,0 10,10 0)'));
select ST_AsText(column1) FROM t1;
DROP TABLE t1;

--echo # POLYGON
CREATE TABLE t1 (
column1 int,
column2 POLYGON,
primary key(column1)
) ENGINE=mytile;
INSERT INTO t1 VALUES (1, PolygonFromText('POLYGON((10 10,20 10,20 20,10 20,10 10))'));
select ST_AsText(column1) FROM t1;
DROP TABLE t1;

--echo # MULTIPOINT
CREATE TABLE t1 (
column1 int,
column2 MULTIPOINT,
primary key(column1)
) ENGINE=mytile;
INSERT INTO t1 VALUES (1, MultiPointFromText('MULTIPOINT(0 0,10 10,10 20,20 20)'));
select ST_AsText(column1) FROM t1;
DROP TABLE t1;

--echo # MULTILINESTRING
CREATE TABLE t1 (
column1 int,
column2 MULTILINESTRING,
primary key(column1)
) ENGINE=mytile;
INSERT INTO t1 VALUES (1, MultiLineStringFromText('MULTILINESTRING((10 48,10 21,10 0),(16 0,16 23,16 48))'));
select ST_AsText(column1) FROM t1;
DROP TABLE t1;

--echo # MULTIPOLYGON
CREATE TABLE t1 (
column1 int,
column2 MULTIPOLYGON,
primary key(column1)
) ENGINE=mytile;
INSERT INTO t1 VALUES (1, MultiPolygonFromText('MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))'));
select ST_AsText(column1) FROM t1;
DROP TABLE t1;

--echo # GEOMETRYCOLLECTION
CREATE TABLE t1 (
column1 int,
column2 GEOMETRYCOLLECTION,
primary key(column1)
) ENGINE=mytile;
INSERT INTO t1 VALUES (1, GeomCollFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))'));
select ST_AsText(column1) FROM t1;
DROP TABLE t1;

--echo # GEOMETRY
CREATE TABLE t1 (
column1 int,
column2 GEOMETRY,
primary key(column1)
) ENGINE=mytile;
INSERT INTO t1 VALUES (1, PointFromText('POINT(10 10)'));
select ST_AsText(column1) FROM t1;
DROP TABLE t1;
41 changes: 27 additions & 14 deletions mytile/ha_mytile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,24 @@ int tile::mytile::write_row(uchar *buf) {
if (field->is_null())
item[field->field_name] = std::string("null");
else {
char attribute_buffer[1024 * 8];
String attribute(attribute_buffer, sizeof(attribute_buffer),
&my_charset_utf8_general_ci);
field->val_str(&attribute, &attribute);
item[field->field_name] = std::string(attribute.c_ptr_safe());
switch (field->type()) {
case MYSQL_TYPE_GEOMETRY: {
char attribute_buffer[1024];
String attribute(attribute_buffer, sizeof(attribute_buffer),
&my_charset_bin);
field->val_str(&attribute, &attribute);
item[field->field_name] = std::string(attribute.c_ptr_safe(), attribute.length());
break;
}
default: {
char attribute_buffer[1024];
String attribute(attribute_buffer, sizeof(attribute_buffer),
&my_charset_utf8_general_ci);
field->val_str(&attribute, &attribute);
item[field->field_name] = std::string(attribute.c_ptr_safe());
break;
}
}
}
break;
}
Expand Down Expand Up @@ -550,7 +563,7 @@ int tile::mytile::write_row(uchar *buf) {
item[field->field_name] = std::string("null");
else {
//Buffer used for conversion of string
char attribute_buffer[1024 * 8];
char attribute_buffer[1024];
String attribute(attribute_buffer, sizeof(attribute_buffer),
&my_charset_utf8_general_ci);
field->val_str(&attribute, &attribute);
Expand All @@ -564,7 +577,7 @@ int tile::mytile::write_row(uchar *buf) {
if (field->is_null())
item[field->field_name] = std::string("null");
else {
char attribute_buffer[1024 * 8];
char attribute_buffer[1024];
String attribute(attribute_buffer, sizeof(attribute_buffer),
&my_charset_utf8_general_ci);
field->val_str(&attribute, &attribute);
Expand All @@ -578,7 +591,7 @@ int tile::mytile::write_row(uchar *buf) {
if (field->is_null())
item[field->field_name] = std::string("null");
else {
char attribute_buffer[1024 * 8];
char attribute_buffer[1024];
String attribute(attribute_buffer, sizeof(attribute_buffer),
&my_charset_utf16_general_ci);
field->val_str(&attribute, &attribute);
Expand All @@ -592,7 +605,7 @@ int tile::mytile::write_row(uchar *buf) {
if (field->is_null())
item[field->field_name] = std::string("null");
else {
char attribute_buffer[1024 * 8];
char attribute_buffer[1024];
String attribute(attribute_buffer, sizeof(attribute_buffer),
&my_charset_utf32_general_ci);
field->val_str(&attribute, &attribute);
Expand All @@ -606,7 +619,7 @@ int tile::mytile::write_row(uchar *buf) {
if (field->is_null())
item[field->field_name] = std::string("null");
else {
char attribute_buffer[1024 * 8];
char attribute_buffer[1024];
String attribute(attribute_buffer, sizeof(attribute_buffer),
&my_charset_ucs2_general_ci);
field->val_str(&attribute, &attribute);
Expand All @@ -620,7 +633,7 @@ int tile::mytile::write_row(uchar *buf) {
if (field->is_null())
item[field->field_name] = std::string("null");
else {
char attribute_buffer[1024 * 8];
char attribute_buffer[1024];
String attribute(attribute_buffer, sizeof(attribute_buffer),
&my_charset_utf8_general_ci);
field->val_str(&attribute, &attribute);
Expand All @@ -634,7 +647,7 @@ int tile::mytile::write_row(uchar *buf) {
if (field->is_null())
item[field->field_name] = std::string("null");
else {
char attribute_buffer[1024 * 8];
char attribute_buffer[1024];
String attribute(attribute_buffer, sizeof(attribute_buffer),
&my_charset_utf8_general_ci);
field->val_str(&attribute, &attribute);
Expand Down Expand Up @@ -853,7 +866,7 @@ ha_rows tile::mytile::records_in_range(uint inx, key_range *min_key, key_range *
*/
ulonglong tile::mytile::table_flags(void) const {
DBUG_ENTER("tile::mytile::table_flags");
DBUG_RETURN(HA_REC_NOT_IN_SEQ | HA_CAN_SQL_HANDLER | HA_NULL_IN_KEY | HA_REQUIRE_PRIMARY_KEY
DBUG_RETURN(HA_REC_NOT_IN_SEQ | HA_CAN_SQL_HANDLER | HA_NULL_IN_KEY | HA_REQUIRE_PRIMARY_KEY | HA_CAN_GEOMETRY
| HA_CAN_BIT_FIELD | HA_FILE_BASED | HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE);
};

Expand Down Expand Up @@ -888,4 +901,4 @@ maria_declare_plugin(mytile)
NULL, /* system variables */
"0.1", /* string version */
MariaDB_PLUGIN_MATURITY_EXPERIMENTAL /* maturity */
}maria_declare_plugin_end;
}maria_declare_plugin_end;

0 comments on commit 7a13ea3

Please sign in to comment.