Fill() options

mikelcid

New Member
Hi all!

I first show you the code and then I will explain it:

Code:
CLASS crearDataSetDinamico: 
    
    DEFINE PRIVATE VARIABLE bindingSource1 AS Progress.Data.BindingSource NO-UNDO.
        
CONSTRUCTOR PUBLIC crearDataSetDinamico (INPUT filtro AS LOGICAL, /* Need filtering? */
    INPUT fTabla AS CHARACTER, /* Table to filter */
    INPUT fCampo AS CHARACTER, /* Field from the table to filter */
    INPUT fFiltro AS CHARACTER, /* Filter text */
    INPUT pcBuffers AS CHARACTER,
    INPUT pcFields AS CHARACTER,
    INPUT pcSources AS CHARACTER,
    INPUT pcSourceKeys AS CHARACTER,
    INPUT pcKeyValue AS CHARACTER,
    OUTPUT phDataSet AS HANDLE,
    OUTPUT bindingSource1 AS Progress.Data.BindingSource):
        
    DEFINE VARIABLE iEntry AS INTEGER NO-UNDO.
    DEFINE VARIABLE hDataSource AS HANDLE NO-UNDO.
    DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.
    DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
    DEFINE VARIABLE condicion AS CHARACTER NO-UNDO.
                  
    CREATE DATASET phDataSet.
    DO iEntry = 1 TO NUM-ENTRIES(pcBuffers):
        phDataSet:ADD-BUFFER(WIDGET-HANDLE(ENTRY(iEntry, pcBuffers))).
    END.
        
    phDataSet:ADD-RELATION(phDataSet:GET-BUFFER-HANDLE(1),phDataSet:GET-BUFFER-HANDLE(2),pcFields).
    
    DO iEntry = 1 TO NUM-ENTRIES(pcSources):
        CREATE DATA-SOURCE hDataSource.
        CREATE BUFFER hBuffer FOR TABLE ENTRY(iEntry, pcSources).
        hDataSource:ADD-SOURCE-BUFFER(hBuffer, ENTRY(iEntry,pcSourceKeys)).
        phDataSet:GET-BUFFER-HANDLE(iEntry):ATTACH-DATA-SOURCE(hDataSource).
    END.
    
    phDataSet:FILL().
        
    bindingSource1 = NEW Progress.Data.BindingSource (phDataSet).   
    
        
END METHOD.

END CLASS.

Apart from the options to filter the data this code receives two table names and the fields to use to join them. What I want after joining the tables is to filter the data using the options received but I don't how to do this, if there exists any option in FILL() statement to do my purpose. Any idea?

Thanks in advence,
Mikel Cid, always asking :)
 
The FILL method on the ProDataSet does not cope with filtering. It is not meant to.

You have two options on defining where a data source gets the data:

  1. A buffer (database table)
  2. A query
In your case you need to build a query which fetches the records from both tables and use that query in the data source:
/* Create a dynamic buffer object for the database table */
CREATE BUFFER hDatabaseBuffer FOR TABLE getMainTableName ( ) {&IN-WIDGET-POOL}.

/* Create the query object */
CREATE QUERY hQuery {&IN-WIDGET-POOL}.
hQuery:SET-BUFFERS ( hDatabaseBuffer ).

/* Create a dynamic data source object and associate it with the query */
CREATE DATA-SOURCE hDataSource {&IN-WIDGET-POOL}.
hDataSource:QUERY = hQuery.

/* Attach the data source to the data object buffer */
IF fieldMapping <> '':U AND fieldMapping <> ? THEN
hDataObjectBuffer:ATTACH-DATA-SOURCE ( hDataSource, fieldMapping ).
ELSE
hDataObjectBuffer:ATTACH-DATA-SOURCE ( hDataSource ).

/* Add a callback to populate calculated fields */
hDataObjectBuffer:SET-CALLBACK ( 'AFTER-ROW-FILL':U, 'afterRowFill':U, THIS-OBJECT ).

/* Depending on the batch relative, set the query start position */
ASSIGN lOkay = setQueryStartPosition (
INPUT hDataSource ). /* Handle to the data source */
IF NOT lOkay THEN
UNDO FETCH-BATCH-BLK, LEAVE FETCH-BATCH-BLK.

/* Set the batch size */
ASSIGN hDataObjectBuffer:BATCH-SIZE = getBatchSize ( ).

/* Prepare the query which will retrieve the data to populate the data set */
IF getBatchRelative ( ) = 'Find':U THEN
hQuery:QUERY-PREPARE ( getBaseQueryString ( ) ).
ELSE
hQuery:QUERY-PREPARE ( cQueryString ).

/* Populate the data set */
phDataSet:HANDLE:FILL ( ).
Heavy Regards, RealHeavyDude.
 
@RealHeavyDude before trying to apply your code to mine I have try to do a filter to the bindingSource doing bindingSource1:Filter = "CustNum = 8" but it provides the same data and it should work find because the data source for the binding is a DataSet. Any idea if I am able to use bindingSource.Filter?
 
Sorry I don't have any experience with the .NET UI in OpenEdge. I use the code on the AppServer called from a Java servlet.

Heavy Regards, RealHeavyDude.
 
I don't have any 10.2+ at hand so I can't test it - but just a thought:

When the binding source can apply a filter on a ProDataSet - IMHO, it can only apply that filter to some query not to a buffer. Therefore I still think your data source needs to be based on a query instead of a buffer in order to allow the binding source to change the query.

Again, that is just a thought of mine without any knowledge about the .NET UI in OpenEdge.

Heavy Regards, RealHeavyDude.
 
Back
Top