private void handleSelect() throws SqlJetException {
// SELECT starts with a tree of SELECT_CORE statements
// For now we support only single SELECT_CORE
CommonTree selectCore = (CommonTree) ast.getChild(0);
if (!"select_core".equalsIgnoreCase(selectCore.getText())) {
throw new SqlJetException(SqlJetErrorCode.ERROR, "Compound select is not supported yet.");
}
int i = 0;
CommonTree child = (CommonTree) selectCore.getChild(i++);
// SELECT_CORE may start with DISTINCT
boolean distinct = false;
if ("distinct".equalsIgnoreCase(child.getText())) {
distinct = true;
child = (CommonTree) selectCore.getChild(i++);
}
if (distinct) {
throw new SqlJetException(SqlJetErrorCode.ERROR, "Distinct select modifier is not supported yet.");
}
// All columns are grouped by RESULT_COLUMNS
// For now we support only *
assert "columns".equalsIgnoreCase(child.getText());
if (child.getChildCount() != 1 && !"*".equals(child.getChild(0).getText())) {
throw new SqlJetException(SqlJetErrorCode.ERROR, "Can select only * for now.");
}
child = (CommonTree) selectCore.getChild(i++);
// We require FROM to refer to a single table
if (!"from".equalsIgnoreCase(child.getText())) {
throw new SqlJetException(SqlJetErrorCode.ERROR, "Select source should be specified.");
}
child = (CommonTree) child.getChild(0);
if (!"alias".equalsIgnoreCase(child.getText())) {
throw new SqlJetException(SqlJetErrorCode.ERROR, "Compound select source is not supported yet.");
}
child = (CommonTree) child.getChild(0);
if ("select".equalsIgnoreCase(child.getText())) {
throw new SqlJetException(SqlJetErrorCode.ERROR, "Select as select source is not supported yet.");
}
String tableName = child.getText();
if (selectCore.getChildCount() > i) {
throw new SqlJetException(SqlJetErrorCode.ERROR, "Unsupported select syntax.");
}
table = db.getTable(tableName);
if (table != null) {
cursor = table.open();
}