Skip to content

Commit a019aa0

Browse files
authored
Add support MySQL SPATIAL KEY (#2388)
1 parent 763e92d commit a019aa0

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9116,10 +9116,11 @@ CreateTable CreateTable(boolean isUsingOrReplace):
91169116
LOOKAHEAD(3) (
91179117
{
91189118
tk=null;
9119+
tk3=null;
91199120
idxSpec.clear();
91209121
}
91219122
[ tk=<K_UNIQUE> ]
9122-
[ tk3=<K_FULLTEXT> ] tk2=<K_KEY>
9123+
[ tk3=<K_FULLTEXT> | tk3=<K_SPATIAL> ] tk2=<K_KEY>
91239124
sk3=RelObjectName()
91249125
colNames = ColumnNamesWithParamsList()
91259126
( parameter=CreateParameter() { idxSpec.addAll(parameter); } )*

src/test/java/net/sf/jsqlparser/statement/create/CreateTableTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,31 @@ public void testMySqlCreateTableWithTextIndexes() throws JSQLParserException {
352352
"CREATE TABLE table2 (id INT (10) UNSIGNED NOT NULL AUTO_INCREMENT, name TEXT, url TEXT, created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id), FULLTEXT KEY idx_table2_name (name)) ENGINE = InnoDB AUTO_INCREMENT = 7334 DEFAULT CHARSET = utf8");
353353
}
354354

355+
@Test
356+
public void testMySqlCreateTableWithSpatialIndex() throws JSQLParserException {
357+
assertSqlCanBeParsedAndDeparsed(
358+
"CREATE TABLE places (id INT NOT NULL, location GEOMETRY NOT NULL, SPATIAL KEY sp_idx_location (location))");
359+
}
360+
361+
@Test
362+
public void testMySqlCreateTableIssue2367()
363+
throws JSQLParserException {
364+
String sql = "CREATE TABLE test (\n"
365+
+ "id int(11) NOT NULL COMMENT 'data id',\n"
366+
+ "code varchar(100) NOT NULL COMMENT 'code',\n"
367+
+ "name varchar(300) DEFAULT NULL COMMENT 'name',\n"
368+
+ "geo geometry NOT NULL,\n"
369+
+ "PRIMARY KEY (id),\n"
370+
+ "UNIQUE KEY index_code (code) USING HASH COMMENT 'unique index on code',\n"
371+
+ "UNIQUE KEY inx_code_name (code,name) USING BTREE COMMENT 'unique index on code and name',\n"
372+
+ "UNIQUE KEY inx_id_code_name (id,code,name) USING BTREE COMMENT 'index 1',\n"
373+
+ "SPATIAL KEY SPATIAL_geo (geo),\n"
374+
+ "KEY NORMAL_name (name) COMMENT 'normal index',\n"
375+
+ "FULLTEXT KEY fulltext_name (name)\n"
376+
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='test table'";
377+
assertSqlCanBeParsedAndDeparsed(sql);
378+
}
379+
355380
@Test
356381
public void testCreateTableWithCheck() throws JSQLParserException {
357382
assertSqlCanBeParsedAndDeparsed(

0 commit comments

Comments
 (0)