summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Botchkov <holyfoot@montyprogram.com>2014-09-02 11:31:26 +0500
committerAlexey Botchkov <holyfoot@montyprogram.com>2014-10-21 12:25:47 +0500
commitc3db4459561bc491582bef6bea7b83e9fe464a10 (patch)
treea3308648bcde663b43f703a1a52051e95ce13ebe
parentc1f5f61c9b651cac80f22319beed13733963c632 (diff)
downloadmariadb-git-c3db4459561bc491582bef6bea7b83e9fe464a10.tar.gz
MDEV-12 OpenGIS: create required tables: GeometryColumns, related views.
GEOMETRY_COLUMNS and SPATIAL_REF_SYS tables added to the INFORMATION_SCHEMA.
-rw-r--r--mysql-test/r/gis.result34
-rw-r--r--mysql-test/r/information_schema.result2
-rw-r--r--mysql-test/t/gis.test9
-rw-r--r--sql/field.h1
-rw-r--r--sql/handler.h6
-rw-r--r--sql/sql_show.cc133
6 files changed, 184 insertions, 1 deletions
diff --git a/mysql-test/r/gis.result b/mysql-test/r/gis.result
index a1d2ec862b7..70e52154082 100644
--- a/mysql-test/r/gis.result
+++ b/mysql-test/r/gis.result
@@ -1613,3 +1613,37 @@ insert into t1 values(Geomfromtext('POLYGON((1 1, 2 2, 2 1, 1 1))'));
ERROR 22007: Incorrect POINT value: 'POLYGON' for column 'pt' at row 1
drop table t1;
End of 5.5 tests
+SHOW CREATE TABLE information_schema.geometry_columns;
+Table Create Table
+GEOMETRY_COLUMNS CREATE TEMPORARY TABLE `GEOMETRY_COLUMNS` (
+ `F_TABLE_CATALOG` varchar(512) NOT NULL DEFAULT '',
+ `F_TABLE_SCHEMA` varchar(64) NOT NULL DEFAULT '',
+ `F_TABLE_NAME` varchar(64) NOT NULL DEFAULT '',
+ `F_GEOMETRY_COLUMN` varchar(64) NOT NULL DEFAULT '',
+ `G_TABLE_CATALOG` varchar(512) NOT NULL DEFAULT '',
+ `G_TABLE_SCHEMA` varchar(64) NOT NULL DEFAULT '',
+ `G_TABLE_NAME` varchar(64) NOT NULL DEFAULT '',
+ `G_GEOMETRY_COLUMN` varchar(64) NOT NULL DEFAULT '',
+ `STORAGE_TYPE` tinyint(2) NOT NULL DEFAULT '0',
+ `GEOMETRY_TYPE` int(7) NOT NULL DEFAULT '0',
+ `COORD_DIMENSION` tinyint(2) NOT NULL DEFAULT '0',
+ `MAX_PPR` tinyint(2) NOT NULL DEFAULT '0',
+ `SRID` smallint(5) NOT NULL DEFAULT '0'
+) ENGINE=MEMORY DEFAULT CHARSET=utf8
+SHOW CREATE TABLE information_schema.spatial_ref_sys;
+Table Create Table
+SPATIAL_REF_SYS CREATE TEMPORARY TABLE `SPATIAL_REF_SYS` (
+ `SRID` smallint(5) NOT NULL DEFAULT '0',
+ `AUTH_NAME` varchar(512) NOT NULL DEFAULT '',
+ `AUTH_SRID` smallint(5) NOT NULL DEFAULT '0',
+ `SRTEXT` varchar(2048) NOT NULL DEFAULT ''
+) ENGINE=MEMORY DEFAULT CHARSET=utf8
+create table t1(g GEOMETRY, pt POINT);
+create table t2(g LINESTRING, pl POLYGON);
+select * from information_schema.geometry_columns;
+F_TABLE_CATALOG F_TABLE_SCHEMA F_TABLE_NAME F_GEOMETRY_COLUMN G_TABLE_CATALOG G_TABLE_SCHEMA G_TABLE_NAME G_GEOMETRY_COLUMN STORAGE_TYPE GEOMETRY_TYPE COORD_DIMENSION MAX_PPR SRID
+def test t1 def test t1 g 1 0 2 0 0 0
+def test t1 def test t1 pt 1 1 2 0 0 0
+def test t2 def test t2 g 1 2 2 0 0 0
+def test t2 def test t2 pl 1 3 2 0 0 0
+drop table t1, t2;
diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result
index 3d261d0be5f..8682d229f11 100644
--- a/mysql-test/r/information_schema.result
+++ b/mysql-test/r/information_schema.result
@@ -58,6 +58,7 @@ ENABLED_ROLES
ENGINES
EVENTS
FILES
+GEOMETRY_COLUMNS
GLOBAL_STATUS
GLOBAL_VARIABLES
INDEX_STATISTICS
@@ -74,6 +75,7 @@ SCHEMATA
SCHEMA_PRIVILEGES
SESSION_STATUS
SESSION_VARIABLES
+SPATIAL_REF_SYS
STATISTICS
SYSTEM_VARIABLES
TABLES
diff --git a/mysql-test/t/gis.test b/mysql-test/t/gis.test
index d20e4c1711e..5dc5b48f32c 100644
--- a/mysql-test/t/gis.test
+++ b/mysql-test/t/gis.test
@@ -1473,3 +1473,12 @@ insert into t1 values(Geomfromtext('POLYGON((1 1, 2 2, 2 1, 1 1))'));
drop table t1;
--echo End of 5.5 tests
+
+SHOW CREATE TABLE information_schema.geometry_columns;
+SHOW CREATE TABLE information_schema.spatial_ref_sys;
+
+create table t1(g GEOMETRY, pt POINT);
+create table t2(g LINESTRING, pl POLYGON);
+select * from information_schema.geometry_columns;
+drop table t1, t2;
+
diff --git a/sql/field.h b/sql/field.h
index f1679379fe8..da854968fe6 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -2571,6 +2571,7 @@ public:
int reset(void) { return Field_blob::reset() || !maybe_null(); }
geometry_type get_geometry_type() { return geom_type; };
+ uint get_srid() { return 0; }
};
#endif /*HAVE_SPATIAL*/
diff --git a/sql/handler.h b/sql/handler.h
index c91b26f768f..00445565f06 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -750,7 +750,11 @@ enum enum_schema_tables
SCH_TABLE_PRIVILEGES,
SCH_TRIGGERS,
SCH_USER_PRIVILEGES,
- SCH_VIEWS
+ SCH_VIEWS,
+#ifdef HAVE_SPATIAL
+ SCH_GEOMETRY_COLUMNS,
+ SCH_SPATIAL_REF_SYS,
+#endif /*HAVE_SPATIAL*/
};
struct TABLE_SHARE;
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index d1c88e35b7a..0541cbcc300 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -331,6 +331,99 @@ int fill_all_plugins(THD *thd, TABLE_LIST *tables, COND *cond)
}
+#ifdef HAVE_SPATIAL
+static int fill_spatial_ref_sys(THD *thd, TABLE_LIST *tables, COND *cond)
+{
+ DBUG_ENTER("fill_spatial_ref_sys");
+ TABLE *table= tables->table;
+ CHARSET_INFO *cs= system_charset_info;
+ int result= 1;
+
+ restore_record(table, s->default_values);
+
+ table->field[0]->store(-1, FALSE); /*SRID*/
+ table->field[1]->store(STRING_WITH_LEN("Not defined"), cs); /*AUTH_NAME*/
+ table->field[2]->store(-1, FALSE); /*AUTH_SRID*/
+ table->field[3]->store(STRING_WITH_LEN(""), cs);/*SRTEXT*/
+ if (schema_table_store_record(thd, table))
+ goto exit;
+
+ table->field[0]->store(0, TRUE); /*SRID*/
+ table->field[1]->store(STRING_WITH_LEN("Cartesian plane"), cs); /*AUTH_NAME*/
+ table->field[2]->store(0, TRUE); /*AUTH_SRID*/
+ table->field[3]->store(STRING_WITH_LEN(""), cs);/*SRTEXT*/
+ if (schema_table_store_record(thd, table))
+ goto exit;
+
+ result= 0;
+
+exit:
+ DBUG_RETURN(result);
+}
+
+
+static int get_geometry_column_record(THD *thd, TABLE_LIST *tables,
+ TABLE *table, bool res,
+ LEX_STRING *db_name,
+ LEX_STRING *table_name)
+{
+ CHARSET_INFO *cs= system_charset_info;
+ TABLE *show_table;
+ Field **ptr, *field;
+ DBUG_ENTER("get_geometry_column_record");
+
+ if (tables->schema_table)
+ goto exit;
+ show_table= tables->table;
+ ptr= show_table->field;
+ show_table->use_all_columns(); // Required for default
+ restore_record(show_table, s->default_values);
+
+ for (; (field= *ptr) ; ptr++)
+ if (field->type() == MYSQL_TYPE_GEOMETRY)
+ {
+ Field_geom *fg= (Field_geom *) field;
+
+ DEBUG_SYNC(thd, "get_schema_column");
+
+ /* Get default row, with all NULL fields set to NULL */
+ restore_record(table, s->default_values);
+
+ /*F_TABLE_CATALOG*/
+ table->field[0]->store(STRING_WITH_LEN("def"), cs);
+ /*F_TABLE_SCHEMA*/
+ table->field[1]->store(db_name->str, db_name->length, cs);
+ /*F_TABLE_NAME*/
+ table->field[2]->store(table_name->str, table_name->length, cs);
+ /*G_TABLE_CATALOG*/
+ table->field[3]->store(STRING_WITH_LEN("def"), cs);
+ /*G_TABLE_SCHEMA*/
+ table->field[4]->store(db_name->str, db_name->length, cs);
+ /*G_TABLE_NAME*/
+ table->field[5]->store(table_name->str, table_name->length, cs);
+ /*G_GEOMETRY_COLUMN*/
+ table->field[6]->store(field->field_name, strlen(field->field_name), cs);
+ /*STORAGE_TYPE*/
+ table->field[7]->store(1LL, TRUE); /*Always 1 (binary implementation)*/
+ /*GEOMETRY_TYPE*/
+ table->field[8]->store((longlong) (fg->get_geometry_type()), TRUE);
+ /*COORD_DIMENSION*/
+ table->field[9]->store(2LL, TRUE);
+ /*MAX_PPR*/
+ table->field[10]->set_null();
+ /*SRID*/
+ table->field[11]->store((longlong) (fg->get_srid()), TRUE);
+
+ if (schema_table_store_record(thd, table))
+ DBUG_RETURN(1);
+ }
+
+exit:
+ DBUG_RETURN(0);
+}
+#endif /*HAVE_SPATIAL*/
+
+
/***************************************************************************
** List all Authors.
** If you can update it, you get to be in it :)
@@ -8747,6 +8840,39 @@ ST_FIELD_INFO show_explain_fields_info[]=
};
+#ifdef HAVE_SPATIAL
+ST_FIELD_INFO geometry_columns_fields_info[]=
+{
+ {"F_TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
+ {"F_TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
+ {"F_TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
+ {"F_GEOMETRY_COLUMN", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Field",
+ OPEN_FRM_ONLY},
+ {"G_TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
+ {"G_TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
+ {"G_TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
+ {"G_GEOMETRY_COLUMN", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Field",
+ OPEN_FRM_ONLY},
+ {"STORAGE_TYPE", 2, MYSQL_TYPE_TINY, 0, 0, 0, OPEN_FRM_ONLY},
+ {"GEOMETRY_TYPE", 7, MYSQL_TYPE_LONG, 0, 0, 0, OPEN_FRM_ONLY},
+ {"COORD_DIMENSION", 2, MYSQL_TYPE_TINY, 0, 0, 0, OPEN_FRM_ONLY},
+ {"MAX_PPR", 2, MYSQL_TYPE_TINY, 0, 0, 0, OPEN_FRM_ONLY},
+ {"SRID", 5, MYSQL_TYPE_SHORT, 0, 0, 0, OPEN_FRM_ONLY},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
+};
+
+
+ST_FIELD_INFO spatial_ref_sys_fields_info[]=
+{
+ {"SRID", 5, MYSQL_TYPE_SHORT, 0, 0, 0, SKIP_OPEN_TABLE},
+ {"AUTH_NAME", FN_REFLEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
+ {"AUTH_SRID", 5, MYSQL_TYPE_SHORT, 0, 0, 0, SKIP_OPEN_TABLE},
+ {"SRTEXT", 2048, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
+};
+#endif /*HAVE_SPATIAL*/
+
+
/*
Description of ST_FIELD_INFO in table.h
@@ -8847,6 +8973,13 @@ ST_SCHEMA_TABLE schema_tables[]=
{"VIEWS", view_fields_info, 0,
get_all_tables, 0, get_schema_views_record, 1, 2, 0,
OPEN_VIEW_ONLY|OPTIMIZE_I_S_TABLE},
+#ifdef HAVE_SPATIAL
+ {"GEOMETRY_COLUMNS", geometry_columns_fields_info, 0,
+ get_all_tables, make_columns_old_format, get_geometry_column_record,
+ 1, 2, 0, OPTIMIZE_I_S_TABLE|OPEN_VIEW_FULL},
+ {"SPATIAL_REF_SYS", spatial_ref_sys_fields_info, 0,
+ fill_spatial_ref_sys, make_old_format, 0, -1, -1, 0, 0},
+#endif /*HAVE_SPATIAL*/
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};