mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for mysql create table parser. for issue #2082
This commit is contained in:
@@ -2675,7 +2675,7 @@ public class SQLExprParser extends SQLParser {
|
||||
lexer.nextToken();
|
||||
accept(Token.NULL);
|
||||
option = SQLForeignKeyImpl.Option.SET_NULL;
|
||||
} else if (lexer.token() == Token.ON || lexer.identifierEquals(FnvHash.Constants.ON)) {
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.NO)) {
|
||||
lexer.nextToken();
|
||||
if (lexer.identifierEquals(FnvHash.Constants.ACTION)) {
|
||||
option = SQLForeignKeyImpl.Option.NO_ACTION;
|
||||
|
||||
@@ -633,5 +633,6 @@ public final class FnvHash {
|
||||
|
||||
long TBLPROPERTIES = fnv1a_64_lower("TBLPROPERTIES");
|
||||
long FULLTEXT = fnv1a_64_lower("FULLTEXT");
|
||||
long NO = fnv1a_64_lower("NO");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.alibaba.druid.bvt.sql.mysql.createTable;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlCreateTableTest97 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "CREATE TABLE `gsp_order` (\n" +
|
||||
" `id` int(11) NOT NULL AUTO_INCREMENT,\n" +
|
||||
" `spare_num` int(11) NOT NULL COMMENT '????',\n" +
|
||||
" `coupon` decimal(11,2) NOT NULL DEFAULT '0.00' COMMENT '????',\n" +
|
||||
" `remark` varchar(255) DEFAULT NULL COMMENT '??',\n" +
|
||||
" `creator_id` int(11) NOT NULL COMMENT '???ID',\n" +
|
||||
" `last_operator` varchar(16) DEFAULT NULL COMMENT '???????',\n" +
|
||||
" `createtime` datetime NOT NULL COMMENT '????',\n" +
|
||||
" `updatetime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '????????',\n" +
|
||||
" `is_del` tinyint(1) NOT NULL DEFAULT '0' COMMENT '?????0????1?????',\n" +
|
||||
" PRIMARY KEY (`id`),\n" +
|
||||
" KEY `creator_id` (`creator_id`),\n" +
|
||||
" KEY `id` (`id`,`is_del`),\n" +
|
||||
" KEY `order_id` (`order_id`),\n" +
|
||||
" CONSTRAINT `gsp_order2_details_ibfk_2` FOREIGN KEY (`creator_id`) REFERENCES `gsp_sys_users` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION\n" +
|
||||
") ENGINE=InnoDB AUTO_INCREMENT=84608 DEFAULT CHARSET=utf8";
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
MySqlCreateTableStatement stmt = (MySqlCreateTableStatement)statementList.get(0);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
assertEquals(14, stmt.getTableElementList().size());
|
||||
|
||||
assertEquals("CREATE TABLE `gsp_order` (\n" +
|
||||
"\t`id` int(11) NOT NULL AUTO_INCREMENT,\n" +
|
||||
"\t`spare_num` int(11) NOT NULL COMMENT '????',\n" +
|
||||
"\t`coupon` decimal(11, 2) NOT NULL DEFAULT '0.00' COMMENT '????',\n" +
|
||||
"\t`remark` varchar(255) DEFAULT NULL COMMENT '??',\n" +
|
||||
"\t`creator_id` int(11) NOT NULL COMMENT '???ID',\n" +
|
||||
"\t`last_operator` varchar(16) DEFAULT NULL COMMENT '???????',\n" +
|
||||
"\t`createtime` datetime NOT NULL COMMENT '????',\n" +
|
||||
"\t`updatetime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '????????',\n" +
|
||||
"\t`is_del` tinyint(1) NOT NULL DEFAULT '0' COMMENT '?????0????1?????',\n" +
|
||||
"\tPRIMARY KEY (`id`),\n" +
|
||||
"\tKEY `creator_id` (`creator_id`),\n" +
|
||||
"\tKEY `id` (`id`, `is_del`),\n" +
|
||||
"\tKEY `order_id` (`order_id`),\n" +
|
||||
"\tCONSTRAINT `gsp_order2_details_ibfk_2` FOREIGN KEY (`creator_id`) REFERENCES `gsp_sys_users` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION\n" +
|
||||
") ENGINE = InnoDB AUTO_INCREMENT = 84608 CHARSET = utf8", stmt.toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user