mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved mysql parser support alter db. for issue #2258
This commit is contained in:
@@ -53,7 +53,6 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
private static final String ENGINE = "ENGINE";
|
||||
private static final String BINLOG = "BINLOG";
|
||||
private static final String EVENTS = "EVENTS";
|
||||
private static final String CHARACTER = "CHARACTER";
|
||||
private static final String SESSION = "SESSION";
|
||||
private static final String GLOBAL = "GLOBAL";
|
||||
private static final String VARIABLES = "VARIABLES";
|
||||
@@ -1311,7 +1310,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
return new MySqlShowMasterStatusStatement();
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(CHARACTER)) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.CHARACTER)) {
|
||||
lexer.nextToken();
|
||||
accept(Token.SET);
|
||||
MySqlShowCharacterSetStatement stmt = new MySqlShowCharacterSetStatement();
|
||||
@@ -2171,7 +2170,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
SQLName tableName = exprParser.name();
|
||||
stmt.setTableName(tableName);
|
||||
|
||||
if (lexer.identifierEquals(CHARACTER)) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.CHARACTER)) {
|
||||
lexer.nextToken();
|
||||
accept(Token.SET);
|
||||
|
||||
@@ -2245,7 +2244,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
SQLName tableName = exprParser.name();
|
||||
stmt.setTableName(tableName);
|
||||
|
||||
if (lexer.identifierEquals(CHARACTER)) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.CHARACTER)) {
|
||||
lexer.nextToken();
|
||||
accept(Token.SET);
|
||||
|
||||
@@ -3693,7 +3692,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
stmt.addItem(item);
|
||||
} else if (lexer.token() == Token.DEFAULT) {
|
||||
lexer.nextToken();
|
||||
if (lexer.identifierEquals(CHARACTER)) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.CHARACTER)) {
|
||||
SQLAlterCharacter item = alterTableCharacter();
|
||||
stmt.addItem(item);
|
||||
} else {
|
||||
@@ -3887,7 +3886,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
stmt.addItem(new MySqlAlterTableOption("PACK_KEYS", lexer.stringVal()));
|
||||
lexer.nextToken();
|
||||
}
|
||||
} else if (lexer.identifierEquals(CHARACTER)) {
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.CHARACTER)) {
|
||||
SQLAlterCharacter item = alterTableCharacter();
|
||||
stmt.addItem(item);
|
||||
} else if (lexer.token() == Token.COMMENT) {
|
||||
@@ -4187,7 +4186,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
accept(Token.DATABASE);
|
||||
}
|
||||
|
||||
SQLAlterDatabaseStatement stmt = new SQLAlterDatabaseStatement();
|
||||
SQLAlterDatabaseStatement stmt = new SQLAlterDatabaseStatement(dbType);
|
||||
|
||||
SQLName name = this.exprParser.name();
|
||||
stmt.setName(name);
|
||||
@@ -4202,12 +4201,17 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
|
||||
if (lexer.token() == Token.DEFAULT) {
|
||||
lexer.nextToken();
|
||||
if (lexer.identifierEquals(CHARACTER)) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.CHARACTER)) {
|
||||
SQLAlterCharacter item = alterTableCharacter();
|
||||
stmt.setCharacter(item);
|
||||
} else {
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.CHARACTER)) {
|
||||
SQLAlterCharacter item = alterTableCharacter();
|
||||
stmt.setCharacter(item);
|
||||
} else {
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
|
||||
return stmt;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.alter;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class MySqlAlterDbTest1 extends TestCase {
|
||||
|
||||
public void test_alter_first() throws Exception {
|
||||
String sql = "alter database test CHARACTER SET='big5' COLLATE='big5_chinese_ci'";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
|
||||
assertEquals("ALTER DATABASE test CHARACTER SET = 'big5' COLLATE big5_chinese_ci", SQLUtils.toMySqlString(stmt));
|
||||
assertEquals("alter database test character set = 'big5' collate big5_chinese_ci", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user