private String getTableAlteredSql(String sql, SqlJetAlterTableDef alterTableDef) throws SqlJetException {
final RuleReturnScope parsedSQL = parseTable(sql);
final CommonTree ast = (CommonTree) parsedSQL.getTree();
final CommonToken nameToken = (CommonToken) ((CommonTree) ast.getChild(1)).getToken();
final CharStream inputStream = nameToken.getInputStream();
final CommonToken stopToken = (CommonToken) parsedSQL.getStop();
final StringBuilder b = new StringBuilder();
if (alterTableDef.getNewTableName() != null) {
b.append(inputStream.substring(0, nameToken.getStartIndex() - 1));
b.append(getAlterTableName(alterTableDef));
b.append(inputStream.substring(nameToken.getStopIndex() + 1, stopToken.getStopIndex()));
} else if (alterTableDef.getNewColumnDef() != null) {
b.append(inputStream.substring(0, stopToken.getStartIndex() - 1));
b.append(",").append(getAlterTableName(alterTableDef));
b.append(inputStream.substring(stopToken.getStartIndex(), stopToken.getStopIndex()));
} else {
throw new SqlJetException("Wrong ALTER TABLE statement");
}
return b.toString();