use of org.jkiss.dbeaver.ui.editors.sql.dialogs.SQLQueryParameterBindDialog in project dbeaver by serge-rider.
the class SQLEditorParametersProvider method prepareStatementParameters.
@Override
public Boolean prepareStatementParameters(@NotNull SQLScriptContext scriptContext, @NotNull SQLQuery sqlStatement, @NotNull List<SQLQueryParameter> parameters, boolean useDefaults) {
for (SQLQueryParameter param : parameters) {
String paramName = param.getVarName();
Object defValue = useDefaults ? scriptContext.getParameterDefaultValue(paramName) : null;
if (defValue != null || scriptContext.hasVariable(paramName)) {
Object varValue = defValue != null ? defValue : scriptContext.getVariable(paramName);
String strValue = varValue == null ? null : varValue.toString();
param.setValue(strValue);
param.setVariableSet(true);
} else {
if (!useDefaults) {
param.setVariableSet(false);
}
}
}
boolean allSet = true;
for (SQLQueryParameter param : parameters) {
if (!param.isVariableSet()) {
allSet = false;
}
}
if (allSet) {
return true;
}
int paramsResult = UITask.run(() -> {
SQLQueryParameterBindDialog dialog = new SQLQueryParameterBindDialog(site, sqlStatement, parameters);
return dialog.open();
});
if (paramsResult == IDialogConstants.OK_ID) {
// Save values back to script context
for (SQLQueryParameter param : parameters) {
if (param.isNamed()) {
String strValue = param.getValue();
if (scriptContext.hasVariable(param.getVarName())) {
scriptContext.setVariable(param.getVarName(), strValue);
} else {
scriptContext.setParameterDefaultValue(param.getVarName(), strValue);
}
}
}
return true;
} else if (paramsResult == IDialogConstants.IGNORE_ID) {
scriptContext.setIgnoreParameters(true);
return null;
}
return false;
}
use of org.jkiss.dbeaver.ui.editors.sql.dialogs.SQLQueryParameterBindDialog in project dbeaver by dbeaver.
the class SQLEditorParametersProvider method prepareStatementParameters.
@Override
public Boolean prepareStatementParameters(@NotNull SQLScriptContext scriptContext, @NotNull SQLQuery sqlStatement, @NotNull List<SQLQueryParameter> parameters, boolean useDefaults) {
for (SQLQueryParameter param : parameters) {
String paramName = param.getVarName();
Object defValue = useDefaults ? scriptContext.getParameterDefaultValue(paramName) : null;
if (defValue != null || scriptContext.hasVariable(paramName)) {
Object varValue = defValue != null ? defValue : scriptContext.getVariable(paramName);
String strValue = varValue == null ? null : varValue.toString();
param.setValue(strValue);
param.setVariableSet(true);
} else {
if (!useDefaults) {
param.setVariableSet(false);
}
}
}
boolean allSet = true;
for (SQLQueryParameter param : parameters) {
if (!param.isVariableSet()) {
allSet = false;
}
}
if (allSet) {
return true;
}
int paramsResult = UITask.run(() -> {
SQLQueryParameterBindDialog dialog = new SQLQueryParameterBindDialog(site, sqlStatement, parameters);
return dialog.open();
});
if (paramsResult == IDialogConstants.OK_ID) {
// Save values back to script context
for (SQLQueryParameter param : parameters) {
if (param.isNamed()) {
String strValue = param.getValue();
if (scriptContext.hasVariable(param.getVarName())) {
scriptContext.setVariable(param.getVarName(), strValue);
} else {
scriptContext.setParameterDefaultValue(param.getVarName(), strValue);
}
}
}
return true;
} else if (paramsResult == IDialogConstants.IGNORE_ID) {
scriptContext.setIgnoreParameters(true);
return null;
}
return false;
}
Aggregations