Search in sources :

Example 1 with ParserException

use of net.sourceforge.sqlexplorer.parsers.ParserException 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();
    }
}
Also used : ParserException(net.sourceforge.sqlexplorer.parsers.ParserException) QueryParser(net.sourceforge.sqlexplorer.parsers.QueryParser) AbstractSQLExecution(net.sourceforge.sqlexplorer.sqlpanel.AbstractSQLExecution) SQLExecution(net.sourceforge.sqlexplorer.sqlpanel.SQLExecution) AbstractSQLExecution(net.sourceforge.sqlexplorer.sqlpanel.AbstractSQLExecution) Session(net.sourceforge.sqlexplorer.dbproduct.Session)

Example 2 with ParserException

use of net.sourceforge.sqlexplorer.parsers.ParserException 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);
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ParserException(net.sourceforge.sqlexplorer.parsers.ParserException) Query(net.sourceforge.sqlexplorer.parsers.Query) Message(net.sourceforge.sqlexplorer.plugin.editors.Message) DataSet(net.sourceforge.sqlexplorer.dataset.DataSet) SQLException(java.sql.SQLException) SQLConnection(net.sourceforge.sqlexplorer.dbproduct.SQLConnection) IOException(java.io.IOException) LinkedList(java.util.LinkedList) DatabaseProduct(net.sourceforge.sqlexplorer.dbproduct.DatabaseProduct) QueryParser(net.sourceforge.sqlexplorer.parsers.QueryParser) FileReader(java.io.FileReader) File(java.io.File)

Example 3 with ParserException

use of net.sourceforge.sqlexplorer.parsers.ParserException 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) {
    }
}
Also used : ParserException(net.sourceforge.sqlexplorer.parsers.ParserException) QueryParser(net.sourceforge.sqlexplorer.parsers.QueryParser) SQLException(java.sql.SQLException) Statement(java.sql.Statement) SQLConnection(net.sourceforge.sqlexplorer.dbproduct.SQLConnection) ResultSet(java.sql.ResultSet) SQLException(java.sql.SQLException) ParserException(net.sourceforge.sqlexplorer.parsers.ParserException) Session(net.sourceforge.sqlexplorer.dbproduct.Session)

Aggregations

ParserException (net.sourceforge.sqlexplorer.parsers.ParserException)3 QueryParser (net.sourceforge.sqlexplorer.parsers.QueryParser)3 SQLException (java.sql.SQLException)2 SQLConnection (net.sourceforge.sqlexplorer.dbproduct.SQLConnection)2 Session (net.sourceforge.sqlexplorer.dbproduct.Session)2 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 LinkedList (java.util.LinkedList)1 DataSet (net.sourceforge.sqlexplorer.dataset.DataSet)1 DatabaseProduct (net.sourceforge.sqlexplorer.dbproduct.DatabaseProduct)1 Query (net.sourceforge.sqlexplorer.parsers.Query)1 Message (net.sourceforge.sqlexplorer.plugin.editors.Message)1 AbstractSQLExecution (net.sourceforge.sqlexplorer.sqlpanel.AbstractSQLExecution)1 SQLExecution (net.sourceforge.sqlexplorer.sqlpanel.SQLExecution)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1