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();
}
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations