Search in sources :

Example 11 with DBGException

use of org.jkiss.dbeaver.debug.DBGException in project dbeaver by dbeaver.

the class PostgreDebugSession method setVariableVal.

@Override
public void setVariableVal(DBGVariable<?> variable, Object value) throws DBGException {
    acquireReadLock();
    try (PreparedStatement stmt = getConnection().prepareStatement(SQL_SET_VAR)) {
        if (variable instanceof PostgreDebugVariable) {
            if (value instanceof String) {
                PostgreDebugVariable var = (PostgreDebugVariable) variable;
                stmt.setInt(1, sessionId);
                stmt.setString(2, var.getName());
                stmt.setInt(3, var.getLinenumber());
                stmt.setString(4, (String) value);
                stmt.execute();
            } else {
                lock.readLock().unlock();
                throw new DBGException("Incorrect variable value class");
            }
        } else {
            lock.readLock().unlock();
            throw new DBGException("Incorrect variable class");
        }
    } catch (SQLException e) {
        throw new DBGException("SQL error", e);
    } finally {
        lock.readLock().unlock();
    }
}
Also used : DBGException(org.jkiss.dbeaver.debug.DBGException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement)

Example 12 with DBGException

use of org.jkiss.dbeaver.debug.DBGException in project dbeaver by dbeaver.

the class PostgreDebugController method getSessionDescriptors.

@Override
public List<PostgreDebugSessionInfo> getSessionDescriptors() throws DBGException {
    DBCExecutionContext executionContext = getExecutionContext();
    try (Statement stmt = getConnection(executionContext).createStatement();
        ResultSet rs = stmt.executeQuery(SQL_SESSION)) {
        List<PostgreDebugSessionInfo> res = new ArrayList<PostgreDebugSessionInfo>();
        while (rs.next()) {
            int pid = rs.getInt("pid");
            String usename = rs.getString("usename");
            String state = rs.getString("state");
            String applicationName = rs.getString("application_name");
            String query = rs.getString("query");
            PostgreDebugSessionInfo info = new PostgreDebugSessionInfo(pid, usename, applicationName, state, query);
            res.add(info);
        }
        return res;
    } catch (SQLException e) {
        throw new DBGException("SQL error", e);
    }
}
Also used : DBGException(org.jkiss.dbeaver.debug.DBGException) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) JDBCExecutionContext(org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext) SQLException(java.sql.SQLException) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList)

Example 13 with DBGException

use of org.jkiss.dbeaver.debug.DBGException in project dbeaver by dbeaver.

the class PostgreDebugSession method attachGlobal.

private void attachGlobal(int oid, int targetPID) throws DBGException {
    try (Statement stmt = getConnection().createStatement();
        ResultSet rs = stmt.executeQuery(SQL_LISTEN)) {
        if (rs.next()) {
            sessionId = rs.getInt("sessionid");
            getConnection().setClientInfo("ApplicationName", "Debug Mode : " + String.valueOf(sessionId));
        } else {
            throw new DBGException("Unable to create debug instance");
        }
    } catch (SQLException e) {
        throw new DBGException("SQL error", e);
    }
    PostgreDebugBreakpointProperties properties = new PostgreDebugBreakpointProperties(true);
    bpGlobal = new PostgreDebugBreakpointDescriptor(oid, properties);
    addBreakpoint(bpGlobal);
    String sessionParam = String.valueOf(getSessionId());
    String taskName = sessionParam + " global attached to " + String.valueOf(targetId);
    String sql = SQL_ATTACH.replaceAll("\\?sessionid", sessionParam);
    DBGEvent begin = new DBGEvent(this, DBGEvent.RESUME, DBGEvent.MODEL_SPECIFIC);
    DBGEvent end = new DBGEvent(this, DBGEvent.SUSPEND, DBGEvent.BREAKPOINT);
    runAsync(sql, taskName, begin, end);
}
Also used : DBGException(org.jkiss.dbeaver.debug.DBGException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) DBGEvent(org.jkiss.dbeaver.debug.DBGEvent) ResultSet(java.sql.ResultSet)

Example 14 with DBGException

use of org.jkiss.dbeaver.debug.DBGException in project dbeaver by dbeaver.

the class PostgreDebugSession method getVariables.

@Override
public List<DBGVariable<?>> getVariables() throws DBGException {
    acquireReadLock();
    List<DBGVariable<?>> vars = new ArrayList<>();
    String sql = SQL_GET_VARS.replaceAll("\\?sessionid", String.valueOf(sessionId));
    try (Statement stmt = getConnection().createStatement();
        ResultSet rs = stmt.executeQuery(sql)) {
        while (rs.next()) {
            String name = rs.getString("name");
            String varclass = rs.getString("varclass");
            int linenumber = rs.getInt("linenumber");
            boolean isunique = rs.getBoolean("isunique");
            boolean isconst = rs.getBoolean("isconst");
            boolean isnotnull = rs.getBoolean("isnotnull");
            int dtype = rs.getInt("dtype");
            String value = rs.getString("value");
            PostgreDebugVariable var = new PostgreDebugVariable(name, varclass, linenumber, isunique, isconst, isnotnull, dtype, value);
            vars.add(var);
        }
    } catch (SQLException e) {
        throw new DBGException("SQL error", e);
    } finally {
        lock.readLock().unlock();
    }
    return vars;
}
Also used : DBGException(org.jkiss.dbeaver.debug.DBGException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) DBGVariable(org.jkiss.dbeaver.debug.DBGVariable)

Example 15 with DBGException

use of org.jkiss.dbeaver.debug.DBGException in project dbeaver by dbeaver.

the class PostgreDebugSession method getStack.

@Override
public List<DBGStackFrame> getStack() throws DBGException {
    acquireReadLock();
    List<DBGStackFrame> stack = new ArrayList<DBGStackFrame>(1);
    String sql = SQL_GET_STACK.replaceAll("\\?sessionid", String.valueOf(getSessionId()));
    try (Statement stmt = getConnection().createStatement();
        ResultSet rs = stmt.executeQuery(sql)) {
        while (rs.next()) {
            int level = rs.getInt("level");
            String targetname = rs.getString("targetname");
            int func = rs.getInt("func");
            int linenumber = rs.getInt("linenumber");
            String args = rs.getString("args");
            PostgreDebugStackFrame frame = new PostgreDebugStackFrame(level, targetname, func, linenumber, args);
            stack.add(frame);
        }
    } catch (SQLException e) {
        throw new DBGException("SQL error", e);
    } finally {
        lock.readLock().unlock();
    }
    return stack;
}
Also used : DBGException(org.jkiss.dbeaver.debug.DBGException) DBGStackFrame(org.jkiss.dbeaver.debug.DBGStackFrame) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet)

Aggregations

DBGException (org.jkiss.dbeaver.debug.DBGException)19 SQLException (java.sql.SQLException)13 ResultSet (java.sql.ResultSet)8 Statement (java.sql.Statement)8 PreparedStatement (java.sql.PreparedStatement)6 IStatus (org.eclipse.core.runtime.IStatus)5 ArrayList (java.util.ArrayList)4 Scanner (java.util.Scanner)4 DBGBreakpointDescriptor (org.jkiss.dbeaver.debug.DBGBreakpointDescriptor)4 DebugException (org.eclipse.debug.core.DebugException)3 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)3 Status (org.eclipse.core.runtime.Status)2 DBGSession (org.jkiss.dbeaver.debug.DBGSession)2 DBGStackFrame (org.jkiss.dbeaver.debug.DBGStackFrame)2 JDBCExecutionContext (org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext)2 Connection (java.sql.Connection)1 DebugPlugin (org.eclipse.debug.core.DebugPlugin)1 IBreakpointManager (org.eclipse.debug.core.IBreakpointManager)1 DBGBaseController (org.jkiss.dbeaver.debug.DBGBaseController)1 DBGController (org.jkiss.dbeaver.debug.DBGController)1