use of net.sourceforge.sqlexplorer.parsers.QueryParser in project tdq-studio-se by Talend.
the class ExecSQLAction method run.
protected void run(int maxRows) {
Session session = getSession();
if (session == null)
return;
QueryParser qt = session.getDatabaseProduct().getQueryParser(_editor.getSQLToBeExecuted(), _editor.getSQLLineNumber());
try {
qt.parse();
} catch (final ParserException e) {
_editor.getSite().getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
MessageDialog.openError(_editor.getSite().getShell(), Messages.getString("SQLResultsView.Error.Title"), e.getMessage());
}
});
}
if (qt.iterator().hasNext()) {
boolean clearResults = SQLExplorerPlugin.getDefault().getPreferenceStore().getBoolean(IConstants.CLEAR_RESULTS_ON_EXECUTE);
if (clearResults)
_editor.clearResults();
AbstractSQLExecution job = new SQLExecution(_editor, qt, maxRows);
job.schedule();
}
}
use of net.sourceforge.sqlexplorer.parsers.QueryParser 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);
}
use of net.sourceforge.sqlexplorer.parsers.QueryParser in project tdq-studio-se by Talend.
the class ExplainAction2 method run.
public void run() {
try {
Session session;
SQLConnection connection;
Statement stmt;
ResultSet rs;
session = getSession();
if (session == null)
return;
connection = null;
stmt = null;
rs = null;
boolean createPlanTable;
boolean notFoundTable;
connection = session.grabConnection();
Statement st = connection.createStatement();
createPlanTable = false;
notFoundTable = true;
try {
rs = st.executeQuery("select statement_id from plan_table");
notFoundTable = false;
rs.close();
rs = null;
} catch (SQLException _ex) {
createPlanTable = MessageDialog.openQuestion(null, Messages.getString("oracle.editor.actions.explain.notFound.Title"), Messages.getString("oracle.editor.actions.explain.notFound"));
}
st.close();
st = null;
if (notFoundTable && !createPlanTable) {
if (rs != null)
try {
rs.close();
} catch (SQLException e) {
SQLExplorerPlugin.error("Cannot close result set", e);
}
if (stmt != null)
try {
stmt.close();
} catch (SQLException e) {
SQLExplorerPlugin.error("Cannot close statement", e);
}
if (connection != null)
session.releaseConnection(connection);
return;
}
try {
if (notFoundTable && createPlanTable) {
st = connection.createStatement();
st.execute("CREATE TABLE PLAN_TABLE ( STATEMENT_ID VARCHAR2(30), TIMESTAMP DATE, REMARKS VARCHAR2(80), OPERATION VARCHAR2(30), OPTIONS VARCHAR2(30), OBJECT_NODE VARCHAR2(128), OBJECT_OWNER VARCHAR2(30), OBJECT_NAME VARCHAR2(30), OBJECT_INSTANCE NUMBER(38), OBJECT_TYPE VARCHAR2(30), OPTIMIZER VARCHAR2(255), SEARCH_COLUMNS NUMBER, ID NUMBER(38), PARENT_ID NUMBER(38), POSITION NUMBER(38), COST NUMBER(38), CARDINALITY NUMBER(38), BYTES NUMBER(38), OTHER_TAG VARCHAR2(255), PARTITION_START VARCHAR2(255), PARTITION_STOP VARCHAR2(255), PARTITION_ID NUMBER(38), OTHER LONG, DISTRIBUTION VARCHAR2(30))");
st.close();
st = null;
}
QueryParser qt = session.getDatabaseProduct().getQueryParser(_editor.getSQLToBeExecuted(), _editor.getSQLLineNumber());
qt.parse();
(new ExplainExecution(_editor, qt)).schedule();
} catch (SQLException e) {
SQLExplorerPlugin.error("Error creating explain plan", e);
} catch (ParserException e) {
SQLExplorerPlugin.error("Cannot parse query", e);
}
if (rs != null)
try {
rs.close();
} catch (SQLException e) {
SQLExplorerPlugin.error("Cannot close result set", e);
}
if (stmt != null)
try {
stmt.close();
} catch (SQLException e) {
SQLExplorerPlugin.error("Cannot close statement", e);
}
if (connection != null)
session.releaseConnection(connection);
if (rs != null)
try {
rs.close();
} catch (SQLException e) {
SQLExplorerPlugin.error("Cannot close result set", e);
}
if (stmt != null)
try {
stmt.close();
} catch (SQLException e) {
SQLExplorerPlugin.error("Cannot close statement", e);
}
if (connection != null)
session.releaseConnection(connection);
} catch (Exception e) {
}
}
Aggregations