提交 6ee6a474 编写于 作者: A Andrew Khitrin

Variables set


Former-commit-id: a3ae5902
上级 2faade9c
......@@ -28,7 +28,6 @@ import org.jkiss.dbeaver.debug.DBGSession;
import org.jkiss.dbeaver.debug.DBGStackFrame;
import org.jkiss.dbeaver.debug.DBGVariable;
import org.jkiss.dbeaver.ext.postgresql.debug.internal.impl.*;
import org.jkiss.dbeaver.ext.postgresql.debug.internal.impl.PostgreDebugBreakpoint;
@SuppressWarnings("nls")
public class Debugger {
......@@ -55,6 +54,79 @@ public class Debugger {
public static final String COMMAND_HELP = "?";
public static final String ANY_ARG = "*";
public static DBGVariable<?> chooseVariable(Scanner sc, PostgreDebugSessionManager pgDbgManager,
PostgreDebugSession session) throws DBGException {
DBGVariable<?> v = null;
List<DBGVariable<?>> vars = session.getVarables();
Scanner scArg;
if (vars.size() == 1) {
v = (PostgreDebugVariable) vars.get(0);
} else {
System.out.println("Choose variable (0 for quit) :");
int varNo = 1;
for (DBGVariable<?> cv : vars) {
System.out.println(String.format(" (%d) %s", varNo++, cv.toString()));
}
int varId = -1;
while (varId < 0) {
String argc = sc.nextLine();
String strvarid = "";
scArg = new Scanner(argc);
if (scArg.hasNext()) {
strvarid = scArg.next();
if (strvarid.trim().length() > 0) {
try {
varId = Integer.valueOf(strvarid);
} catch (Exception e) {
System.out.println(String.format("Incorrect var ID %s", strvarid));
varId = -1;
}
if (varId == 0) {
break;
}
if (varId > vars.size()) {
System.out.println(String.format("Incorrect var ID %s", strvarid));
varId = -1;
} else {
v = vars.get(varId - 1);
break;
}
}
}
scArg.close();
}
}
return v;
}
public static PostgreDebugBreakpoint chooseBreakpoint(Scanner sc, PostgreDebugSessionManager pgDbgManager,
PostgreDebugSession session) throws DBGException {
......@@ -339,7 +411,45 @@ public class Debugger {
break;
case COMMAND_VARIABLE_SET:
System.out.println("VARIABLE_SET!!!");
String strVal = "";
String argcV = sc.nextLine();
if (argcV.length() > 0) {
scArg = new Scanner(argcV);
if (scArg.hasNext()) {
strVal = scArg.next();
}
scArg.close();
}
if (pgDbgManager.getDebugSessions().size() == 0) {
System.out.println("Debug sessions not found");
break;
}
PostgreDebugSession debugSessionVS = chooseSession(sc, pgDbgManager);
if (debugSessionVS == null) {
break;
}
DBGVariable<?> var = chooseVariable(sc, pgDbgManager,debugSessionVS);
if (var == null) {
break;
}
debugSessionVS.setVariableVal(var, strVal);
System.out.println(String.format("Variable Set %s",strVal));
break;
case COMMAND_BREAKPOINT:
......
......@@ -19,6 +19,7 @@
package org.jkiss.dbeaver.ext.postgresql.debug.internal.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
......@@ -28,12 +29,14 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.eclipse.debug.core.DebugException;
import org.jkiss.dbeaver.debug.DBGBreakpoint;
import org.jkiss.dbeaver.debug.DBGBreakpointProperties;
import org.jkiss.dbeaver.debug.DBGException;
import org.jkiss.dbeaver.debug.DBGSession;
import org.jkiss.dbeaver.debug.DBGStackFrame;
import org.jkiss.dbeaver.debug.DBGVariable;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement;
@SuppressWarnings("nls")
public class PostgreDebugSession implements DBGSession<PostgreDebugSessionInfo, PostgreDebugObject, Integer> {
......@@ -55,6 +58,8 @@ public class PostgreDebugSession implements DBGSession<PostgreDebugSessionInfo,
private static final String SQL_LISTEN = "select pldbg_create_listener() as sessionid";
private static final String SQL_GET_VARS = "select * from pldbg_get_variables(?sessionid)";
private static final String SQL_SET_VAR = "select pldbg_deposit_value(?,?,?,?)";
private static final String SQL_GET_STACK = "select * from pldbg_get_stack(?sessionid)";
......@@ -294,7 +299,40 @@ public class PostgreDebugSession implements DBGSession<PostgreDebugSessionInfo,
@Override
public void setVariableVal(DBGVariable<?> variable, Object value) throws DBGException {
// TODO Auto-generated method stub
acquireReadLock();
try (PreparedStatement stmt = connection.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(e);
} finally {
lock.readLock().unlock();
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册