boolean includeOpenOption0;
try {
final String createTableStatements = schemaTextArea.getText();
String sqlSource = queryTextArea.getText();
final Schema databaseSchema = Schemas.fromDDL(createTableStatements);
// TODO show a meaningful error message if syntax error in the CREATE TABLE statement, e.g.,
// duplicate table names
// TODO show a meaningful error message if the CREATE TABLE statements are broken
// TODO extract the code that parses the schema and the query from the two translateAnd* functions
List<String> queries = Lists.newArrayList();
List<Term> formulas = Lists.newArrayList();
List<Term> inputTables = Lists.newArrayList();
final List<Result> results = Lists.newArrayList();
declareTablesThenTranslate(sqlSource, databaseSchema, queries, formulas, inputTables);
Iterator<String> tableNamesIter = databaseSchema.tableNames().iterator();
for (Term inputTable : inputTables) {
// add input tables to {@link results} so that they get borders
// also add labels with column names
// TODO refactor this and move to QuietSpreadsheetLayout
Result result = inputTable.execute();
ColumnLabels labels = result.getLabels();
String tableName = tableNamesIter.next();
ColumnNamesImpl cn = databaseSchema.schemaTable(tableName);
ColumnIndexesImpl ci = cn.asColumnIndexesLookup();
Iterator<SimpleColumn> scs = ci.iterator();
for (Column c : result.getResultRelation()) {
SimpleColumn sc = scs.next();
labels.put(c, tableName+"."+sc.name());