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();
}
Aggregations