public void testSubSelect() {
SQLGenerator gen = getSQLGenerator();
Table table = getComposedKeyTable();
Table otherTable = table.getSchema().newTable("OtherTable");
Column otherIndex = otherTable.newColumn("MyIndex", Column.Type.INTEGER);
otherTable.newPrimaryKey().addColumn(otherIndex);
ForeignKey foreignKey = otherTable.newForeignKey(table);
SelectStatement selectStatement = sqlFactory.newSelectStatement();
selectStatement.setTable(otherTable);
DeleteStatement deleteStatement = sqlFactory.newDeleteStatement();
deleteStatement.setTable(table);
List columns = new ArrayList();
for (Iterator iter = table.getColumns(); iter.hasNext(); ) {
Column column = (Column) iter.next();
Column refColumn = otherTable.newColumn("Ref" + column.getName(), column.getType());
foreignKey.addColumnLink(refColumn, column);
if (column.isPrimaryKeyPart()) {
selectStatement.addResultColumn(selectStatement.getTableReference().newColumnReference(refColumn));
columns.add(deleteStatement.getTableReference().newColumnReference(column));
}