use of net.sourceforge.sqlexplorer.dbstructure.nodes.ColumnNode in project tdq-studio-se by Talend.
the class GenerateSelectSQLAction method run.
/**
* Generate select statement
*
* @see org.eclipse.jface.action.IAction#run()
*/
@Override
public void run() {
try {
String query = null;
if (_selectedNodes[0] instanceof ColumnNode) {
query = createColumnSelect();
}
if (_selectedNodes[0] instanceof TableNode) {
query = createTableSelect();
}
if (query == null) {
return;
}
SQLEditorInput input = new SQLEditorInput(// $NON-NLS-1$
"SQL Editor (" + SQLExplorerPlugin.getDefault().getEditorSerialNo() + // $NON-NLS-1$
").sql");
input.setUser(_selectedNodes[0].getSession().getUser());
IWorkbenchPage page = SQLExplorerPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
SQLEditor editorPart = (SQLEditor) page.openEditor(input, SQLEditor.class.getName());
editorPart.setText(query);
} catch (Throwable e) {
SQLExplorerPlugin.error("Could generate sql.", e);
}
}
use of net.sourceforge.sqlexplorer.dbstructure.nodes.ColumnNode in project tdq-studio-se by Talend.
the class GenerateSelectSQLAction method createColumnSelect.
/**
* @return query string for full table select
*/
private String createColumnSelect() {
// $NON-NLS-1$
StringBuffer query = new StringBuffer("select ");
// $NON-NLS-1$
String sep = "";
// $NON-NLS-1$
String table = "";
for (INode node : _selectedNodes) {
if (node instanceof ColumnNode) {
ColumnNode column = (ColumnNode) node;
if (table.length() == 0) {
table = column.getQualifiedParentTableName();
}
if (column.getQualifiedParentTableName().equals(table)) {
query.append(sep);
query.append(quote(column.getName(), getQuoteString(column)));
// $NON-NLS-1$
sep = ", ";
}
}
}
// $NON-NLS-1$
query.append(" from ");
query.append(fixTableName(table));
return query.toString();
}
Aggregations