Where to place FILL-WHERE-STRING

Posted by mikelcid on 28-Jul-2011 06:10

Hi all!

I am doing a method that create a dataset adding relations between different tables and selecting from then some data filtered by where clauses, all this done dynamically because I give the names of the tables, the fields used to add the relations and the where clauses in variables. Note that at last, the created dataSet is given to a binding source.

So the question is, in the following code where should I place FILL-WHERE-STRING to filter each table?


CREATE DATASET phDataSet.   DO iEntry = 1 TO NUM-ENTRIES(pcBuffers):
     phDataSet:ADD-BUFFER(WIDGET-HANDLE(ENTRY(iEntry, pcBuffers))).
   END.


   DEFINE VARIABLE iw_tablas AS INTEGER NO-UNDO.
   iw_tablas = NUM-ENTRIES(pcSources, ",").
   
   DO iEntry = 1 TO iw_tablas:
      FOR EACH _File WHERE _File._File-Name = ENTRY(iEntry,pcSources,",") NO-LOCK,
         EACH _Index WHERE _Index._File-recid = RECID(_File) NO-LOCK:
         IF _Index._Unique = TRUE THEN DO:
            FOR EACH _Index-Field WHERE _Index-Field._Index-recid = RECID(_Index) NO-LOCK, 
               FIRST _Field OF _INdex-Field NO-LOCK:
               IF pcSourceKeys = "" THEN
                  pcSourceKeys = _Field._Field-Name.
               ELSE
                  pcSourceKeys = pcSourceKeys + "," + _Field._Field-Name.
            END.
         END.
      END.
   END.


   DEFINE VARIABLE tablas AS CHARACTER NO-UNDO.
   DEFINE VARIABLE iw_relaciones AS INTEGER NO-UNDO.
   DEFINE VARIABLE t1 AS INTEGER NO-UNDO.
   DEFINE VARIABLE t2 AS INTEGER NO-UNDO.
   
   iw_relaciones = NUM-ENTRIES(pcFields, "|").
   
   DO iEntry = 1 TO iw_relaciones:
      tablas = ENTRY(iEntry,pcTablas,"|").
      t1 = INT(ENTRY(1,tablas,",")).
      t2 = INT(ENTRY(2,tablas,",")).
      phDataSet:ADD-RELATION(phDataSet:GET-BUFFER-HANDLE(t1),
                             phDataSet:GET-BUFFER-HANDLE(t2),
                             ENTRY(iEntry,pcFields,"|")).
   END.
   
   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)).
     IF lp_batch THEN 
        phDataSet:GET-BUFFER-HANDLE(iEntry):BATCH-SIZE = 100.
     phDataSet:GET-BUFFER-HANDLE(iEntry):ATTACH-DATA-SOURCE(hDataSource).
   END.


   phDataSet:FILL().

   DELETE OBJECT hQuery.
   DO iEntry = 1 TO phDataSet:NUM-BUFFERS:
     hBuffer = phDataSet:GET-BUFFER-HANDLE(iEntry).
     DELETE OBJECT hBuffer:DATA-SOURCE.
   END.

   bindingSource1 = NEW Progress.Data.BindingSource(phDataSet).


All Replies

Posted by Peter Judge on 28-Jul-2011 08:08



So the question is, in the following code where should I place FILL-WHERE-STRING to filter each table?



   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)).
     IF lp_batch THEN
        phDataSet:GET-BUFFER-HANDLE(iEntry):BATCH-SIZE = 100.
     phDataSet:GET-BUFFER-HANDLE(iEntry):ATTACH-DATA-SOURCE(hDataSource).
   END.


Here ^^

You need to be conscious of the order of operations a little bit when modifying the query string.

If you just want to change the fill-where clause,

  1. attach to buffer
  2. assign fill-where-string = ' WHERE ' + ...

If you're using an external query handle, the order is

  1. datasource:query = hQuery
  2. Attach datasource to buffer
  3. prepare query (ie change query's prepare-string)

If your datasource has more than one (DB) buffer, you need to use an external query. OpenEdge.DataSource.StandardDataSource in the AutoEdge|TheFactory sample has examples of this.

-- peter

This thread is closed