Search in sources :

Example 6 with DBGException

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

the class Debugger method chooseBreakpoint.

public static DBGBreakpointDescriptor chooseBreakpoint(Scanner sc, DBGController controller, DBGSession session) throws DBGException {
    DBGBreakpointDescriptor bp = null;
    List<? extends DBGBreakpointDescriptor> bps = session.getBreakpoints();
    Scanner scArg;
    if (bps.size() == 1) {
        bp = bps.get(0);
    } else {
        System.out.println("Choose breakpoint (0 for quit) :");
        int bpNo = 1;
        for (DBGBreakpointDescriptor b : bps) {
            System.out.println(String.format(" (%d) %s", bpNo++, b.toString()));
        }
        int bpId = -1;
        while (bpId < 0) {
            String argc = sc.nextLine();
            String strBpid = "";
            scArg = new Scanner(argc);
            if (scArg.hasNext()) {
                strBpid = scArg.next();
                if (strBpid.trim().length() > 0) {
                    try {
                        bpId = Integer.valueOf(strBpid);
                    } catch (Exception e) {
                        System.out.println(String.format("Incorrect session ID %s", strBpid));
                        bpId = -1;
                    }
                    if (bpId == 0) {
                        break;
                    }
                    if (bpId > bps.size()) {
                        System.out.println(String.format("Incorrect breakpoint ID %s", strBpid));
                        bpId = -1;
                    } else {
                        bp = bps.get(bpId - 1);
                        break;
                    }
                }
            }
            scArg.close();
        }
    }
    return bp;
}
Also used : Scanner(java.util.Scanner) DBGBreakpointDescriptor(org.jkiss.dbeaver.debug.DBGBreakpointDescriptor) DBGException(org.jkiss.dbeaver.debug.DBGException) SQLException(java.sql.SQLException)

Example 7 with DBGException

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

the class Debugger method chooseSession.

public static DBGSession chooseSession(Scanner sc, DBGBaseController controller) throws DBGException {
    DBGSession debugSession = null;
    List<DBGSession> sessions = controller.getSessions();
    Scanner scArg;
    if (sessions.size() == 1) {
        debugSession = sessions.get(0);
    } else {
        System.out.println("Choose debug session (0 for quit) :");
        int sessNo = 1;
        for (DBGSession s : sessions) {
            System.out.println(String.format(" (%d) %s", sessNo++, s.toString()));
        }
        int sessionId = -1;
        while (sessionId < 0) {
            String argc = sc.nextLine();
            String strSessionid = "";
            scArg = new Scanner(argc);
            if (scArg.hasNext()) {
                strSessionid = scArg.next();
                if (strSessionid.trim().length() > 0) {
                    try {
                        sessionId = Integer.valueOf(strSessionid);
                    } catch (Exception e) {
                        System.out.println(String.format("Incorrect session ID %s", strSessionid));
                        sessionId = -1;
                    }
                    if (sessionId == 0) {
                        break;
                    }
                    if (sessionId > sessions.size()) {
                        System.out.println(String.format("Incorrect session ID %s", strSessionid));
                        sessionId = -1;
                    } else {
                        debugSession = sessions.get(sessionId - 1);
                        break;
                    }
                }
            }
            scArg.close();
        }
    }
    return debugSession;
}
Also used : Scanner(java.util.Scanner) DBGSession(org.jkiss.dbeaver.debug.DBGSession) DBGException(org.jkiss.dbeaver.debug.DBGException) SQLException(java.sql.SQLException)

Example 8 with DBGException

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

the class PostgreDebugController method getObjects.

@Override
public List<PostgreDebugObjectDescriptor> getObjects(String ownerCtx, String nameCtx) throws DBGException {
    DBCExecutionContext executionContext = getExecutionContext();
    String sql = SQL_OBJECT.replaceAll("\\?nameCtx", nameCtx).replaceAll("\\?userCtx", ownerCtx).toLowerCase();
    try (Statement stmt = getConnection(executionContext).createStatement();
        ResultSet rs = stmt.executeQuery(sql)) {
        List<PostgreDebugObjectDescriptor> res = new ArrayList<PostgreDebugObjectDescriptor>();
        while (rs.next()) {
            int oid = rs.getInt("oid");
            String proname = rs.getString("proname");
            String owner = rs.getString("owner");
            String nspname = rs.getString("nspname");
            String lang = rs.getString("lang");
            PostgreDebugObjectDescriptor object = new PostgreDebugObjectDescriptor(oid, proname, owner, nspname, lang);
            res.add(object);
        }
        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 9 with DBGException

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

the class PostgreDebugController method getSessionDescriptor.

@Override
public PostgreDebugSessionInfo getSessionDescriptor(DBCExecutionContext connectionTarget) throws DBGException {
    try (Statement stmt = getConnection(connectionTarget).createStatement();
        ResultSet rs = stmt.executeQuery(SQL_CURRENT_SESSION)) {
        if (rs.next()) {
            int pid = rs.getInt("pid");
            String usename = rs.getString("usename");
            String applicationName = rs.getString("application_name");
            String state = rs.getString("state");
            String query = rs.getString("query");
            PostgreDebugSessionInfo res = new PostgreDebugSessionInfo(pid, usename, applicationName, state, query);
            return res;
        }
        throw new DBGException("Error getting session");
    } catch (SQLException e) {
        throw new DBGException("SQL error", e);
    }
}
Also used : DBGException(org.jkiss.dbeaver.debug.DBGException) SQLException(java.sql.SQLException) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet)

Example 10 with DBGException

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

the class PostgreDebugSession method selectFrame.

/**
 * This function changes the debugger focus to the indicated frame (in the
 * call stack). Whenever the target stops (at a breakpoint or as the result
 * of a step/into or step/over), the debugger changes focus to most deeply
 * nested function in the call stack (because that's the function that's
 * executing).
 *
 * You can change the debugger focus to other stack frames - once you do
 * that, you can examine the source code for that frame, the variable values
 * in that frame, and the breakpoints in that target.
 *
 * The debugger focus remains on the selected frame until you change it or
 * the target stops at another breakpoint.
 *
 * @return DBGStackFrame
 */
public void selectFrame(int frameNumber) throws DBGException {
    acquireReadLock();
    String pattern = SQL_SELECT_FRAME;
    pattern = "select * from pldbg_select_frame(?sessionid,?frameno)";
    String sql = pattern.replaceAll("\\?sessionid", String.valueOf(sessionId)).replaceAll("\\?frameno", String.valueOf(frameNumber));
    try (Statement stmt = getConnection().createStatement();
        ResultSet rs = stmt.executeQuery(sql)) {
        if (!rs.next()) {
            throw new DBGException("Unable to select frame");
        }
    } 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) Statement(java.sql.Statement) 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