mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
fix SQL SERVER ALTER TABLE ADD COLUMN BUG.
This commit is contained in:
@@ -2494,6 +2494,9 @@ public class SQLStatementParser extends SQLParser {
|
||||
SQLConstraint constraint = this.exprParser.parseConstaint();
|
||||
SQLAlterTableAddConstraint item = new SQLAlterTableAddConstraint(constraint);
|
||||
stmt.addItem(item);
|
||||
} else if (lexer.token == LITERAL_ALIAS && dbType == DbType.sqlserver) {
|
||||
SQLAlterTableAddColumn item = parseAlterTableAddColumn();
|
||||
stmt.addItem(item);
|
||||
} else {
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.alibaba.druid.sql.parser;
|
||||
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser;
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
|
||||
/**
|
||||
* Created by zyc@byshell.org on 2016/8/16.
|
||||
*/
|
||||
public class SqlserverAlterTest extends TestCase {
|
||||
public void testAlter1() {
|
||||
String sql = "alter table alert_config_detail\n" + " add age14 int";
|
||||
SQLStatementParser parser = new SQLServerStatementParser(sql);
|
||||
SQLAlterTableStatement stmt = (SQLAlterTableStatement) parser.parseStatement(); //
|
||||
try {
|
||||
stmt.toString();
|
||||
} catch (ClassCastException e) {
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testAlter2() {
|
||||
String sql = "ALTER TABLE \"console\".\"dbo\".\"alert_config_detail\"\n" + "\tADD \"age14\" int";
|
||||
SQLStatementParser parser = new SQLServerStatementParser(sql);
|
||||
SQLAlterTableStatement stmt = (SQLAlterTableStatement) parser.parseStatement(); //
|
||||
try {
|
||||
stmt.toString();
|
||||
} catch (ClassCastException e) {
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user