mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Fix bug: Parse "national" keywords in DataType #3561
This commit is contained in:
@@ -2716,6 +2716,17 @@ public class SQLExprParser extends SQLParser {
|
||||
}
|
||||
}
|
||||
|
||||
if (typeNameHashCode == FnvHash.Constants.NATIONAL) {
|
||||
if (lexer.token == Token.IDENTIFIER) {
|
||||
String nationalName = lexer.stringVal();
|
||||
if ("varchar".equalsIgnoreCase(nationalName) || "char"
|
||||
.equalsIgnoreCase(nationalName)) {
|
||||
typeName = (" n" + lexer.stringVal().toLowerCase());
|
||||
lexer.nextToken();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isCharType(typeName)) {
|
||||
SQLCharacterDataType charType = new SQLCharacterDataType(typeName);
|
||||
|
||||
|
||||
@@ -415,6 +415,7 @@ public final class FnvHash {
|
||||
long GROUP_CONCAT = fnv1a_64_lower("GROUP_CONCAT");
|
||||
long DEDUPLICATION = fnv1a_64_lower("DEDUPLICATION");
|
||||
long CONVERT = fnv1a_64_lower("CONVERT");
|
||||
long NATIONAL = fnv1a_64_lower("NATIONAL");
|
||||
long CHAR = fnv1a_64_lower("CHAR");
|
||||
long VARCHAR = fnv1a_64_lower("VARCHAR");
|
||||
long VARCHAR2 = fnv1a_64_lower("VARCHAR2");
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Dagon0577
|
||||
* @date 2020/5/14 10:51
|
||||
*/
|
||||
public class MySqlCreateTableTest135 extends MysqlTest {
|
||||
public void test_0() throws Exception {
|
||||
String sql =
|
||||
"create table MQ_TOPIC_RECORD(\n"
|
||||
+ " TOPIC_ID bigint(11) not null,\n"
|
||||
+ " BROKENNAME national VARCHAR(50),\n"
|
||||
+ " BROKENNAME2 national CHAR(50)\n" + ");";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
MySqlCreateTableStatement stmt = (MySqlCreateTableStatement) statementList.get(0);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
|
||||
assertEquals("CREATE TABLE MQ_TOPIC_RECORD (\n"
|
||||
+ "\tTOPIC_ID bigint(11) NOT NULL,\n"
|
||||
+ "\tBROKENNAME nvarchar(50),\n"
|
||||
+ "\tBROKENNAME2 nchar(50)\n"
|
||||
+ ");", stmt.toString());
|
||||
|
||||
assertEquals("create table MQ_TOPIC_RECORD (\n"
|
||||
+ "\tTOPIC_ID bigint(11) not null,\n"
|
||||
+ "\tBROKENNAME nvarchar(50),\n"
|
||||
+ "\tBROKENNAME2 nchar(50)\n" + ");", stmt.toLowerCaseString());
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user