We are migrating an existing PowerBuilder application to make use of SnapDevelop to handle the datawindow calls. Our system has a reporting area, where we give the user a selection of criteria they can use to customize the report. As the current system works, we have something like this where we are appending to the where clause:
is_sqlSyntax = dw_report.GetSQLSelect()
is_sqlSyntax += " and def_lname Like 'J%'"
ll_ret = dw_report.SetSQLSelect(is_sqlSyntax)
dw_report.SetTransObject(SQLCA)
ll_rows = dw_report.retrieve ( )
In the new system, we make the following call to issue the retrieve of the datawindow:
dw_report.dataobject = 'd_caseload_all_main'
ls_url = gs_host +"/api/"+dw_browse.dataobject+"/retrieve/"
ll_ret = gnv_RestClient.Retrieve(dw_browse, ls_URL)
Since the datawindow object is now in SnapDevelop, calling a SetSQLSelect() from the PowerBuilder code before calling the retrieve does nothing. I would like to know how I can pass to the datawindow object in SnapDevelop the text that needs to be appended to the SQL and then make it happen in the SnapDevelop code.
When I tried to just do a SetSQLSelect in SnapDevelop (without worrying about how I would get the value passed in) it did not work. I added the 3 lines of code between the '----' lines to the Service but I get no data returned to the PB app.
public class D_Caseload_MainService : ID_Caseload_MainService
{
private readonly DataContext _dataContext;
public D_Caseload_MainService(SqlDataContext dataContext)
{
_dataContext = dataContext;
}
public async Task<IDataStore<D_Caseload_Main>> RetrieveAsync(CancellationToken cancellationToken)
{
var dataStore = new DataStore<D_Caseload_Main>(_dataContext);
----------------------------------------------------------------------------------
string sqlSelect = dataStore.GetSqlSelect();
sqlSelect += " and def_lname Like 'J%'";
dataStore.SetSqlSelect(sqlSelect);
----------------------------------------------------------------------------------
await dataStore.RetrieveAsync(new object[] { }, cancellationToken);
return dataStore;
}
}
Could someone help me figure out how to make this work? I need to know 1) how to send the SQL to be appended on the PowerBuilder side and 2) where to put the SetSqlSelect call so that the SQL is updated before retrieving data.
Thanks!
Brian O'Malley
To prevent parameter data passed into the API from being treated as a part of SQL instructions and executed directly, a safer way is to add more Retrieve arguments for this DataWindow (NET DataStore), thus it can use variable binding to reduce the risk.
Regards, Logan