accept(Token.ALTER);
if (lexer.token() == Token.TABLE) {
lexer.nextToken();
SQLAlterTableStatement stmt = new SQLAlterTableStatement();
stmt.setName(this.exprParser.name());
for (;;) {
if (lexer.token() == Token.DROP) {
parseAlterDrop(stmt);
} else if (identifierEquals("ADD")) {
lexer.nextToken();
if (lexer.token() == Token.PRIMARY) {
SQLPrimaryKey primaryKey = this.exprParser.parsePrimaryKey();
SQLAlterTableAddConstraint item = new SQLAlterTableAddConstraint(primaryKey);
stmt.getItems().add(item);
} else if (lexer.token() == Token.IDENTIFIER) {
SQLAlterTableAddColumn item = parseAlterTableAddColumn();
stmt.getItems().add(item);
} else {
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
}
} else if (lexer.token() == Token.DISABLE) {
lexer.nextToken();
if (lexer.token() == Token.CONSTRAINT) {
lexer.nextToken();
SQLAlterTableDisableConstraint item = new SQLAlterTableDisableConstraint();
item.setConstraintName(this.exprParser.name());
stmt.getItems().add(item);
} else {
acceptIdentifier("KEYS");
SQLAlterTableDisableKeys item = new SQLAlterTableDisableKeys();
stmt.getItems().add(item);
}
} else if (lexer.token() == Token.ENABLE) {
lexer.nextToken();
if (lexer.token() == Token.CONSTRAINT) {
lexer.nextToken();
SQLAlterTableEnableConstraint item = new SQLAlterTableEnableConstraint();
item.setConstraintName(this.exprParser.name());
stmt.getItems().add(item);
} else {
acceptIdentifier("KEYS");
SQLAlterTableEnableKeys item = new SQLAlterTableEnableKeys();
stmt.getItems().add(item);
}
} else if (lexer.token() == Token.ALTER) {
lexer.nextToken();
if (lexer.token() == Token.COLUMN) {
lexer.nextToken();
SQLColumnDefinition column = this.exprParser.parseColumn();
SQLAlterTableAlterColumn alterColumn = new SQLAlterTableAlterColumn();
alterColumn.setColumn(column);
stmt.getItems().add(alterColumn);
} else {
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
}
} else if (lexer.token() == Token.WITH) {
lexer.nextToken();
acceptIdentifier("NOCHECK");
acceptIdentifier("ADD");
SQLConstraint check = this.exprParser.parseConstaint();
SQLAlterTableAddConstraint addCheck = new SQLAlterTableAddConstraint();
addCheck.setWithNoCheck(true);
addCheck.setConstraint(check);
stmt.getItems().add(addCheck);
} else {
break;
}
}