public SqlJetAlterTableDef(ParserRuleReturnScope parsedSql) throws SqlJetException {
this.parsedSql = parsedSql;
final CommonTree ast = (CommonTree)parsedSql.getTree();
final int childCount = ast.getChildCount();
if (childCount < 5) {
throw new SqlJetException(SqlJetErrorCode.MISUSE, INVALID_ALTER_TABLE_STATEMENT);
}
final CommonTree alterNode = (CommonTree) ast.getChild(0);
final CommonTree tableNode = (CommonTree) ast.getChild(1);
if (!"alter".equalsIgnoreCase(alterNode.getText()) || !"table".equalsIgnoreCase(tableNode.getText())) {
throw new SqlJetException(SqlJetErrorCode.MISUSE, INVALID_ALTER_TABLE_STATEMENT);
}
final CommonTree tableNameNode = (CommonTree) ast.getChild(2);
tableName = tableNameNode.getText();
final CommonTree actionNode = (CommonTree) ast.getChild(3);
final String action = actionNode.getText();
final CommonTree child = (CommonTree) ast.getChild(4);
if ("add".equalsIgnoreCase(action)) {
newTableName = null;
final CommonTree newColumnNode;
if ("column".equalsIgnoreCase(child.getText())) {
if (childCount != 6) {
throw new SqlJetException(SqlJetErrorCode.MISUSE, INVALID_ALTER_TABLE_STATEMENT);
}
newColumnNode = (CommonTree) ast.getChild(5);
} else {
if (childCount != 5) {
throw new SqlJetException(SqlJetErrorCode.MISUSE, INVALID_ALTER_TABLE_STATEMENT);
}
newColumnNode = child;
}
newColumnDef = new SqlJetColumnDef(newColumnNode);
} else if ("rename".equalsIgnoreCase(action)) {
newColumnDef = null;
assert ("to".equalsIgnoreCase(child.getText()));
if (childCount < 6) {
throw new SqlJetException(SqlJetErrorCode.MISUSE, INVALID_ALTER_TABLE_STATEMENT);
}
final CommonTree newTableNode = (CommonTree) ast.getChild(5);
newTableName = newTableNode.getText();
} else {
newTableName = null;
newColumnDef = null;
throw new SqlJetException(SqlJetErrorCode.MISUSE, INVALID_ALTER_TABLE_STATEMENT);
}
}