use of net.sourceforge.sqlexplorer.dataset.DataSet in project tdq-studio-se by Talend.
the class ExportedKeysTab method getDataSet.
public DataSet getDataSet() throws Exception {
INode node = getNode();
if (node == null) {
return null;
}
if (node instanceof TableNode) {
TableNode tableNode = (TableNode) node;
ResultSet resultSet = node.getSession().getMetaData().getExportedKeys(tableNode.getTableInfo());
DataSet dataSet = new DataSet(resultSet, new int[] { 4, 7, 8, 9, 10, 11, 12, 13, 14 });
resultSet.close();
return dataSet;
}
return null;
}
use of net.sourceforge.sqlexplorer.dataset.DataSet in project tdq-studio-se by Talend.
the class ColumnInfoTab method getDataSet.
@Override
public DataSet getDataSet() {
INode node = getNode();
if (node == null) {
return null;
}
if (node instanceof TableNode) {
TableNode tableNode = (TableNode) node;
DataSet dataSet = null;
// something(.e.g,ResultSetColumnReader.getLong(16))
try {
TableColumnInfo[] cols = node.getSession().getMetaData().getColumnInfo(tableNode.getTableInfo());
Comparable[][] dataRows = new Comparable[cols.length][];
int index = 0;
for (TableColumnInfo col : cols) {
Comparable[] row = new Comparable[COLUMN_LABELS.length];
dataRows[index++] = row;
int i = 0;
row[i++] = col.getColumnName();
row[i++] = col.getDataType();
row[i++] = col.getTypeName();
row[i++] = col.getColumnSize();
row[i++] = col.getDecimalDigits();
row[i++] = col.getRadix();
row[i++] = col.isNullAllowed();
row[i++] = col.getRemarks();
row[i++] = col.getDefaultValue();
row[i++] = col.getOctetLength();
row[i++] = col.getOrdinalPosition();
row[i++] = col.isNullable();
if (i != COLUMN_LABELS.length) {
throw new RuntimeException(Messages.getString("ColumnInfoTab.runtimeException"));
}
}
dataSet = new DataSet(COLUMN_LABELS, dataRows);
} catch (Exception e) {
SQLExplorerPlugin.error(Messages.getString("AbstractDataSetTab.error"), e);
boolean isODBCTeradata = false;
try {
isODBCTeradata = ConnectionUtils.isOdbcTeradata(node.getSession().getMetaData().getJDBCMetaData()) ? true : false;
} catch (SQLException e1) {
SQLExplorerPlugin.error("Failed to get the type of Database", e);
}
if (isODBCTeradata) {
MessageDialog.openError(Display.getDefault().getActiveShell(), "unsupported", "This operation is unsupported by ODBC Teradata in SQLExplorer!");
}
}
return dataSet;
}
return null;
}
use of net.sourceforge.sqlexplorer.dataset.DataSet in project tdq-studio-se by Talend.
the class SQLExecution method doExecution.
protected void doExecution(IProgressMonitor monitor) throws Exception {
int numErrors = 0;
SQLException lastSQLException = null;
try {
long overallUpdateCount = 0;
long overallStartTime = System.currentTimeMillis();
for (Query query : getQueryParser()) {
if (monitor.isCanceled())
break;
if (getEditor().isClosed())
break;
// Get the next bit of SQL to run and store it as "current"
if (query == null)
break;
String querySQL = query.getQuerySql().toString();
if (querySQL == null)
continue;
// Initialise
setProgressMessage(Messages.getString("SQLResultsView.Executing"));
final long startTime = System.currentTimeMillis();
// Run it
DatabaseProduct.ExecutionResults results = null;
try {
DatabaseProduct product = getEditor().getSession().getDatabaseProduct();
try {
results = product.executeQuery(_connection, query, _maxRows);
} catch (RuntimeException e) {
throw new SQLException(e.getMessage());
}
final long endTime = System.currentTimeMillis();
DataSet dataSet;
boolean checkedForMessages = false;
while ((dataSet = results.nextDataSet()) != null) {
// update sql result
SQLResult sqlResult = new SQLResult();
sqlResult.setQuery(query);
sqlResult.setDataSet(dataSet);
sqlResult.setExecutionTimeMillis(endTime - startTime);
// Save successfull query
SQLExplorerPlugin.getDefault().getSQLHistory().addSQL(querySQL, _session);
if (monitor.isCanceled())
return;
checkForMessages(query);
checkedForMessages = true;
// show results..
displayResults(sqlResult);
}
overallUpdateCount += results.getUpdateCount();
if (!checkedForMessages)
checkForMessages(query);
debugLogQuery(query, null);
} catch (final SQLException e) {
debugLogQuery(query, e);
boolean stopOnError = SQLExplorerPlugin.getDefault().getPreferenceStore().getBoolean(IConstants.STOP_ON_ERROR);
logException(e, query, stopOnError);
closeStatement();
hasMessages = true;
if (stopOnError) {
errorDialog(Messages.getString("SQLResultsView.Error.Title"), e.getMessage());
return;
}
numErrors++;
lastSQLException = e;
} finally {
try {
if (results != null) {
results.close();
results = null;
}
} catch (SQLException e) {
// Nothing
}
}
}
if (!hasMessages || SQLExplorerPlugin.getDefault().getPreferenceStore().getBoolean(IConstants.LOG_SUCCESS_MESSAGES)) {
long overallTime = System.currentTimeMillis() - overallStartTime;
String message = Long.toString(overallUpdateCount) + " " + Messages.getString("SQLEditor.Update.Prefix") + " " + Long.toString(overallTime) + " " + Messages.getString("SQLEditor.Update.Postfix");
addMessage(new Message(Message.Status.STATUS, getQueryParser().adjustLineNo(1), 0, "", message));
}
} catch (Exception e) {
closeStatement();
throw e;
}
if (numErrors == 1)
throw lastSQLException;
else if (numErrors > 1 && SQLExplorerPlugin.getDefault().getPreferenceStore().getBoolean(IConstants.CONFIRM_BOOL_SHOW_DIALOG_ON_QUERY_ERROR))
getEditor().getSite().getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
MessageDialogWithToggle dialog = MessageDialogWithToggle.openInformation(getEditor().getSite().getShell(), Messages.getString("SQLExecution.Error.Title"), Messages.getString("SQLExecution.Error.Message"), Messages.getString("SQLExecution.Error.Toggle"), false, null, null);
if (dialog.getToggleState() && dialog.getReturnCode() == IDialogConstants.OK_ID)
SQLExplorerPlugin.getDefault().getPluginPreferences().setValue(IConstants.CONFIRM_BOOL_SHOW_DIALOG_ON_QUERY_ERROR, false);
}
});
}
use of net.sourceforge.sqlexplorer.dataset.DataSet in project tdq-studio-se by Talend.
the class BatchJob method run.
@Override
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask(Messages.getString("BatchJob.ExecutingScripts"), files.size());
DatabaseProduct product = user.getAlias().getDriver().getDatabaseProduct();
SQLConnection connection = null;
try {
if (session == null)
session = user.createSession();
connection = session.grabConnection();
int index = 0;
for (File file : files) {
if (monitor.isCanceled())
break;
monitor.worked(index++);
monitor.subTask(file.getName());
_logger.fatal(file.getAbsolutePath());
String sql = null;
try {
char[] buffer = new char[(int) file.length() + 10];
FileReader reader = new FileReader(file);
int length = reader.read(buffer);
reader.close();
if (length < 0 || length >= buffer.length) {
SQLExplorerPlugin.error("Cannot read from file " + file.getAbsolutePath());
continue;
}
// Normalise this to have standard \n in strings. \r confuses Oracle and
// isn't normally needed internally anyway
StringBuffer sb = new StringBuffer(new String(buffer, 0, length));
buffer = null;
for (int i = 0; i < sb.length(); i++) {
if (sb.charAt(i) == '\r') {
sb.deleteCharAt(i);
i--;
}
}
sql = sb.toString();
sb = null;
} catch (IOException e) {
SQLExplorerPlugin.error("Cannot read from file " + file.getAbsolutePath(), e);
continue;
}
QueryParser parser = product.getQueryParser(sql, 1);
parser.parse();
for (Query query : parser) {
DatabaseProduct.ExecutionResults results = null;
try {
results = product.executeQuery(connection, query, -1);
DataSet dataSet;
while ((dataSet = results.nextDataSet()) != null) {
LinkedList<Message> messages = new LinkedList<Message>();
Collection<Message> messagesTmp = session.getDatabaseProduct().getErrorMessages(connection, query);
if (messagesTmp != null)
messages.addAll(messagesTmp);
messagesTmp = session.getDatabaseProduct().getServerMessages(connection);
if (messagesTmp != null)
messages.addAll(messagesTmp);
for (Message msg : messages) msg.setLineNo(parser.adjustLineNo(msg.getLineNo()));
for (Message message : messages) {
_logger.fatal(message.getSql());
}
}
} catch (SQLException e) {
_logger.fatal(e.getMessage());
} finally {
try {
if (results != null) {
results.close();
results = null;
}
} catch (SQLException e) {
// Nothing
}
}
}
}
monitor.done();
} catch (SQLException e) {
SQLExplorerPlugin.error(e);
} catch (ParserException e) {
SQLExplorerPlugin.error(e);
} finally {
if (connection != null)
session.releaseConnection(connection);
}
return new Status(IStatus.OK, getClass().getName(), IStatus.OK, Messages.getString("BatchJob.Success"), null);
}
Aggregations