Search in sources :

Example 1 with ColumnProposalDetailInfo

use of com.cubrid.common.ui.query.editor.ColumnProposalDetailInfo in project cubrid-manager by CUBRID.

the class QuickBuilderDialog method makeQueryAndClose.

private void makeQueryAndClose(int type) {
    // FIXME move this logic to core module
    String tableName = getSelectedTable().trim();
    List<ColumnProposalDetailInfo> columns = null;
    String query = null;
    ColumnProposal proposal = ColumnProposalAdvisor.getInstance().findProposal(sqlComp.getQueryEditorPart().getSelectedDatabase().getDatabaseInfo());
    if (proposal != null) {
        columns = proposal.getColumns().get(tableName);
    }
    if (columns == null) {
        columns = new ArrayList<ColumnProposalDetailInfo>();
    }
    int cursorPosition = 0;
    if (type == 0) {
        query = "SELECT * FROM " + QuerySyntax.escapeKeyword(tableName) + " " + appendLimit() + ";" + StringUtil.NEWLINE;
        cursorPosition = query.length() - 1;
    } else if (type == 1) {
        StringBuilder col = new StringBuilder();
        if (columns != null) {
            for (ColumnProposalDetailInfo info : columns) {
                String column = info.getColumnName();
                if (col.length() > 0) {
                    col.append(", ");
                }
                col.append(QuerySyntax.escapeKeyword(column));
            }
        }
        query = "SELECT " + col.toString() + " FROM " + QuerySyntax.escapeKeyword(tableName) + " " + appendLimit() + ";" + StringUtil.NEWLINE;
        cursorPosition = query.length() - 1;
    } else if (type == 2) {
        StringBuilder col = new StringBuilder();
        StringBuilder col2 = new StringBuilder();
        if (columns != null) {
            for (ColumnProposalDetailInfo info : columns) {
                String column = info.getColumnName();
                if (col.length() > 0) {
                    col.append(", ");
                    col2.append(", ");
                }
                col.append(QuerySyntax.escapeKeyword(column));
                col2.append(column);
            }
        }
        query = "INSERT INTO " + QuerySyntax.escapeKeyword(tableName) + " (" + col.toString() + ") VALUES (" + col2.toString() + ");\n";
        cursorPosition = 14 + tableName.length() + col.length() + 10;
    } else if (type == 3) {
        StringBuilder col = new StringBuilder();
        if (columns != null) {
            for (ColumnProposalDetailInfo info : columns) {
                String column = info.getColumnName();
                if (col.length() > 0) {
                    col.append(", ");
                }
                col.append(QuerySyntax.escapeKeyword(column)).append("=");
            }
        }
        query = "UPDATE " + QuerySyntax.escapeKeyword(tableName) + " SET " + col.toString() + " WHERE ;" + StringUtil.NEWLINE;
        cursorPosition = 12 + tableName.length();
    }
    pasteIntoQueryEditor(query, cursorPosition);
    closeThisDialog();
}
Also used : ColumnProposal(com.cubrid.common.ui.query.editor.ColumnProposal) ColumnProposalDetailInfo(com.cubrid.common.ui.query.editor.ColumnProposalDetailInfo)

Aggregations

ColumnProposal (com.cubrid.common.ui.query.editor.ColumnProposal)1 ColumnProposalDetailInfo (com.cubrid.common.ui.query.editor.ColumnProposalDetailInfo)1