Skip to content

Commit

Permalink
bugfix: parse error for 'alter table xx comment 'xx''
Browse files Browse the repository at this point in the history
  • Loading branch information
yakolee committed Mar 5, 2014
1 parent 161771d commit 987458f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2383,7 +2383,14 @@ public SQLStatement parseAlter() {
item.setCollate(this.exprParser.primary());
}
stmt.getItems().add(item);
} else {
} else if (lexer.token() == Token.COMMENT) {
lexer.nextToken();
if(lexer.token() == Token.EQ) {
accept(Token.EQ);
}
stmt.getItems().add(new MySqlAlterTableOption("COMMENT", '\'' + lexer.stringVal() + '\''));
lexer.nextToken();
}else {
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.alibaba.druid.bvt.sql.mysql;

import org.junit.Assert;

import junit.framework.TestCase;

import com.alibaba.druid.sql.SQLUtils;
Expand Down Expand Up @@ -70,4 +71,13 @@ public void test_alter_4() throws Exception {
Assert.assertEquals("ALTER TABLE `test`.`tb1`\n\tCOLLATE = utf8_general_ci,\n\tPACK_KEYS = PACK ALL,\n\tENGINE = InnoDB", output);
}

public void test_alter_5() throws Exception {
String sql = "ALTER TABLE t1 COMMENT '表的注释';";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("ALTER TABLE t1\n\tCOMMENT = '表的注释'", output);
}

}

0 comments on commit 987458f

Please sign in to comment.