Skip to content

Commit c3db445

Browse files
committed
MDEV-12 OpenGIS: create required tables: GeometryColumns, related views.
GEOMETRY_COLUMNS and SPATIAL_REF_SYS tables added to the INFORMATION_SCHEMA.
1 parent c1f5f61 commit c3db445

File tree

6 files changed

+184
-1
lines changed

6 files changed

+184
-1
lines changed

mysql-test/r/gis.result

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,3 +1613,37 @@ insert into t1 values(Geomfromtext('POLYGON((1 1, 2 2, 2 1, 1 1))'));
16131613
ERROR 22007: Incorrect POINT value: 'POLYGON' for column 'pt' at row 1
16141614
drop table t1;
16151615
End of 5.5 tests
1616+
SHOW CREATE TABLE information_schema.geometry_columns;
1617+
Table Create Table
1618+
GEOMETRY_COLUMNS CREATE TEMPORARY TABLE `GEOMETRY_COLUMNS` (
1619+
`F_TABLE_CATALOG` varchar(512) NOT NULL DEFAULT '',
1620+
`F_TABLE_SCHEMA` varchar(64) NOT NULL DEFAULT '',
1621+
`F_TABLE_NAME` varchar(64) NOT NULL DEFAULT '',
1622+
`F_GEOMETRY_COLUMN` varchar(64) NOT NULL DEFAULT '',
1623+
`G_TABLE_CATALOG` varchar(512) NOT NULL DEFAULT '',
1624+
`G_TABLE_SCHEMA` varchar(64) NOT NULL DEFAULT '',
1625+
`G_TABLE_NAME` varchar(64) NOT NULL DEFAULT '',
1626+
`G_GEOMETRY_COLUMN` varchar(64) NOT NULL DEFAULT '',
1627+
`STORAGE_TYPE` tinyint(2) NOT NULL DEFAULT '0',
1628+
`GEOMETRY_TYPE` int(7) NOT NULL DEFAULT '0',
1629+
`COORD_DIMENSION` tinyint(2) NOT NULL DEFAULT '0',
1630+
`MAX_PPR` tinyint(2) NOT NULL DEFAULT '0',
1631+
`SRID` smallint(5) NOT NULL DEFAULT '0'
1632+
) ENGINE=MEMORY DEFAULT CHARSET=utf8
1633+
SHOW CREATE TABLE information_schema.spatial_ref_sys;
1634+
Table Create Table
1635+
SPATIAL_REF_SYS CREATE TEMPORARY TABLE `SPATIAL_REF_SYS` (
1636+
`SRID` smallint(5) NOT NULL DEFAULT '0',
1637+
`AUTH_NAME` varchar(512) NOT NULL DEFAULT '',
1638+
`AUTH_SRID` smallint(5) NOT NULL DEFAULT '0',
1639+
`SRTEXT` varchar(2048) NOT NULL DEFAULT ''
1640+
) ENGINE=MEMORY DEFAULT CHARSET=utf8
1641+
create table t1(g GEOMETRY, pt POINT);
1642+
create table t2(g LINESTRING, pl POLYGON);
1643+
select * from information_schema.geometry_columns;
1644+
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
1645+
def test t1 def test t1 g 1 0 2 0 0 0
1646+
def test t1 def test t1 pt 1 1 2 0 0 0
1647+
def test t2 def test t2 g 1 2 2 0 0 0
1648+
def test t2 def test t2 pl 1 3 2 0 0 0
1649+
drop table t1, t2;

mysql-test/r/information_schema.result

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ ENABLED_ROLES
5858
ENGINES
5959
EVENTS
6060
FILES
61+
GEOMETRY_COLUMNS
6162
GLOBAL_STATUS
6263
GLOBAL_VARIABLES
6364
INDEX_STATISTICS
@@ -74,6 +75,7 @@ SCHEMATA
7475
SCHEMA_PRIVILEGES
7576
SESSION_STATUS
7677
SESSION_VARIABLES
78+
SPATIAL_REF_SYS
7779
STATISTICS
7880
SYSTEM_VARIABLES
7981
TABLES

mysql-test/t/gis.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,3 +1473,12 @@ insert into t1 values(Geomfromtext('POLYGON((1 1, 2 2, 2 1, 1 1))'));
14731473
drop table t1;
14741474

14751475
--echo End of 5.5 tests
1476+
1477+
SHOW CREATE TABLE information_schema.geometry_columns;
1478+
SHOW CREATE TABLE information_schema.spatial_ref_sys;
1479+
1480+
create table t1(g GEOMETRY, pt POINT);
1481+
create table t2(g LINESTRING, pl POLYGON);
1482+
select * from information_schema.geometry_columns;
1483+
drop table t1, t2;
1484+

sql/field.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2571,6 +2571,7 @@ class Field_geom :public Field_blob {
25712571
int reset(void) { return Field_blob::reset() || !maybe_null(); }
25722572

25732573
geometry_type get_geometry_type() { return geom_type; };
2574+
uint get_srid() { return 0; }
25742575
};
25752576
#endif /*HAVE_SPATIAL*/
25762577

sql/handler.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,11 @@ enum enum_schema_tables
750750
SCH_TABLE_PRIVILEGES,
751751
SCH_TRIGGERS,
752752
SCH_USER_PRIVILEGES,
753-
SCH_VIEWS
753+
SCH_VIEWS,
754+
#ifdef HAVE_SPATIAL
755+
SCH_GEOMETRY_COLUMNS,
756+
SCH_SPATIAL_REF_SYS,
757+
#endif /*HAVE_SPATIAL*/
754758
};
755759

756760
struct TABLE_SHARE;

sql/sql_show.cc

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,99 @@ int fill_all_plugins(THD *thd, TABLE_LIST *tables, COND *cond)
331331
}
332332

333333

334+
#ifdef HAVE_SPATIAL
335+
static int fill_spatial_ref_sys(THD *thd, TABLE_LIST *tables, COND *cond)
336+
{
337+
DBUG_ENTER("fill_spatial_ref_sys");
338+
TABLE *table= tables->table;
339+
CHARSET_INFO *cs= system_charset_info;
340+
int result= 1;
341+
342+
restore_record(table, s->default_values);
343+
344+
table->field[0]->store(-1, FALSE); /*SRID*/
345+
table->field[1]->store(STRING_WITH_LEN("Not defined"), cs); /*AUTH_NAME*/
346+
table->field[2]->store(-1, FALSE); /*AUTH_SRID*/
347+
table->field[3]->store(STRING_WITH_LEN(""), cs);/*SRTEXT*/
348+
if (schema_table_store_record(thd, table))
349+
goto exit;
350+
351+
table->field[0]->store(0, TRUE); /*SRID*/
352+
table->field[1]->store(STRING_WITH_LEN("Cartesian plane"), cs); /*AUTH_NAME*/
353+
table->field[2]->store(0, TRUE); /*AUTH_SRID*/
354+
table->field[3]->store(STRING_WITH_LEN(""), cs);/*SRTEXT*/
355+
if (schema_table_store_record(thd, table))
356+
goto exit;
357+
358+
result= 0;
359+
360+
exit:
361+
DBUG_RETURN(result);
362+
}
363+
364+
365+
static int get_geometry_column_record(THD *thd, TABLE_LIST *tables,
366+
TABLE *table, bool res,
367+
LEX_STRING *db_name,
368+
LEX_STRING *table_name)
369+
{
370+
CHARSET_INFO *cs= system_charset_info;
371+
TABLE *show_table;
372+
Field **ptr, *field;
373+
DBUG_ENTER("get_geometry_column_record");
374+
375+
if (tables->schema_table)
376+
goto exit;
377+
show_table= tables->table;
378+
ptr= show_table->field;
379+
show_table->use_all_columns(); // Required for default
380+
restore_record(show_table, s->default_values);
381+
382+
for (; (field= *ptr) ; ptr++)
383+
if (field->type() == MYSQL_TYPE_GEOMETRY)
384+
{
385+
Field_geom *fg= (Field_geom *) field;
386+
387+
DEBUG_SYNC(thd, "get_schema_column");
388+
389+
/* Get default row, with all NULL fields set to NULL */
390+
restore_record(table, s->default_values);
391+
392+
/*F_TABLE_CATALOG*/
393+
table->field[0]->store(STRING_WITH_LEN("def"), cs);
394+
/*F_TABLE_SCHEMA*/
395+
table->field[1]->store(db_name->str, db_name->length, cs);
396+
/*F_TABLE_NAME*/
397+
table->field[2]->store(table_name->str, table_name->length, cs);
398+
/*G_TABLE_CATALOG*/
399+
table->field[3]->store(STRING_WITH_LEN("def"), cs);
400+
/*G_TABLE_SCHEMA*/
401+
table->field[4]->store(db_name->str, db_name->length, cs);
402+
/*G_TABLE_NAME*/
403+
table->field[5]->store(table_name->str, table_name->length, cs);
404+
/*G_GEOMETRY_COLUMN*/
405+
table->field[6]->store(field->field_name, strlen(field->field_name), cs);
406+
/*STORAGE_TYPE*/
407+
table->field[7]->store(1LL, TRUE); /*Always 1 (binary implementation)*/
408+
/*GEOMETRY_TYPE*/
409+
table->field[8]->store((longlong) (fg->get_geometry_type()), TRUE);
410+
/*COORD_DIMENSION*/
411+
table->field[9]->store(2LL, TRUE);
412+
/*MAX_PPR*/
413+
table->field[10]->set_null();
414+
/*SRID*/
415+
table->field[11]->store((longlong) (fg->get_srid()), TRUE);
416+
417+
if (schema_table_store_record(thd, table))
418+
DBUG_RETURN(1);
419+
}
420+
421+
exit:
422+
DBUG_RETURN(0);
423+
}
424+
#endif /*HAVE_SPATIAL*/
425+
426+
334427
/***************************************************************************
335428
** List all Authors.
336429
** If you can update it, you get to be in it :)
@@ -8747,6 +8840,39 @@ ST_FIELD_INFO show_explain_fields_info[]=
87478840
};
87488841

87498842

8843+
#ifdef HAVE_SPATIAL
8844+
ST_FIELD_INFO geometry_columns_fields_info[]=
8845+
{
8846+
{"F_TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
8847+
{"F_TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
8848+
{"F_TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
8849+
{"F_GEOMETRY_COLUMN", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Field",
8850+
OPEN_FRM_ONLY},
8851+
{"G_TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
8852+
{"G_TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
8853+
{"G_TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
8854+
{"G_GEOMETRY_COLUMN", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Field",
8855+
OPEN_FRM_ONLY},
8856+
{"STORAGE_TYPE", 2, MYSQL_TYPE_TINY, 0, 0, 0, OPEN_FRM_ONLY},
8857+
{"GEOMETRY_TYPE", 7, MYSQL_TYPE_LONG, 0, 0, 0, OPEN_FRM_ONLY},
8858+
{"COORD_DIMENSION", 2, MYSQL_TYPE_TINY, 0, 0, 0, OPEN_FRM_ONLY},
8859+
{"MAX_PPR", 2, MYSQL_TYPE_TINY, 0, 0, 0, OPEN_FRM_ONLY},
8860+
{"SRID", 5, MYSQL_TYPE_SHORT, 0, 0, 0, OPEN_FRM_ONLY},
8861+
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
8862+
};
8863+
8864+
8865+
ST_FIELD_INFO spatial_ref_sys_fields_info[]=
8866+
{
8867+
{"SRID", 5, MYSQL_TYPE_SHORT, 0, 0, 0, SKIP_OPEN_TABLE},
8868+
{"AUTH_NAME", FN_REFLEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
8869+
{"AUTH_SRID", 5, MYSQL_TYPE_SHORT, 0, 0, 0, SKIP_OPEN_TABLE},
8870+
{"SRTEXT", 2048, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
8871+
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
8872+
};
8873+
#endif /*HAVE_SPATIAL*/
8874+
8875+
87508876
/*
87518877
Description of ST_FIELD_INFO in table.h
87528878
@@ -8847,6 +8973,13 @@ ST_SCHEMA_TABLE schema_tables[]=
88478973
{"VIEWS", view_fields_info, 0,
88488974
get_all_tables, 0, get_schema_views_record, 1, 2, 0,
88498975
OPEN_VIEW_ONLY|OPTIMIZE_I_S_TABLE},
8976+
#ifdef HAVE_SPATIAL
8977+
{"GEOMETRY_COLUMNS", geometry_columns_fields_info, 0,
8978+
get_all_tables, make_columns_old_format, get_geometry_column_record,
8979+
1, 2, 0, OPTIMIZE_I_S_TABLE|OPEN_VIEW_FULL},
8980+
{"SPATIAL_REF_SYS", spatial_ref_sys_fields_info, 0,
8981+
fill_spatial_ref_sys, make_old_format, 0, -1, -1, 0, 0},
8982+
#endif /*HAVE_SPATIAL*/
88508983
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
88518984
};
88528985

0 commit comments

Comments
 (0)