OOABL Returning a dynamic temp-table

Posted by Kim Ward on 08-Feb-2016 05:40


I'm currently trying to write a dynamic query object. So I can do something like:

dynQuery:newQuery():for("Customer"):where("name", "fred"):get().

At the moment the get method returns a handle to the dynamic temp-table which allows me to use the copy-temp-table method to dump the dynamic temp-table into a static one making it easier to work with. However this feels really untidy. I was wondering if anyone could suggest a better way of doing this?


All Replies

Posted by James Palmer on 08-Feb-2016 06:09

I would just leave out the step that copies the dynamic to static and work dynamically. It's not too hard once you get your head round it.

One thing some people miss is that you can change




It makes the code a lot easier to write and read.

Posted by Tim Kuehn on 08-Feb-2016 08:38

Resolving the buffer field handle takes time - so one can also do:

  hField = BufferHandle:BufferField("FieldName").

once and then


as required later on.

Posted by Peter Judge on 08-Feb-2016 09:05

Maybe I'm misunderstanding, but you could overload the Get() method to accept a buffer handle. This would allow you to pass in an existing temp-table handle which you could manipulate however you choose.

Something like


Def temp-table ttCust no-undo like mydb.Customer.

find first ttCust no-error.
message available ttCust.    /* NO */

        :where("name", "fred")
    :get(input buffer ttCust:handle).

/* now you can do all the static code you want */
find first ttCust no-error.
message available ttCust.    /* YES */

The dynQuery:Get() code can be something like

method public dynQuery Get(input phbuffer as handle):
  do while not hQry:query-off-end

  return this-object.
end method.

method public dynQuery Get():
  def var hTT as handle.
  create temp-table hTT.
  /* create like etc etc etc */

  return this--object:Get(hTT:default-buffer-handle).
end method.

The above code works for only a single query table. multiple tables are left as an exercise for the reader.

Posted by Kim Ward on 08-Feb-2016 14:35

Thanks Peter that looks exactly like that I'm aiming for. I'll give it a try in the morning and let you know.

Update: Worked a treat thanks :) this is exactly what I was trying to achieve. Now I just need to make it useful. 

This thread is closed